diff options
author | Akira Kawata <akirakawata1@gmail.com> | 2022-01-27 21:40:17 +0900 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2022-03-01 16:16:27 -0800 |
commit | 2b4bfbe0967697c9b5de83dbaf5b49db4b367ec0 (patch) | |
tree | 0ca6e896d2618bdcf05f116550477fac83d160aa | |
parent | 0da1d5002745cdc721bc018b582a8a9704d56c42 (diff) | |
download | linux-stable-2b4bfbe0967697c9b5de83dbaf5b49db4b367ec0.tar.gz linux-stable-2b4bfbe0967697c9b5de83dbaf5b49db4b367ec0.tar.bz2 linux-stable-2b4bfbe0967697c9b5de83dbaf5b49db4b367ec0.zip |
fs/binfmt_elf: Refactor load_elf_binary function
I delete load_addr because it is not used anymore. And I rename
load_addr_set to first_pt_load because it is used only to capture the
first iteration of the loop.
Signed-off-by: Akira Kawata <akirakawata1@gmail.com>
Acked-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220127124014.338760-3-akirakawata1@gmail.com
-rw-r--r-- | fs/binfmt_elf.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 600cec2173c8..4c5a2175f605 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -824,8 +824,8 @@ static int parse_elf_properties(struct file *f, const struct elf_phdr *phdr, static int load_elf_binary(struct linux_binprm *bprm) { struct file *interpreter = NULL; /* to shut gcc up */ - unsigned long load_addr, load_bias = 0, phdr_addr = 0; - int load_addr_set = 0; + unsigned long load_bias = 0, phdr_addr = 0; + int first_pt_load = 1; unsigned long error; struct elf_phdr *elf_ppnt, *elf_phdata, *interp_elf_phdata = NULL; struct elf_phdr *elf_property_phdata = NULL; @@ -1075,12 +1075,12 @@ out_free_interp: vaddr = elf_ppnt->p_vaddr; /* - * The first time through the loop, load_addr_set is false: + * The first time through the loop, first_pt_load is true: * layout will be calculated. Once set, use MAP_FIXED since * we know we've already safely mapped the entire region with * MAP_FIXED_NOREPLACE in the once-per-binary logic following. */ - if (load_addr_set) { + if (!first_pt_load) { elf_flags |= MAP_FIXED; } else if (elf_ex->e_type == ET_EXEC) { /* @@ -1171,13 +1171,11 @@ out_free_interp: goto out_free_dentry; } - if (!load_addr_set) { - load_addr_set = 1; - load_addr = (elf_ppnt->p_vaddr - elf_ppnt->p_offset); + if (first_pt_load) { + first_pt_load = 0; if (elf_ex->e_type == ET_DYN) { load_bias += error - ELF_PAGESTART(load_bias + vaddr); - load_addr += load_bias; reloc_func_desc = load_bias; } } |