aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/mm
diff options
context:
space:
mode:
authorAnton Blanchard <anton@samba.org>2009-02-21 20:50:01 -0500
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2009-02-22 23:53:07 -0500
commit9f14c42d7582bf33bbe1e133d897a6942ceae08e (patch)
treefe95aaa735051496863f81f413afb2d3c128fb75 /arch/powerpc/mm
parent13a2cb3694d7237e6cc3e94fcb311b81908ccd06 (diff)
powerpc: Randomise mmap start address
Randomise mmap start address - 8MB on 32bit and 1GB on 64bit tasks. Until ppc32 uses the mmap.c functionality, this is ppc64 specific. Before: # ./test & cat /proc/${!}/maps|tail -2|head -1 f75fe000-f7fff000 rw-p f75fe000 00:00 0 f75fe000-f7fff000 rw-p f75fe000 00:00 0 f75fe000-f7fff000 rw-p f75fe000 00:00 0 f75fe000-f7fff000 rw-p f75fe000 00:00 0 f75fe000-f7fff000 rw-p f75fe000 00:00 0 After: # ./test & cat /proc/${!}/maps|tail -2|head -1 f718b000-f7b8c000 rw-p f718b000 00:00 0 f7551000-f7f52000 rw-p f7551000 00:00 0 f6ee7000-f78e8000 rw-p f6ee7000 00:00 0 f74d4000-f7ed5000 rw-p f74d4000 00:00 0 f6e9d000-f789e000 rw-p f6e9d000 00:00 0 Similar for 64bit, but with 1GB of scatter: # ./test & cat /proc/${!}/maps|tail -2|head -1 fffb97b5000-fffb97b6000 rw-p fffb97b5000 00:00 0 fffce9a3000-fffce9a4000 rw-p fffce9a3000 00:00 0 fffeaaf2000-fffeaaf3000 rw-p fffeaaf2000 00:00 0 fffd88ac000-fffd88ad000 rw-p fffd88ac000 00:00 0 fffbc62e000-fffbc62f000 rw-p fffbc62e000 00:00 0 Signed-off-by: Anton Blanchard <anton@samba.org> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/mm')
-rw-r--r--arch/powerpc/mm/mmap.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
index 8ff5757af0d7..f7376dbb653b 100644
--- a/arch/powerpc/mm/mmap.c
+++ b/arch/powerpc/mm/mmap.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/personality.h> 25#include <linux/personality.h>
26#include <linux/mm.h> 26#include <linux/mm.h>
27#include <linux/random.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28 29
29/* 30/*
@@ -45,6 +46,20 @@ static inline int mmap_is_legacy(void)
45 return sysctl_legacy_va_layout; 46 return sysctl_legacy_va_layout;
46} 47}
47 48
49static unsigned long mmap_rnd(void)
50{
51 unsigned long rnd = 0;
52
53 if (current->flags & PF_RANDOMIZE) {
54 /* 8MB for 32bit, 1GB for 64bit */
55 if (is_32bit_task())
56 rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
57 else
58 rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
59 }
60 return rnd << PAGE_SHIFT;
61}
62
48static inline unsigned long mmap_base(void) 63static inline unsigned long mmap_base(void)
49{ 64{
50 unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur; 65 unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
@@ -54,7 +69,7 @@ static inline unsigned long mmap_base(void)
54 else if (gap > MAX_GAP) 69 else if (gap > MAX_GAP)
55 gap = MAX_GAP; 70 gap = MAX_GAP;
56 71
57 return TASK_SIZE - (gap & PAGE_MASK); 72 return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
58} 73}
59 74
60/* 75/*