Skip to content

Commit

Permalink
s390/mmap: randomize mmap base for bottom up direction
Browse files Browse the repository at this point in the history
Implement mmap base randomization for the bottom up direction, so ASLR
works for both mmap layouts on s390.  See also commit df54d6f ("x86
get_unmapped_area(): use proper mmap base for bottom-up direction").

Signed-off-by: Heiko Carstens <[email protected]>
Cc: Radu Caragea <[email protected]>
Cc: Michel Lespinasse <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: Chris Metcalf <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
heicarst authored and torvalds committed Nov 13, 2013
1 parent 4e99b02 commit 7aba842
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions arch/s390/mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ static unsigned long mmap_rnd(void)
return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
}

static unsigned long mmap_base_legacy(void)
{
return TASK_UNMAPPED_BASE + mmap_rnd();
}

static inline unsigned long mmap_base(void)
{
unsigned long gap = rlimit(RLIMIT_STACK);
Expand All @@ -89,7 +94,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
* bit is set, or if the expected stack growth is unlimited:
*/
if (mmap_is_legacy()) {
mm->mmap_base = TASK_UNMAPPED_BASE;
mm->mmap_base = mmap_base_legacy();
mm->get_unmapped_area = arch_get_unmapped_area;
} else {
mm->mmap_base = mmap_base();
Expand Down Expand Up @@ -164,7 +169,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
* bit is set, or if the expected stack growth is unlimited:
*/
if (mmap_is_legacy()) {
mm->mmap_base = TASK_UNMAPPED_BASE;
mm->mmap_base = mmap_base_legacy();
mm->get_unmapped_area = s390_get_unmapped_area;
} else {
mm->mmap_base = mmap_base();
Expand Down

0 comments on commit 7aba842

Please sign in to comment.