exec: Move most of setup_new_exec into flush_old_exec
authorEric W. Biederman <ebiederm@xmission.com>
Sun, 3 May 2020 12:15:28 +0000 (07:15 -0500)
committerEric W. Biederman <ebiederm@xmission.com>
Thu, 7 May 2020 21:55:47 +0000 (16:55 -0500)
commitdf9e4d2c4a53503a97fc08eeebdc04e3c11b4618
treec4cefb24dc296c3cc1d1963b6c074f04379fccaa
parent7d503feba0c88586b4c9f1212e9cc582c9370fa7
exec: Move most of setup_new_exec into flush_old_exec

The current idiom for the callers is:

flush_old_exec(bprm);
set_personality(...);
setup_new_exec(bprm);

In 2010 Linus split flush_old_exec into flush_old_exec and
setup_new_exec.  With the intention that setup_new_exec be what is
called after the processes new personality is set.

Move the code that doesn't depend upon the personality from
setup_new_exec into flush_old_exec.  This is to facilitate future
changes by having as much code together in one function as possible.

To see why it is safe to move this code please note that effectively
this change moves the personality setting in the binfmt and the following
three lines of code after everything except unlocking the mutexes:
arch_pick_mmap_layout
arch_setup_new_exec
mm->task_size = TASK_SIZE

The function arch_pick_mmap_layout at most sets:
mm->get_unmapped_area
mm->mmap_base
mm->mmap_legacy_base
mm->mmap_compat_base
mm->mmap_compat_legacy_base
which nothing in flush_old_exec or setup_new_exec depends on.

The function arch_setup_new_exec only sets architecture specific
state and the rest of the functions only deal in state that applies
to all architectures.

The last line just sets mm->task_size and again nothing in flush_old_exec
or setup_new_exec depend on task_size.

Ref: 221af7f87b97 ("Split 'flush_old_exec' into two functions")
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Greg Ungerer <gerg@linux-m68k.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
fs/exec.c