diff options
author | Heiko Carstens <heiko.carstens@de.ibm.com> | 2011-01-12 03:55:30 -0500 |
---|---|---|
committer | Martin Schwidefsky <sky@mschwide.boeblingen.de.ibm.com> | 2011-01-12 03:55:25 -0500 |
commit | 3351918282fd664e918a3175ddfae9b15656122e (patch) | |
tree | fcfcf8d8ab1ad7380d802276e0dc4a0026b70d84 /arch/s390 | |
parent | a05c90f1948baacedd0c3e7e3250225be4cae727 (diff) |
[S390] Randomise the brk region
Randomize heap address like other architectures do already.
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'arch/s390')
-rw-r--r-- | arch/s390/include/asm/elf.h | 3 | ||||
-rw-r--r-- | arch/s390/kernel/process.c | 18 |
2 files changed, 21 insertions, 0 deletions
diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h index 9dbd3e7a3bc3..457fb7c16236 100644 --- a/arch/s390/include/asm/elf.h +++ b/arch/s390/include/asm/elf.h | |||
@@ -220,4 +220,7 @@ struct linux_binprm; | |||
220 | #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 | 220 | #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 |
221 | int arch_setup_additional_pages(struct linux_binprm *, int); | 221 | int arch_setup_additional_pages(struct linux_binprm *, int); |
222 | 222 | ||
223 | extern unsigned long arch_randomize_brk(struct mm_struct *mm); | ||
224 | #define arch_randomize_brk arch_randomize_brk | ||
225 | |||
223 | #endif | 226 | #endif |
diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c index 38ff69e562c8..26d48fe72999 100644 --- a/arch/s390/kernel/process.c +++ b/arch/s390/kernel/process.c | |||
@@ -341,3 +341,21 @@ unsigned long arch_align_stack(unsigned long sp) | |||
341 | sp -= get_random_int() & ~PAGE_MASK; | 341 | sp -= get_random_int() & ~PAGE_MASK; |
342 | return sp & ~0xf; | 342 | return sp & ~0xf; |
343 | } | 343 | } |
344 | |||
345 | static inline unsigned long brk_rnd(void) | ||
346 | { | ||
347 | /* 8MB for 32bit, 1GB for 64bit */ | ||
348 | if (is_32bit_task()) | ||
349 | return (get_random_int() & 0x7ffUL) << PAGE_SHIFT; | ||
350 | else | ||
351 | return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT; | ||
352 | } | ||
353 | |||
354 | unsigned long arch_randomize_brk(struct mm_struct *mm) | ||
355 | { | ||
356 | unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd()); | ||
357 | |||
358 | if (ret < mm->brk) | ||
359 | return mm->brk; | ||
360 | return ret; | ||
361 | } | ||