Skip to content

Commit b838383

Browse files
keestorvalds
authored andcommitted
exec: introduce finalize_exec() before start_thread()
Provide a final callback into fs/exec.c before start_thread() takes over, to handle any last-minute changes, like the coming restoration of the stack limit. Link: http://lkml.kernel.org/r/1518638796-20819-3-git-send-email-keescook@chromium.org Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Ben Hutchings <ben@decadent.org.uk> Cc: Ben Hutchings <ben.hutchings@codethink.co.uk> Cc: Brad Spengler <spender@grsecurity.net> Cc: Greg KH <greg@kroah.com> Cc: Hugh Dickins <hughd@google.com> Cc: "Jason A. Donenfeld" <Jason@zx2c4.com> Cc: Laura Abbott <labbott@redhat.com> Cc: Michal Hocko <mhocko@kernel.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Rik van Riel <riel@redhat.com> Cc: Willy Tarreau <w@1wt.eu> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8f2af15 commit b838383

File tree

6 files changed

+11
-0
lines changed

6 files changed

+11
-0
lines changed

fs/binfmt_aout.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
330330
#ifdef __alpha__
331331
regs->gp = ex.a_gpvalue;
332332
#endif
333+
finalize_exec(bprm);
333334
start_thread(regs, ex.a_entry, current->mm->start_stack);
334335
return 0;
335336
}

fs/binfmt_elf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
11551155
ELF_PLAT_INIT(regs, reloc_func_desc);
11561156
#endif
11571157

1158+
finalize_exec(bprm);
11581159
start_thread(regs, elf_entry, bprm->p);
11591160
retval = 0;
11601161
out:

fs/binfmt_elf_fdpic.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
463463
dynaddr);
464464
#endif
465465

466+
finalize_exec(bprm);
466467
/* everything is now ready... get the userspace context ready to roll */
467468
entryaddr = interp_params.entry_addr ?: exec_params.entry_addr;
468469
start_thread(regs, entryaddr, current->mm->start_stack);

fs/binfmt_flat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
994994
FLAT_PLAT_INIT(regs);
995995
#endif
996996

997+
finalize_exec(bprm);
997998
pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n",
998999
regs, start_addr, current->mm->start_stack);
9991000
start_thread(regs, start_addr, current->mm->start_stack);

fs/exec.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,12 @@ void setup_new_exec(struct linux_binprm * bprm)
13841384
}
13851385
EXPORT_SYMBOL(setup_new_exec);
13861386

1387+
/* Runs immediately before start_thread() takes over. */
1388+
void finalize_exec(struct linux_binprm *bprm)
1389+
{
1390+
}
1391+
EXPORT_SYMBOL(finalize_exec);
1392+
13871393
/*
13881394
* Prepare credentials and lock ->cred_guard_mutex.
13891395
* install_exec_creds() commits the new creds and drops the lock.

include/linux/binfmts.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ extern int __must_check remove_arg_zero(struct linux_binprm *);
118118
extern int search_binary_handler(struct linux_binprm *);
119119
extern int flush_old_exec(struct linux_binprm * bprm);
120120
extern void setup_new_exec(struct linux_binprm * bprm);
121+
extern void finalize_exec(struct linux_binprm *bprm);
121122
extern void would_dump(struct linux_binprm *, struct file *);
122123

123124
extern int suid_dumpable;

0 commit comments

Comments
 (0)