Skip to contentSkip to conversation

binfmt_elf: randomize PIE binaries (2nd try)

PATCH In review Marcus Meissner 2 participants 3 messages Oct 20, 2006

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

PATCH 1/1 binfmt_elf: randomize PIE binaries (2nd try)

Randomizes -pie compiled binaries from PAGE_SIZE up to ELF_ET_DYN_BASE.

0 -> PAGE_SIZE is excluded to allow NULL ptr accesses to fail.

----

 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(PAGE_SIZE,
+							    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,
#1 lore raw
Quoted 15 lines · Marcus Meissner

Randomizes -pie compiled binaries from PAGE_SIZE up to ELF_ET_DYN_BASE.

0 -> PAGE_SIZE is excluded to allow NULL ptr accesses to fail.

----

 binfmt_elf.c |    8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

fs/binfmt_elf.c 2006-10-20 10:51:27.000000000 +0200 line 862

Quoted 8 lines
fs/binfmt_elf.c 2006-10-20 10:51:27.000000000 +0200 renamed from fs/binfmt_elf.c.xx 2006-10-20 10:42:03.000000000 +0200 +4 -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(PAGE_SIZE,
+                                                           ELF_ET_DYN_BASE,
+                                                           0);

How about putting the two lines above on one line? ^^^^^

Quoted 1 line
fs/binfmt_elf.c 2006-10-20 10:51:27.000000000 +0200 renamed from fs/binfmt_elf.c.xx 2006-10-20 10:42:03.000000000 +0200 +1 -0
+                                                           ELF_ET_DYN_BASE, 0);
Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#2 lore raw
Quoted 13 lines · Jesper Juhl
Quoted 12 lines · Marcus Meissner

Randomizes -pie compiled binaries from PAGE_SIZE up to ELF_ET_DYN_BASE.

0 -> PAGE_SIZE is excluded to allow NULL ptr accesses to fail.

----
binfmt_elf.c | 8 +++++++-

1 file changed, 7 insertions(+), 1 deletion(-)
Quoted 15 lines

fs/binfmt_elf.c 2006-10-20 10:51:27.000000000 +0200 line 864

Quoted 13 lines
fs/binfmt_elf.c 2006-10-20 10:51:27.000000000 +0200 renamed from fs/binfmt_elf.c.xx 2006-10-20 10:42:03.000000000 +0200 +4 -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(PAGE_SIZE,
+                                                           
 ELF_ET_DYN_BASE,
+                                                           0);

How about putting the two lines above on one line? ^^^^^

My editor said it would end at column 80. Starting from 0 it would col 79 actually, but I did not want to risk it.

Ciao, Marcus