]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
mips: extract logic for mmap_rnd()
authorKees Cook <keescook@chromium.org>
Tue, 14 Apr 2015 22:47:51 +0000 (15:47 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 14 Apr 2015 23:49:05 +0000 (16:49 -0700)
In preparation for splitting out ET_DYN ASLR, extract the mmap ASLR
selection into a separate function.

Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/mips/mm/mmap.c

index f1baadd56e82e2b0b4f2b79bd82686ea61a112d0..9a4f1f5c1f0ea6ac0781fa8f76d9abb22b9bf2fc 100644 (file)
@@ -142,18 +142,26 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp,
                        addr0, len, pgoff, flags, DOWN);
 }
 
+static unsigned long mmap_rnd(void)
+{
+       unsigned long rnd;
+
+       rnd = (unsigned long)get_random_int();
+       rnd <<= PAGE_SHIFT;
+       if (TASK_IS_32BIT_ADDR)
+               rnd &= 0xfffffful;
+       else
+               rnd &= 0xffffffful;
+
+       return rnd;
+}
+
 void arch_pick_mmap_layout(struct mm_struct *mm)
 {
        unsigned long random_factor = 0UL;
 
-       if (current->flags & PF_RANDOMIZE) {
-               random_factor = get_random_int();
-               random_factor = random_factor << PAGE_SHIFT;
-               if (TASK_IS_32BIT_ADDR)
-                       random_factor &= 0xfffffful;
-               else
-                       random_factor &= 0xffffffful;
-       }
+       if (current->flags & PF_RANDOMIZE)
+               random_factor = mmap_rnd();
 
        if (mmap_is_legacy()) {
                mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;