Commit b213c2dc authored by Eric W. Biederman's avatar Eric W. Biederman
Browse files

exec: Promised cleanups after introducing exec_update_mutex

In the patchset that introduced exec_update_mutex there were a few last
minute discoveries and fixes that left the code in a state that can
be very easily be improved.

During the merge window we discussed the first three of these patches
and I promised I would resend them.

What the first patch does is it makes the the calls in the binfmts:
	flush_old_exec();
        /* set the personality */
        setup_new_exec();
        install_exec_creds();

With no sleeps or anything in between.

At the conclusion of this set of changes the the calls in the binfmts
are:
	begin_new_exec();
        /* set the personality */
        setup_new_exec();

The intent is to make the code easier to follow and easier to change.

Eric W. Biederman (7):
      binfmt: Move install_exec_creds after setup_new_exec to match binfmt_elf
      exec: Make unlocking exec_update_mutex explict
      exec: Rename the flag called_exec_mmap point_of_no_return
      exec: Merge install_exec_creds into setup_new_exec
      exec: In setup_new_exec cache current in the local variable me
      exec: Move most of setup_new_exec into flush_old_exec
      exec: Rename flush_old_exec begin_new_exec

 Documentation/trace/ftrace.rst |   2 +-
 arch/x86/ia32/ia32_aout.c      |   4 +-
 fs/binfmt_aout.c               |   3 +-
 fs/binfmt_elf.c                |   3 +-
 fs/binfmt_elf_fdpic.c          |   3 +-
 fs/binfmt_flat.c               |   4 +-
 fs/exec.c                      | 162 ++++++++++++++++++++---------------------
 include/linux/binfmts.h        |  10 +--
 kernel/events/core.c           |   2 +-
 9 files changed, 92 insertions(+), 101 deletions(-)

Link: https://lkml.kernel.org/r/87h7wujhmz.fsf@x220.int.ebiederm.org


Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Reviewed-by: default avatarGreg Ungerer <gerg@linux-m68k.org>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
parents 6a8b55ed 2388777a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1524,7 +1524,7 @@ display-graph option::
   => remove_vma
   => exit_mmap
   => mmput
   => flush_old_exec
   => begin_new_exec
   => load_elf_binary
   => search_binary_handler
   => __do_execve_file.isra.32
+1 −3
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ static int load_aout_binary(struct linux_binprm *bprm)
		return -ENOMEM;

	/* Flush all traces of the currently running executable */
	retval = flush_old_exec(bprm);
	retval = begin_new_exec(bprm);
	if (retval)
		return retval;

@@ -156,8 +156,6 @@ static int load_aout_binary(struct linux_binprm *bprm)
	if (retval < 0)
		return retval;

	install_exec_creds(bprm);

	if (N_MAGIC(ex) == OMAGIC) {
		unsigned long text_addr, map_size;

+1 −2
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
		return -ENOMEM;

	/* Flush all traces of the currently running executable */
	retval = flush_old_exec(bprm);
	retval = begin_new_exec(bprm);
	if (retval)
		return retval;

@@ -174,7 +174,6 @@ static int load_aout_binary(struct linux_binprm * bprm)
	if (retval < 0)
		return retval;

	install_exec_creds(bprm);

	if (N_MAGIC(ex) == OMAGIC) {
		unsigned long text_addr, map_size;
+1 −2
Original line number Diff line number Diff line
@@ -844,7 +844,7 @@ out_free_interp:
		goto out_free_dentry;

	/* Flush all traces of the currently running executable */
	retval = flush_old_exec(bprm);
	retval = begin_new_exec(bprm);
	if (retval)
		goto out_free_dentry;

@@ -858,7 +858,6 @@ out_free_interp:
		current->flags |= PF_RANDOMIZE;

	setup_new_exec(bprm);
	install_exec_creds(bprm);

	/* Do this so that we can load the interpreter, if need be.  We will
	   change some of these later */
+1 −2
Original line number Diff line number Diff line
@@ -338,7 +338,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
		interp_params.flags |= ELF_FDPIC_FLAG_CONSTDISP;

	/* flush all traces of the currently running executable */
	retval = flush_old_exec(bprm);
	retval = begin_new_exec(bprm);
	if (retval)
		goto error;

@@ -434,7 +434,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
	current->mm->start_stack = current->mm->start_brk + stack_size;
#endif

	install_exec_creds(bprm);
	if (create_elf_fdpic_tables(bprm, current->mm,
				    &exec_params, &interp_params) < 0)
		goto error;
Loading