e0adc28
On Mon, 3 Oct 2011, Josh Boyer wrote:
e0adc28
e0adc28
> > > Perhaps another check here for randomize?  Something like:
e0adc28
> > > 
e0adc28
> > > #if defined(CONFIG_X86) || defined(CONFIG_ARM)
e0adc28
> > > 		if (current->flags & PF_RANDOMIZE)
e0adc28
> > > 			load_bias = 0;
e0adc28
> > > 		else if (vaddr)
e0adc28
> > > 			load_bias = 0;
e0adc28
> > > 		else
e0adc28
> > > 			load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE);
e0adc28
> > > #else
e0adc28
> > > 		load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
e0adc28
> > > #endif
e0adc28
> > > 
e0adc28
> > > If that's stupid, then feel free to tell me.  I won't pretend like I
e0adc28
> > > understand what is going on here yet, but based on the explanation you
e0adc28
> > > provided that might work.
e0adc28
> > 
e0adc28
> > I have just verified my hunch that the original patch from H.J. / Josh 
e0adc28
> > breaks ASLR completely, so Andrew, please drop it for now.
e0adc28
> 
e0adc28
> Yes, please drop the original.
e0adc28
e0adc28
Thanks.
e0adc28
e0adc28
> > I am now looking into how to fix things properly.
e0adc28
> > 
e0adc28
> > Josh, looking at what you are proposing -- do you see any reason to make 
e0adc28
> > the behavior different in #else branch and in !(current->flags & 
e0adc28
> > PF_RANDOMIZE) case?
e0adc28
> 
e0adc28
> I was mostly just trying to adapt H.J.'s patch to account for the
e0adc28
> PF_RANDOMIZE case.  Looking at it a bit more, I'm not sure why they
e0adc28
> would need to be different.  H.J., do you recall why you made that
e0adc28
> change originally?
e0adc28
e0adc28
How about the patch below instead? It survives my testing, and I believe 
e0adc28
it handles both cases properly.
e0adc28
e0adc28
Confirmation from the original bug reporter would obviously be a nice 
e0adc28
bonus too :)
e0adc28
e0adc28
e0adc28
e0adc28
e0adc28
From: Jiri Kosina <jkosina@suse.cz>
e0adc28
Subject: [PATCH] binfmt_elf: fix PIE execution with randomization disabled
e0adc28
e0adc28
The case of address space randomization being disabled in runtime through
e0adc28
randomize_va_space sysctl is not treated properly in load_elf_binary(),
e0adc28
resulting in SIGKILL coming at exec() time for certain PIE-linked binaries
e0adc28
in case the randomization has been disabled at runtime prior to calling
e0adc28
exec().
e0adc28
e0adc28
Handle the randomize_va_space == 0 case the same way as if we were not
e0adc28
supporting .text randomization at all.
e0adc28
e0adc28
Based on original patch by H.J. Lu <hongjiu.lu@intel.com> and
e0adc28
Josh Boyer <jwboyer@redhat.com>
e0adc28
e0adc28
Cc: Ingo Molnar <mingo@elte.hu>
e0adc28
Cc: Jiri Kosina <jkosina@suse.cz>
e0adc28
Cc: Nicolas Pitre <nicolas.pitre@linaro.org>
e0adc28
Cc: Russell King <rmk@arm.linux.org.uk>
e0adc28
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
e0adc28
---
e0adc28
 fs/binfmt_elf.c |    5 ++++-
e0adc28
 1 files changed, 4 insertions(+), 1 deletions(-)
e0adc28
e0adc28
diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
e0adc28
index dd0fdfc..bb11fe4 100644
e0adc28
--- a/fs/binfmt_elf.c
e0adc28
+++ b/fs/binfmt_elf.c
e0adc28
@@ -795,7 +795,10 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
e0adc28
 			 * might try to exec.  This is because the brk will
e0adc28
 			 * follow the loader, and is not movable.  */
e0adc28
 #if defined(CONFIG_X86) || defined(CONFIG_ARM)
e0adc28
-			load_bias = 0;
e0adc28
+			if (current->flags & PF_RANDOMIZE)
e0adc28
+				load_bias = 0;
e0adc28
+			else
e0adc28
+				load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
e0adc28
 #else
e0adc28
 			load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
e0adc28
 #endif
e0adc28