Skip to contentSkip to conversation

PATCH: binfmt_elf: randomize PIE binaries (3rd try)

PATCH Marcus Meissner 1 participant 1 message Nov 14, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Randomizes -pie compiled binaries from 64k (0x10000) up to ELF_ET_DYN_BASE.

0 -> 64k is excluded to allow NULL ptr array accesses to fail.

Cc Ingo Molnar <[email protected]>
Cc Dave Jones <[email protected]>
Cc Arjan van de Ven <[email protected]>

----

 binfmt_elf.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/binfmt_elf.c renamed from fs/binfmt_elf.c.xx +7 -1
@@ -856,7 +856,13 @@
 			 * default mmap base, as well as whatever program they
 			 * might try to exec.  This is because the brk will
 			 * follow the loader, and is not movable.  */
-			load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
+			if (current->flags & PF_RANDOMIZE)
+				load_bias = randomize_range(0x10000,
+							    ELF_ET_DYN_BASE,
+							    0);
+			else
+				load_bias = ELF_ET_DYN_BASE;
+			load_bias = ELF_PAGESTART(load_bias - vaddr);
 		}
 
 		error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,