]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
s390/mmap: randomize mmap base for bottom up direction
authorHeiko Carstens <heiko.carstens@de.ibm.com>
Tue, 5 Nov 2013 05:55:47 +0000 (16:55 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Tue, 5 Nov 2013 05:55:47 +0000 (16:55 +1100)
Implement mmap base randomization for the bottom up direction, so ASLR
works for both mmap layouts on s390.  See also df54d6fa54 ("x86
get_unmapped_area(): use proper mmap base for bottom-up direction").

Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Radu Caragea <sinaelgl@gmail.com>
Cc: Michel Lespinasse <walken@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Chris Metcalf <cmetcalf@tilera.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
arch/s390/mm/mmap.c

index 40023290ee5b43dea2cf72b68c97f9495b6c59fd..7110c0f0fb01c8fd42bf7f90a4cf155141724778 100644 (file)
@@ -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);
@@ -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();
@@ -172,7 +177,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();