From: Akira Kawata <akirakawata1@gmail.com>
To: akpm@linux-foundation.org, adobriyan@gmail.com,
viro@zeniv.linux.org.uk, keescook@chromium.org,
linux-fsdevel@vger.kernel.org, lukas.bulwahn@gmail.com
Cc: akirakawata1@gmail.com, Eric Biederman <ebiederm@xmission.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 2/2] fs/binfmt_elf: Refactor load_elf_binary function
Date: Mon, 13 Dec 2021 08:24:15 +0900 [thread overview]
Message-ID: <20211212232414.1402199-6-akirakawata1@gmail.com> (raw)
In-Reply-To: <20211212232414.1402199-1-akirakawata1@gmail.com>
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>
---
fs/binfmt_elf.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 828e88841cb4..48206fd1a20e 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -822,8 +822,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;
@@ -1073,12 +1073,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
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) {
/*
@@ -1138,10 +1138,10 @@ static int load_elf_binary(struct linux_binprm *bprm)
/*
* Calculate the entire size of the ELF mapping (total_size).
- * (Note that load_addr_set is set to true later once the
+ * (Note that first_pt_load is set to false later once the
* initial mapping is performed.)
*/
- if (!load_addr_set) {
+ if (first_pt_load) {
total_size = total_mapping_size(elf_phdata,
elf_ex->e_phnum);
if (!total_size) {
@@ -1158,13 +1158,11 @@ static int load_elf_binary(struct linux_binprm *bprm)
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;
}
}
--
2.34.1
prev parent reply other threads:[~2021-12-12 23:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-12 23:24 [PATCH v4 0/2] [PATCH v4 0/2] fs/binfmt_elf: Fix AT_PHDR for unusual ELF files Akira Kawata
2021-12-12 23:24 ` [PATCH v4 1/2] " Akira Kawata
2022-01-27 5:01 ` Kees Cook
2022-01-27 12:56 ` Akira Kawata
2022-01-27 16:23 ` Kees Cook
2022-01-28 11:10 ` Akira Kawata
2022-01-28 19:56 ` Kees Cook
2021-12-12 23:24 ` [PATCH v4 2/2] fs/binfmt_elf: Refactor load_elf_binary function Akira Kawata
2022-01-27 5:11 ` Kees Cook
2021-12-12 23:24 ` [PATCH v4 0/2] [PATCH v4 0/2] fs/binfmt_elf: Fix AT_PHDR for unusual ELF files Akira Kawata
2021-12-12 23:35 ` Akira Kawata
2021-12-12 23:24 ` [PATCH v4 1/2] " Akira Kawata
2021-12-12 23:24 ` Akira Kawata [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211212232414.1402199-6-akirakawata1@gmail.com \
--to=akirakawata1@gmail.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas.bulwahn@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).