summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2004-12-09 17:57:53 -0800
committerLinus Torvalds <torvalds@ppc970.osdl.org>2004-12-09 17:57:53 -0800
commitf9286bcfa0a8c531b90e2dc010e451fd77c9f982 (patch)
tree64c8437a87dbd599bcdd691ea7b3f4447d28cac9
parentea75ccda06241e2f1422b2def756cbacb4206f19 (diff)
Clean up open_exec()/kmalloc() error case handling.
It's a purely theoretical bug, since the kmalloc() failure that might "leak" file descriptors cannot actually happen (we do not ever fail small GFP_KERNEL allocations), but it's good to do things properly. Noted by Brad Spender.
-rw-r--r--fs/compat.c18
-rw-r--r--fs/exec.c18
2 files changed, 20 insertions, 16 deletions
diff --git a/fs/compat.c b/fs/compat.c
index eb289d3e8ce7..4120c9ea6ed2 100644
--- a/fs/compat.c
+++ b/fs/compat.c
@@ -1387,25 +1387,25 @@ int compat_do_execve(char * filename,
int retval;
int i;
- file = open_exec(filename);
-
- retval = PTR_ERR(file);
- if (IS_ERR(file))
- return retval;
-
- sched_exec();
-
retval = -ENOMEM;
bprm = kmalloc(sizeof(*bprm), GFP_KERNEL);
if (!bprm)
goto out_ret;
memset(bprm, 0, sizeof(*bprm));
+ file = open_exec(filename);
+ retval = PTR_ERR(file);
+ if (IS_ERR(file))
+ goto out_kfree;
+
+ sched_exec();
+
bprm->p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
bprm->file = file;
bprm->filename = filename;
bprm->interp = filename;
bprm->mm = mm_alloc();
+ retval = -ENOMEM;
if (!bprm->mm)
goto out_file;
@@ -1472,6 +1472,8 @@ out_file:
allow_write_access(bprm->file);
fput(bprm->file);
}
+
+out_kfree:
kfree(bprm);
out_ret:
diff --git a/fs/exec.c b/fs/exec.c
index dd1c43b6f975..a2e554cdace3 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1094,26 +1094,26 @@ int do_execve(char * filename,
int retval;
int i;
- file = open_exec(filename);
-
- retval = PTR_ERR(file);
- if (IS_ERR(file))
- return retval;
-
- sched_exec();
-
retval = -ENOMEM;
bprm = kmalloc(sizeof(*bprm), GFP_KERNEL);
if (!bprm)
goto out_ret;
memset(bprm, 0, sizeof(*bprm));
+ file = open_exec(filename);
+ retval = PTR_ERR(file);
+ if (IS_ERR(file))
+ goto out_kfree;
+
+ sched_exec();
+
bprm->p = PAGE_SIZE*MAX_ARG_PAGES-sizeof(void *);
bprm->file = file;
bprm->filename = filename;
bprm->interp = filename;
bprm->mm = mm_alloc();
+ retval = -ENOMEM;
if (!bprm->mm)
goto out_file;
@@ -1180,6 +1180,8 @@ out_file:
allow_write_access(bprm->file);
fput(bprm->file);
}
+
+out_kfree:
kfree(bprm);
out_ret: