From: Baoquan He <bhe@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
oleg@redhat.com, mhocko@kerne.org, keescook@chromium.org,
jkosina@suse.cz, mingo@elte.hu, torvalds@linux-foundation.org,
Baoquan He <bhe@redhat.com>
Subject: [PATCH 2/3] binfmt_elf: Get the total_size only for dynamic loader in load_elf_binary()
Date: Fri, 6 Oct 2017 11:37:57 +0800 [thread overview]
Message-ID: <1507261078-23615-3-git-send-email-bhe@redhat.com> (raw)
In-Reply-To: <1507261078-23615-1-git-send-email-bhe@redhat.com>
In commit:
eab09532d4 ("binfmt_elf: use ELF_ET_DYN_BASE only for PIE")
... PIE programs are loaded offset from ELF_ET_DYN_BASE, and its map
has been set as MAP_FIXED. Only dynamic loader will be mapped from
below mm->mmap_base (E.g "./ld.so someprog"), and need take account
of the need to allocate sufficient space for the entire loader image
to avoid the case that the first PT_LOAD segment is mapped below
mm->mmap_base, the subsequent PT_LOAD segment(s) end up being mapped
above mm->mmap_base into the area that is supposed to be the "gap"
between the stack and mm->mmap_base.
Whether it's harmless or not, we should not allow program to map above
mm->mmap_base. So here change to get the total_size only for dynamic
loader in load_elf_binary().
Signed-off-by: Baoquan He <bhe@redhat.com>
---
fs/binfmt_elf.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index 72b7ecba7ead..d7a8a53a6f18 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -967,9 +967,17 @@ static int load_elf_binary(struct linux_binprm *bprm)
if (current->flags & PF_RANDOMIZE)
load_bias += arch_mmap_rnd();
elf_flags |= MAP_FIXED;
- } else
+ } else {
load_bias = 0;
+ total_size = total_mapping_size(elf_phdata,
+ loc->elf_ex.e_phnum);
+ if (!total_size) {
+ retval = -EINVAL;
+ goto out_free_dentry;
+ }
+ }
+
/*
* Since load_bias is used for all subsequent loading
* calculations, we must lower it by the first vaddr
@@ -978,13 +986,6 @@ static int load_elf_binary(struct linux_binprm *bprm)
* is then page aligned.
*/
load_bias = ELF_PAGESTART(load_bias - vaddr);
-
- total_size = total_mapping_size(elf_phdata,
- loc->elf_ex.e_phnum);
- if (!total_size) {
- retval = -EINVAL;
- goto out_free_dentry;
- }
}
error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
--
2.5.5
next prev parent reply other threads:[~2017-10-06 3:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-06 3:37 [PATCH 0/3] binfmt_elf: Clean up codes related to total_size passed into elf_map() Baoquan He
2017-10-06 3:37 ` [PATCH 1/3] binfmt_elf: Clean up the variable name of map flags Baoquan He
2017-10-06 3:37 ` Baoquan He [this message]
2017-10-06 3:37 ` [PATCH 3/3] binfmt_elf: Search an unmapped area with total_size but not map the whole image Baoquan He
2017-11-07 12:00 ` [PATCH 0/3] binfmt_elf: Clean up codes related to total_size passed into elf_map() Baoquan He
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=1507261078-23615-3-git-send-email-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=jkosina@suse.cz \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@kerne.org \
--cc=mingo@elte.hu \
--cc=oleg@redhat.com \
--cc=torvalds@linux-foundation.org \
--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
all inboxes | Powered by JetHome®