summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mack <zonque@gmail.com>2014-03-08 13:40:32 +0100
committerDaniel Mack <zonque@gmail.com>2014-03-08 13:40:32 +0100
commitf07ae2933e32c53bc1b20e5477813e3b97070be0 (patch)
tree73ecd63b7128af39548ab4e90458a9a20a3c5c79
parentfde2d5143119af0d320c19f4645a5ca406ef1007 (diff)
downloadkdbus-bus-f07ae2933e32c53bc1b20e5477813e3b97070be0.tar.gz
kdbus-bus-f07ae2933e32c53bc1b20e5477813e3b97070be0.tar.bz2
kdbus-bus-f07ae2933e32c53bc1b20e5477813e3b97070be0.zip
metadata: fix error unwinding in kdbus_meta_append_cmdline()
-rw-r--r--metadata.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/metadata.c b/metadata.c
index 4012461e409..77f0df02892 100644
--- a/metadata.c
+++ b/metadata.c
@@ -275,6 +275,7 @@ static int kdbus_meta_append_cmdline(struct kdbus_meta *meta)
{
struct mm_struct *mm;
int ret = 0;
+ size_t len;
char *tmp;
tmp = (char *)__get_free_page(GFP_TEMPORARY | __GFP_ZERO);
@@ -282,23 +283,26 @@ static int kdbus_meta_append_cmdline(struct kdbus_meta *meta)
return -ENOMEM;
mm = get_task_mm(current);
+ if (!mm)
+ goto exit_free_page;
- if (mm && mm->arg_end) {
- size_t len = mm->arg_end - mm->arg_start;
+ if (!mm->arg_end)
+ goto exit_mmput;
- if (len > PAGE_SIZE)
- len = PAGE_SIZE;
+ len = mm->arg_end - mm->arg_start;
+ if (len > PAGE_SIZE)
+ len = PAGE_SIZE;
- ret = copy_from_user(tmp, (const char __user *)mm->arg_start,
- len);
- if (ret == 0)
- ret = kdbus_meta_append_data(meta, KDBUS_ITEM_CMDLINE,
- tmp, len);
- }
+ ret = copy_from_user(tmp, (const char __user *)mm->arg_start, len);
+ if (ret < 0)
+ goto exit_mmput;
- if (mm)
- mmput(mm);
+ ret = kdbus_meta_append_data(meta, KDBUS_ITEM_CMDLINE, tmp, len);
+exit_mmput:
+ mmput(mm);
+
+exit_free_page:
free_page((unsigned long) tmp);
return ret;