diff options
author | Anton Blanchard <anton@samba.org> | 2009-02-21 20:50:04 -0500 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2009-02-22 23:53:20 -0500 |
commit | 912f9ee21c836081e3c96dfe61025841ebeb95da (patch) | |
tree | 289e0c461cb651d041a2f1df359d88f285b82b4d /arch/powerpc/kernel/process.c | |
parent | d839088caec6891a5070f0b1ce61031e458533a9 (diff) |
powerpc: Randomise the brk region
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>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/kernel/process.c')
-rw-r--r-- | arch/powerpc/kernel/process.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index 69b9d2d3cb84..30b149ce7598 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c | |||
@@ -1147,3 +1147,26 @@ unsigned long arch_align_stack(unsigned long sp) | |||
1147 | sp -= get_random_int() & ~PAGE_MASK; | 1147 | sp -= get_random_int() & ~PAGE_MASK; |
1148 | return sp & ~0xf; | 1148 | return sp & ~0xf; |
1149 | } | 1149 | } |
1150 | |||
1151 | static inline unsigned long brk_rnd(void) | ||
1152 | { | ||
1153 | unsigned long rnd = 0; | ||
1154 | |||
1155 | /* 8MB for 32bit, 1GB for 64bit */ | ||
1156 | if (is_32bit_task()) | ||
1157 | rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT))); | ||
1158 | else | ||
1159 | rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT))); | ||
1160 | |||
1161 | return rnd << PAGE_SHIFT; | ||
1162 | } | ||
1163 | |||
1164 | unsigned long arch_randomize_brk(struct mm_struct *mm) | ||
1165 | { | ||
1166 | unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd()); | ||
1167 | |||
1168 | if (ret < mm->brk) | ||
1169 | return mm->brk; | ||
1170 | |||
1171 | return ret; | ||
1172 | } | ||