From: Jakub Jelinek <jakub@redhat.com>
To: Jiri Kosina <jkosina@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Jan Kratochvil <honza@jikos.cz>, Ingo Molnar <mingo@elte.hu>,
Rik van Riel <riel@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH][RESEND] PIE randomization
Date: Wed, 4 Jul 2007 04:25:54 -0400 [thread overview]
Message-ID: <20070704082554.GQ7012@devserv.devel.redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0705231044540.22906@jikos.suse.cz>
On Wed, May 23, 2007 at 10:50:24AM +0200, Jiri Kosina wrote:
> From: Jan Kratochvil <honza@jikos.cz>
>
> This patch is using mmap()'s randomization functionality in such a way
> that it maps the main executable of (specially compiled/linked -pie/-fpie)
> ET_DYN binaries onto a random address (in cases in which mmap() is allowed
> to perform a randomization).
>
> Origin of this patch is in exec-shield
> (http://people.redhat.com/mingo/exec-shield/)
>
> Signed-off-by: Jan Kratochvil <honza@jikos.cz>
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Roland McGrath <roland@redhat.com>
> Cc: Jakub Jelinek <jakub@redhat.com>
> -#define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
> +#define BAD_ADDR(x) ((unsigned long)(x) >= PAGE_MASK)
...
> @@ -442,8 +491,7 @@ static unsigned long load_elf_interp(str
> goto out_close;
> }
>
> - *interp_load_addr = load_addr;
> - error = ((unsigned long)interp_elf_ex->e_entry) + load_addr;
> + error = load_addr;
...
> if (elf_interpreter) {
> - if (interpreter_type == INTERPRETER_AOUT)
> + if (interpreter_type == INTERPRETER_AOUT) {
> elf_entry = load_aout_interp(&loc->interp_ex,
> interpreter);
> - else
> + } else {
> + unsigned long interp_map_addr; /* unused */
> +
> elf_entry = load_elf_interp(&loc->interp_elf_ex,
> interpreter,
> - &interp_load_addr);
> + &interp_map_addr,
> + load_bias);
> + if (!BAD_ADDR(elf_entry)) {
> + /*
> + * load_elf_interp() returns relocation
> + * adjustment
> + */
> + interp_load_addr = elf_entry;
> + elf_entry += loc->interp_elf_ex.e_entry;
> + }
> + }
> if (BAD_ADDR(elf_entry)) {
> force_sig(SIGSEGV, current);
> retval = IS_ERR((void *)elf_entry) ?
The above highlighted changes are the cause of random segfaults of PIE
binaries. See
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=246623
The problem is if ld.so is prelinked to some address in the area where
the kernel actually maps it, particularly if elf_map in load_elf_interp
returns an address one page below its first PT_LOAD segments vaddr.
Then load_addr (it is a load bias actually) returned from load_elf_interp
is 0xfffff000 (on 32-bit kernels) and BAD_ADDR are all
addresses >= 0xfffff000 (on i?86).
The fix should be either changing the definition of BAD_ADDR to
e.g. IS_ERR_VALUE(x), or at least changing the if (!BAD_ADDR(elf_entry)) {
above to if (!IS_ERR_VALUE(elf_entry)) {, the second BAD_ADDR can already
stay, because at that place elf_entry is no longer a bias (difference
between actual and preferred load address), but an actual address, where
very high addresses are of course invalid.
Jakub
next prev parent reply other threads:[~2007-07-04 8:26 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-11 12:33 [PATCH][RESEND] PIE randomization Jan Kratochvil
2007-05-11 19:56 ` Andrew Morton
2007-05-11 20:18 ` Jiri Kosina
2007-05-11 20:36 ` Andrew Morton
2007-05-11 22:41 ` Ulrich Drepper
2007-05-11 23:50 ` Jiri Kosina
2007-05-16 17:14 ` Jiri Kosina
2007-05-17 20:24 ` Jan Kratochvil
2007-05-17 21:50 ` Jiri Kosina
2007-05-18 17:29 ` Andrew Morton
2007-05-21 14:58 ` Hugh Dickins
2007-05-22 23:16 ` Andrew Morton
2007-05-23 8:50 ` Jiri Kosina
2007-07-04 8:25 ` Jakub Jelinek [this message]
2007-07-04 17:35 ` Jiri Kosina
2007-07-05 20:53 ` Chuck Ebbert
2007-07-05 20:57 ` Rik van Riel
2007-07-07 0:13 ` Jiri Kosina
2007-07-07 12:30 ` Jakub Jelinek
2007-07-09 11:41 ` Jiri Kosina
2007-07-09 21:58 ` Jiri Kosina
2007-07-10 9:47 ` Jakub Jelinek
2007-07-11 9:58 ` Jiri Kosina
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=20070704082554.GQ7012@devserv.devel.redhat.com \
--to=jakub@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=honza@jikos.cz \
--cc=jkosina@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=riel@redhat.com \
/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