Skip to content

Commit

Permalink
binfmt: Move install_exec_creds after setup_new_exec to match binfmt_elf
Browse files Browse the repository at this point in the history
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: Greg Ungerer <[email protected]>

Ref: 9f834ec ("binfmt_elf: switch to new creds when switching to new mm")
Reviewed-by: Kees Cook <[email protected]>
Reviewed-by: Greg Ungerer <[email protected]>
Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed May 7, 2020
1 parent 6a8b55e commit e7f7785
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions arch/x86/ia32/ia32_aout.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ static int load_aout_binary(struct linux_binprm *bprm)
set_personality_ia32(false);

setup_new_exec(bprm);
install_exec_creds(bprm);

regs->cs = __USER32_CS;
regs->r8 = regs->r9 = regs->r10 = regs->r11 = regs->r12 =
Expand All @@ -156,8 +157,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;

Expand Down
2 changes: 1 addition & 1 deletion fs/binfmt_aout.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
set_personality(PER_LINUX);
#endif
setup_new_exec(bprm);
install_exec_creds(bprm);

current->mm->end_code = ex.a_text +
(current->mm->start_code = N_TXTADDR(ex));
Expand All @@ -174,7 +175,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;
Expand Down
2 changes: 1 addition & 1 deletion fs/binfmt_elf_fdpic.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
current->personality |= READ_IMPLIES_EXEC;

setup_new_exec(bprm);
install_exec_creds(bprm);

set_binfmt(&elf_fdpic_format);

Expand Down Expand Up @@ -434,7 +435,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;
Expand Down
3 changes: 1 addition & 2 deletions fs/binfmt_flat.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ static int load_flat_file(struct linux_binprm *bprm,
/* OK, This is the point of no return */
set_personality(PER_LINUX_32BIT);
setup_new_exec(bprm);
install_exec_creds(bprm);
}

/*
Expand Down Expand Up @@ -963,8 +964,6 @@ static int load_flat_binary(struct linux_binprm *bprm)
}
}

install_exec_creds(bprm);

set_binfmt(&flat_format);

#ifdef CONFIG_MMU
Expand Down

0 comments on commit e7f7785

Please sign in to comment.