Commit 9046e401e752dba784805a7818f99cc45a39cbff

Authored by Heiko Carstens
Committed by Martin Schwidefsky
1 parent 7a63fa1a85

[S390] mmap: consider stack address randomization

Consider stack address randomization when calulating mmap_base for
flexible mmap layout . Because of address randomization the stack
address can be up to 8MB lower than STACK_TOP.
When calculating mmap_base this isn't taken into account, which could
lead to the case that the gap between the real stack top and mmap_base
is lower than what ulimit specifies for the maximum stack size.

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

Showing 2 changed files with 12 additions and 1 deletions Side-by-side Diff

arch/s390/include/asm/elf.h
... ... @@ -206,6 +206,8 @@
206 206 current->mm->context.noexec == 0; \
207 207 })
208 208  
  209 +#define STACK_RND_MASK 0x7ffUL
  210 +
209 211 #define ARCH_DLINFO \
210 212 do { \
211 213 if (vdso_enabled) \
... ... @@ -30,6 +30,15 @@
30 30 #include <asm/pgalloc.h>
31 31 #include <asm/compat.h>
32 32  
  33 +static unsigned long stack_maxrandom_size(void)
  34 +{
  35 + if (!(current->flags & PF_RANDOMIZE))
  36 + return 0;
  37 + if (current->personality & ADDR_NO_RANDOMIZE)
  38 + return 0;
  39 + return STACK_RND_MASK << PAGE_SHIFT;
  40 +}
  41 +
33 42 /*
34 43 * Top of mmap area (just below the process stack).
35 44 *
... ... @@ -47,7 +56,7 @@
47 56 else if (gap > MAX_GAP)
48 57 gap = MAX_GAP;
49 58  
50   - return STACK_TOP - (gap & PAGE_MASK);
  59 + return STACK_TOP - stack_maxrandom_size() - (gap & PAGE_MASK);
51 60 }
52 61  
53 62 static inline int mmap_is_legacy(void)