aboutsummaryrefslogtreecommitdiffstats
path: root/fs/exec.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2013-09-11 17:24:41 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-09-11 18:59:05 -0400
commit52f14282bb0c3d3e5ba2a9eaacb12ff37a033e7e (patch)
treec0f02056772e53e294784388b4202e94271c46e6 /fs/exec.c
parent9beb266f2d7e5362c5bb9f999255aa1af5318aef (diff)
exec: move allow_write_access/fput to exec_binprm()
When search_binary_handler() succeeds it does allow_write_access() and fput(), then it clears bprm->file to ensure the caller will not do the same. We can simply move this code to exec_binprm() which is called only once. In fact we could move this to free_bprm() and remove the same code in do_execve_common's error path. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Acked-by: Kees Cook <keescook@chromium.org> Cc: Al Viro <viro@ZenIV.linux.org.uk> Cc: Evgeniy Polyakov <zbr@ioremap.net> Cc: Zach Levis <zml@linux.vnet.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/exec.c')
-rw-r--r--fs/exec.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/fs/exec.c b/fs/exec.c
index d51f7172832b..a4cfd1d725e0 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1400,10 +1400,6 @@ int search_binary_handler(struct linux_binprm *bprm)
1400 bprm->recursion_depth--; 1400 bprm->recursion_depth--;
1401 if (retval >= 0) { 1401 if (retval >= 0) {
1402 put_binfmt(fmt); 1402 put_binfmt(fmt);
1403 allow_write_access(bprm->file);
1404 if (bprm->file)
1405 fput(bprm->file);
1406 bprm->file = NULL;
1407 return retval; 1403 return retval;
1408 } 1404 }
1409 read_lock(&binfmt_lock); 1405 read_lock(&binfmt_lock);
@@ -1455,6 +1451,12 @@ static int exec_binprm(struct linux_binprm *bprm)
1455 ptrace_event(PTRACE_EVENT_EXEC, old_vpid); 1451 ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
1456 current->did_exec = 1; 1452 current->did_exec = 1;
1457 proc_exec_connector(current); 1453 proc_exec_connector(current);
1454
1455 if (bprm->file) {
1456 allow_write_access(bprm->file);
1457 fput(bprm->file);
1458 bprm->file = NULL; /* to catch use-after-free */
1459 }
1458 } 1460 }
1459 1461
1460 return ret; 1462 return ret;