提交 b8383831 编写于 作者: K Kees Cook 提交者: Linus Torvalds

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.orgSigned-off-by: NKees 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: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 8f2af155
...@@ -330,6 +330,7 @@ static int load_aout_binary(struct linux_binprm * bprm) ...@@ -330,6 +330,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
#ifdef __alpha__ #ifdef __alpha__
regs->gp = ex.a_gpvalue; regs->gp = ex.a_gpvalue;
#endif #endif
finalize_exec(bprm);
start_thread(regs, ex.a_entry, current->mm->start_stack); start_thread(regs, ex.a_entry, current->mm->start_stack);
return 0; return 0;
} }
......
...@@ -1155,6 +1155,7 @@ static int load_elf_binary(struct linux_binprm *bprm) ...@@ -1155,6 +1155,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
ELF_PLAT_INIT(regs, reloc_func_desc); ELF_PLAT_INIT(regs, reloc_func_desc);
#endif #endif
finalize_exec(bprm);
start_thread(regs, elf_entry, bprm->p); start_thread(regs, elf_entry, bprm->p);
retval = 0; retval = 0;
out: out:
......
...@@ -463,6 +463,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm) ...@@ -463,6 +463,7 @@ static int load_elf_fdpic_binary(struct linux_binprm *bprm)
dynaddr); dynaddr);
#endif #endif
finalize_exec(bprm);
/* everything is now ready... get the userspace context ready to roll */ /* everything is now ready... get the userspace context ready to roll */
entryaddr = interp_params.entry_addr ?: exec_params.entry_addr; entryaddr = interp_params.entry_addr ?: exec_params.entry_addr;
start_thread(regs, entryaddr, current->mm->start_stack); start_thread(regs, entryaddr, current->mm->start_stack);
......
...@@ -994,6 +994,7 @@ static int load_flat_binary(struct linux_binprm *bprm) ...@@ -994,6 +994,7 @@ static int load_flat_binary(struct linux_binprm *bprm)
FLAT_PLAT_INIT(regs); FLAT_PLAT_INIT(regs);
#endif #endif
finalize_exec(bprm);
pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n", pr_debug("start_thread(regs=0x%p, entry=0x%lx, start_stack=0x%lx)\n",
regs, start_addr, current->mm->start_stack); regs, start_addr, current->mm->start_stack);
start_thread(regs, start_addr, current->mm->start_stack); start_thread(regs, start_addr, current->mm->start_stack);
......
...@@ -1384,6 +1384,12 @@ void setup_new_exec(struct linux_binprm * bprm) ...@@ -1384,6 +1384,12 @@ void setup_new_exec(struct linux_binprm * bprm)
} }
EXPORT_SYMBOL(setup_new_exec); EXPORT_SYMBOL(setup_new_exec);
/* Runs immediately before start_thread() takes over. */
void finalize_exec(struct linux_binprm *bprm)
{
}
EXPORT_SYMBOL(finalize_exec);
/* /*
* Prepare credentials and lock ->cred_guard_mutex. * Prepare credentials and lock ->cred_guard_mutex.
* install_exec_creds() commits the new creds and drops the lock. * install_exec_creds() commits the new creds and drops the lock.
......
...@@ -118,6 +118,7 @@ extern int __must_check remove_arg_zero(struct linux_binprm *); ...@@ -118,6 +118,7 @@ extern int __must_check remove_arg_zero(struct linux_binprm *);
extern int search_binary_handler(struct linux_binprm *); extern int search_binary_handler(struct linux_binprm *);
extern int flush_old_exec(struct linux_binprm * bprm); extern int flush_old_exec(struct linux_binprm * bprm);
extern void setup_new_exec(struct linux_binprm * bprm); extern void setup_new_exec(struct linux_binprm * bprm);
extern void finalize_exec(struct linux_binprm *bprm);
extern void would_dump(struct linux_binprm *, struct file *); extern void would_dump(struct linux_binprm *, struct file *);
extern int suid_dumpable; extern int suid_dumpable;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册