提交 e7f77854 编写于 作者: E Eric W. Biederman

binfmt: Move install_exec_creds after setup_new_exec to match binfmt_elf

In 2016 Linus moved install_exec_creds immediately after
setup_new_exec, in binfmt_elf as a cleanup and as part of closing a
potential information leak.

Perform the same cleanup for the other binary formats.

Different binary formats doing the same things the same way makes exec
easier to reason about and easier to maintain.

Greg Ungerer reports:
> I tested the the whole series on non-MMU m68k and non-MMU arm
> (exercising binfmt_flat) and it all tested out with no problems,
> so for the binfmt_flat changes:
Tested-by: NGreg Ungerer <gerg@linux-m68k.org>

Ref: 9f834ec1 ("binfmt_elf: switch to new creds when switching to new mm")
Reviewed-by: NKees Cook <keescook@chromium.org>
Reviewed-by: NGreg Ungerer <gerg@linux-m68k.org>
Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
上级 6a8b55ed
...@@ -140,6 +140,7 @@ static int load_aout_binary(struct linux_binprm *bprm) ...@@ -140,6 +140,7 @@ static int load_aout_binary(struct linux_binprm *bprm)
set_personality_ia32(false); set_personality_ia32(false);
setup_new_exec(bprm); setup_new_exec(bprm);
install_exec_creds(bprm);
regs->cs = __USER32_CS; regs->cs = __USER32_CS;
regs->r8 = regs->r9 = regs->r10 = regs->r11 = regs->r12 = regs->r8 = regs->r9 = regs->r10 = regs->r11 = regs->r12 =
...@@ -156,8 +157,6 @@ static int load_aout_binary(struct linux_binprm *bprm) ...@@ -156,8 +157,6 @@ static int load_aout_binary(struct linux_binprm *bprm)
if (retval < 0) if (retval < 0)
return retval; return retval;
install_exec_creds(bprm);
if (N_MAGIC(ex) == OMAGIC) { if (N_MAGIC(ex) == OMAGIC) {
unsigned long text_addr, map_size; unsigned long text_addr, map_size;
......
...@@ -162,6 +162,7 @@ static int load_aout_binary(struct linux_binprm * bprm) ...@@ -162,6 +162,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
set_personality(PER_LINUX); set_personality(PER_LINUX);
#endif #endif
setup_new_exec(bprm); setup_new_exec(bprm);
install_exec_creds(bprm);
current->mm->end_code = ex.a_text + current->mm->end_code = ex.a_text +
(current->mm->start_code = N_TXTADDR(ex)); (current->mm->start_code = N_TXTADDR(ex));
...@@ -174,7 +175,6 @@ static int load_aout_binary(struct linux_binprm * bprm) ...@@ -174,7 +175,6 @@ static int load_aout_binary(struct linux_binprm * bprm)
if (retval < 0) if (retval < 0)
return retval; return retval;
install_exec_creds(bprm);
if (N_MAGIC(ex) == OMAGIC) { if (N_MAGIC(ex) == OMAGIC) {
unsigned long text_addr, map_size; unsigned long text_addr, map_size;
......
...@@ -353,6 +353,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) ...@@ -353,6 +353,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
current->personality |= READ_IMPLIES_EXEC; current->personality |= READ_IMPLIES_EXEC;
setup_new_exec(bprm); setup_new_exec(bprm);
install_exec_creds(bprm);
set_binfmt(&elf_fdpic_format); set_binfmt(&elf_fdpic_format);
...@@ -434,7 +435,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) ...@@ -434,7 +435,6 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
current->mm->start_stack = current->mm->start_brk + stack_size; current->mm->start_stack = current->mm->start_brk + stack_size;
#endif #endif
install_exec_creds(bprm);
if (create_elf_fdpic_tables(bprm, current->mm, if (create_elf_fdpic_tables(bprm, current->mm,
&exec_params, &interp_params) < 0) &exec_params, &interp_params) < 0)
goto error; goto error;
......
...@@ -541,6 +541,7 @@ static int load_flat_file(struct linux_binprm *bprm, ...@@ -541,6 +541,7 @@ static int load_flat_file(struct linux_binprm *bprm,
/* OK, This is the point of no return */ /* OK, This is the point of no return */
set_personality(PER_LINUX_32BIT); set_personality(PER_LINUX_32BIT);
setup_new_exec(bprm); setup_new_exec(bprm);
install_exec_creds(bprm);
} }
/* /*
...@@ -963,8 +964,6 @@ static int load_flat_binary(struct linux_binprm *bprm) ...@@ -963,8 +964,6 @@ static int load_flat_binary(struct linux_binprm *bprm)
} }
} }
install_exec_creds(bprm);
set_binfmt(&flat_format); set_binfmt(&flat_format);
#ifdef CONFIG_MMU #ifdef CONFIG_MMU
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册