diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h index 354d42616c7e6dc057a4bbf1bbfbb80805f7d880..9dbd3e7a3bc39bf570d8e384c42ca7e7b575be61 100644 --- a/arch/s390/include/asm/elf.h +++ b/arch/s390/include/asm/elf.h @@ -206,6 +206,8 @@ do { \ current->mm->context.noexec == 0; \ }) +#define STACK_RND_MASK 0x7ffUL + #define ARCH_DLINFO \ do { \ if (vdso_enabled) \ diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c index 869efbaed3eadf76db6c90de2bd75550fb630bf6..5578740ab9c93eeddafa4bb1b60500b2353a0b2a 100644 --- a/arch/s390/mm/mmap.c +++ b/arch/s390/mm/mmap.c @@ -30,6 +30,15 @@ #include #include +static unsigned long stack_maxrandom_size(void) +{ + if (!(current->flags & PF_RANDOMIZE)) + return 0; + if (current->personality & ADDR_NO_RANDOMIZE) + return 0; + return STACK_RND_MASK << PAGE_SHIFT; +} + /* * Top of mmap area (just below the process stack). * @@ -47,7 +56,7 @@ static inline unsigned long mmap_base(void) else if (gap > MAX_GAP) gap = MAX_GAP; - return STACK_TOP - (gap & PAGE_MASK); + return STACK_TOP - stack_maxrandom_size() - (gap & PAGE_MASK); } static inline int mmap_is_legacy(void)