Commit df1ca53c authored by Heiko Carstens's avatar Heiko Carstens Committed by Martin Schwidefsky

[S390] Randomize mmap start address

Randomize mmap start address with 8MB.
Signed-off-by: default avatarHeiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
parent 1060f62e
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/personality.h> #include <linux/personality.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/random.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
#include <asm/compat.h> #include <asm/compat.h>
...@@ -56,6 +57,14 @@ static inline int mmap_is_legacy(void) ...@@ -56,6 +57,14 @@ static inline int mmap_is_legacy(void)
return sysctl_legacy_va_layout; return sysctl_legacy_va_layout;
} }
static unsigned long mmap_rnd(void)
{
if (!(current->flags & PF_RANDOMIZE))
return 0;
/* 8MB randomization for mmap_base */
return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
}
static inline unsigned long mmap_base(void) static inline unsigned long mmap_base(void)
{ {
unsigned long gap = rlimit(RLIMIT_STACK); unsigned long gap = rlimit(RLIMIT_STACK);
...@@ -64,8 +73,8 @@ static inline unsigned long mmap_base(void) ...@@ -64,8 +73,8 @@ static inline unsigned long mmap_base(void)
gap = MIN_GAP; gap = MIN_GAP;
else if (gap > MAX_GAP) else if (gap > MAX_GAP)
gap = MAX_GAP; gap = MAX_GAP;
gap &= PAGE_MASK;
return STACK_TOP - stack_maxrandom_size() - (gap & PAGE_MASK); return STACK_TOP - stack_maxrandom_size() - mmap_rnd() - gap;
} }
#ifndef CONFIG_64BIT #ifndef CONFIG_64BIT
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment