Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52f14282 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds
Browse files

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: default avatarOleg Nesterov <oleg@redhat.com>
Acked-by: default avatarKees 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 9beb266f
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -1400,10 +1400,6 @@ int search_binary_handler(struct linux_binprm *bprm)
			bprm->recursion_depth--;
			bprm->recursion_depth--;
			if (retval >= 0) {
			if (retval >= 0) {
				put_binfmt(fmt);
				put_binfmt(fmt);
				allow_write_access(bprm->file);
				if (bprm->file)
					fput(bprm->file);
				bprm->file = NULL;
				return retval;
				return retval;
			}
			}
			read_lock(&binfmt_lock);
			read_lock(&binfmt_lock);
@@ -1455,6 +1451,12 @@ static int exec_binprm(struct linux_binprm *bprm)
		ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
		ptrace_event(PTRACE_EVENT_EXEC, old_vpid);
		current->did_exec = 1;
		current->did_exec = 1;
		proc_exec_connector(current);
		proc_exec_connector(current);

		if (bprm->file) {
			allow_write_access(bprm->file);
			fput(bprm->file);
			bprm->file = NULL; /* to catch use-after-free */
		}
	}
	}


	return ret;
	return ret;