Patchwork [10/10] powerpc: Randomise PIEs

login
register
mail settings
Submitter Anton Blanchard
Date Feb. 22, 2009, 11:50 a.m.
Message ID <20090222115332.932267488@samba.org>
Download mbox | patch
Permalink /patch/23529/
State Accepted, archived
Commit 501cb16d3cfdcca99ac26fe122079f2a43b046b8
Delegated to: Benjamin Herrenschmidt
Headers show

Comments

Anton Blanchard - Feb. 22, 2009, 11:50 a.m.
Randomise ELF_ET_DYN_BASE, which is used when loading position independent
executables.

Signed-off-by: Anton Blanchard <anton@samba.org>
---

Patch

Index: linux-2.6/arch/powerpc/include/asm/elf.h
===================================================================
--- linux-2.6.orig/arch/powerpc/include/asm/elf.h	2009-02-22 21:18:04.000000000 +1100
+++ linux-2.6/arch/powerpc/include/asm/elf.h	2009-02-22 21:34:49.000000000 +1100
@@ -178,7 +178,8 @@ 
    the loader.  We need to make sure that it is out of the way of the program
    that it will "exec", and that there is sufficient room for the brk.  */
 
-#define ELF_ET_DYN_BASE         (0x20000000)
+extern unsigned long randomize_et_dyn(unsigned long base);
+#define ELF_ET_DYN_BASE		(randomize_et_dyn(0x20000000))
 
 /*
  * Our registers are always unsigned longs, whether we're a 32 bit
Index: linux-2.6/arch/powerpc/kernel/process.c
===================================================================
--- linux-2.6.orig/arch/powerpc/kernel/process.c	2009-02-22 21:21:14.000000000 +1100
+++ linux-2.6/arch/powerpc/kernel/process.c	2009-02-22 21:36:02.000000000 +1100
@@ -1154,3 +1154,13 @@ 
 
 	return ret;
 }
+
+unsigned long randomize_et_dyn(unsigned long base)
+{
+	unsigned long ret = PAGE_ALIGN(base + brk_rnd());
+
+	if (ret < base)
+		return base;
+
+	return ret;
+}