提交 0693ffeb 编写于 作者: A Alexey Dobriyan 提交者: Linus Torvalds

fs/binfmt_elf.c: allocate less for static executable

PT_INTERP ELF header can be spared if executable is static.
Signed-off-by: NAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/20200219185012.GB4871@avx2Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 c69bcc93
...@@ -699,17 +699,11 @@ static int load_elf_binary(struct linux_binprm *bprm) ...@@ -699,17 +699,11 @@ static int load_elf_binary(struct linux_binprm *bprm)
unsigned long reloc_func_desc __maybe_unused = 0; unsigned long reloc_func_desc __maybe_unused = 0;
int executable_stack = EXSTACK_DEFAULT; int executable_stack = EXSTACK_DEFAULT;
struct elfhdr *elf_ex = (struct elfhdr *)bprm->buf; struct elfhdr *elf_ex = (struct elfhdr *)bprm->buf;
struct elfhdr *interp_elf_ex; struct elfhdr *interp_elf_ex = NULL;
struct arch_elf_state arch_state = INIT_ARCH_ELF_STATE; struct arch_elf_state arch_state = INIT_ARCH_ELF_STATE;
struct mm_struct *mm; struct mm_struct *mm;
struct pt_regs *regs; struct pt_regs *regs;
interp_elf_ex = kmalloc(sizeof(*interp_elf_ex), GFP_KERNEL);
if (!interp_elf_ex) {
retval = -ENOMEM;
goto out_ret;
}
retval = -ENOEXEC; retval = -ENOEXEC;
/* First of all, some simple consistency checks */ /* First of all, some simple consistency checks */
if (memcmp(elf_ex->e_ident, ELFMAG, SELFMAG) != 0) if (memcmp(elf_ex->e_ident, ELFMAG, SELFMAG) != 0)
...@@ -769,6 +763,12 @@ static int load_elf_binary(struct linux_binprm *bprm) ...@@ -769,6 +763,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
*/ */
would_dump(bprm, interpreter); would_dump(bprm, interpreter);
interp_elf_ex = kmalloc(sizeof(*interp_elf_ex), GFP_KERNEL);
if (!interp_elf_ex) {
retval = -ENOMEM;
goto out_free_ph;
}
/* Get the exec headers */ /* Get the exec headers */
retval = elf_read(interpreter, interp_elf_ex, retval = elf_read(interpreter, interp_elf_ex,
sizeof(*interp_elf_ex), 0); sizeof(*interp_elf_ex), 0);
...@@ -1074,6 +1074,8 @@ static int load_elf_binary(struct linux_binprm *bprm) ...@@ -1074,6 +1074,8 @@ static int load_elf_binary(struct linux_binprm *bprm)
allow_write_access(interpreter); allow_write_access(interpreter);
fput(interpreter); fput(interpreter);
kfree(interp_elf_ex);
} else { } else {
elf_entry = e_entry; elf_entry = e_entry;
if (BAD_ADDR(elf_entry)) { if (BAD_ADDR(elf_entry)) {
...@@ -1152,12 +1154,11 @@ static int load_elf_binary(struct linux_binprm *bprm) ...@@ -1152,12 +1154,11 @@ static int load_elf_binary(struct linux_binprm *bprm)
start_thread(regs, elf_entry, bprm->p); start_thread(regs, elf_entry, bprm->p);
retval = 0; retval = 0;
out: out:
kfree(interp_elf_ex);
out_ret:
return retval; return retval;
/* error cleanup */ /* error cleanup */
out_free_dentry: out_free_dentry:
kfree(interp_elf_ex);
kfree(interp_elf_phdata); kfree(interp_elf_phdata);
allow_write_access(interpreter); allow_write_access(interpreter);
if (interpreter) if (interpreter)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册