public inbox for linuxppc-dev@ozlabs.org 
 help / color / mirror / Atom feed
From: Anton Blanchard <anton@samba•org>
To: linuxppc-dev@ozlabs•org
Subject: [patch 07/10] powerpc: Randomise the brk region
Date: Sun, 22 Feb 2009 22:50:04 +1100	[thread overview]
Message-ID: <20090222115332.546296226@samba.org> (raw)
In-Reply-To: 20090222114957.213647384@samba.org

Randomize the heap.

before:
tundro2:~ # sleep 1 & cat /proc/${!}/maps | grep heap
10017000-10118000 rw-p 10017000 00:00 0                                  [heap]
10017000-10118000 rw-p 10017000 00:00 0                                  [heap]
10017000-10118000 rw-p 10017000 00:00 0                                  [heap]
10017000-10118000 rw-p 10017000 00:00 0                                  [heap]
10017000-10118000 rw-p 10017000 00:00 0                                  [heap]


after
tundro2:~ # sleep 1 & cat /proc/${!}/maps | grep heap
19419000-1951a000 rw-p 19419000 00:00 0                                  [heap]
325ff000-32700000 rw-p 325ff000 00:00 0                                  [heap]
1a97c000-1aa7d000 rw-p 1a97c000 00:00 0                                  [heap]
1cc60000-1cd61000 rw-p 1cc60000 00:00 0                                  [heap]
1afa9000-1b0aa000 rw-p 1afa9000 00:00 0                                  [heap]

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

Index: linux-2.6/arch/powerpc/include/asm/elf.h
===================================================================
--- linux-2.6.orig/arch/powerpc/include/asm/elf.h	2009-02-20 16:06:32.000000000 +1100
+++ linux-2.6/arch/powerpc/include/asm/elf.h	2009-02-22 11:58:02.000000000 +1100
@@ -275,6 +275,9 @@
 	(0x7ff >> (PAGE_SHIFT - 12)) : \
 	(0x3ffff >> (PAGE_SHIFT - 12)))
 
+extern unsigned long arch_randomize_brk(struct mm_struct *mm);
+#define arch_randomize_brk arch_randomize_brk
+
 #endif /* __KERNEL__ */
 
 /*
Index: linux-2.6/arch/powerpc/kernel/process.c
===================================================================
--- linux-2.6.orig/arch/powerpc/kernel/process.c	2009-02-20 16:06:32.000000000 +1100
+++ linux-2.6/arch/powerpc/kernel/process.c	2009-02-22 11:58:02.000000000 +1100
@@ -1131,3 +1131,26 @@
 		sp -= get_random_int() & ~PAGE_MASK;
 	return sp & ~0xf;
 }
+
+static inline unsigned long brk_rnd(void)
+{
+        unsigned long rnd = 0;
+
+	/* 8MB for 32bit, 1GB for 64bit */
+	if (is_32bit_task())
+		rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
+	else
+		rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
+
+	return rnd << PAGE_SHIFT;
+}
+
+unsigned long arch_randomize_brk(struct mm_struct *mm)
+{
+	unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
+
+	if (ret < mm->brk)
+		return mm->brk;
+
+	return ret;
+}

-- 

  parent reply	other threads:[~2009-02-22 11:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-22 11:49 [patch 00/10] PowerPC address space randomisation Anton Blanchard
2009-02-22 11:49 ` [patch 01/10] powerpc: Move is_32bit_task Anton Blanchard
2009-02-22 11:49 ` [patch 02/10] powerpc: Use new layout for 64bit binaries Anton Blanchard
2009-02-22 11:50 ` [patch 03/10] powerpc: Rearrange mmap.c Anton Blanchard
2009-02-22 11:50 ` [patch 04/10] powerpc: Randomise mmap start address Anton Blanchard
2009-02-22 11:50 ` [patch 05/10] powerpc: More stack randomisation for 64bit binaries Anton Blanchard
2009-02-22 11:50 ` [patch 06/10] powerpc: Randomise lower bits of stack address Anton Blanchard
2009-02-22 11:50 ` Anton Blanchard [this message]
2009-02-22 11:50 ` [patch 08/10] powerpc: Ensure random space between stack and mmaps Anton Blanchard
2009-02-22 11:50 ` [patch 09/10] powerpc: Increase stack gap on 64bit binaries Anton Blanchard
2009-02-22 11:50 ` [patch 10/10] powerpc: Randomise PIEs Anton Blanchard

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=20090222115332.546296226@samba.org \
    --to=anton@samba$(echo .)org \
    --cc=linuxppc-dev@ozlabs$(echo .)org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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