arm: mm: support ARCH_MMAP_RND_BITS
authorDaniel Cashman <[email protected]>
Thu, 14 Jan 2016 23:19:57 +0000 (15:19 -0800)
committerLinus Torvalds <[email protected]>
Fri, 15 Jan 2016 00:00:49 +0000 (16:00 -0800)
arm: arch_mmap_rnd() uses a hard-code value of 8 to generate the random
offset for the mmap base address.  This value represents a compromise
between increased ASLR effectiveness and avoiding address-space
fragmentation.  Replace it with a Kconfig option, which is sensibly
bounded, so that platform developers may choose where to place this
compromise.  Keep 8 as the minimum acceptable value.

[[email protected]: ARM: avoid ARCH_MMAP_RND_BITS for NOMMU]
Signed-off-by: Daniel Cashman <[email protected]>
Cc: Russell King <[email protected]>
Acked-by: Kees Cook <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Jonathan Corbet <[email protected]>
Cc: Don Zickus <[email protected]>
Cc: Eric W. Biederman <[email protected]>
Cc: Heinrich Schuchardt <[email protected]>
Cc: Josh Poimboeuf <[email protected]>
Cc: Kirill A. Shutemov <[email protected]>
Cc: Naoya Horiguchi <[email protected]>
Cc: Andrea Arcangeli <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Mark Salyzyn <[email protected]>
Cc: Jeff Vander Stoep <[email protected]>
Cc: Nick Kralevich <[email protected]>
Cc: Catalin Marinas <[email protected]>
Cc: Will Deacon <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Hector Marco-Gisbert <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Ralf Baechle <[email protected]>
Cc: Heiko Carstens <[email protected]>
Cc: Martin Schwidefsky <[email protected]>
Cc: Benjamin Herrenschmidt <[email protected]>
Signed-off-by: Arnd Bergmann <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
arch/arm/Kconfig
arch/arm/mm/mmap.c

index 84b1b21b08aee0c756538b311dd3b1f55fc64965..4e489cc5c45e5f4e1f648b5acc79cae8fdb81c5d 100644 (file)
@@ -37,6 +37,7 @@ config ARM
        select HAVE_ARCH_BITREVERSE if (CPU_32v7M || CPU_32v7) && !CPU_32v6
        select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU
        select HAVE_ARCH_KGDB if !CPU_ENDIAN_BE32 && MMU
+       select HAVE_ARCH_MMAP_RND_BITS if MMU
        select HAVE_ARCH_SECCOMP_FILTER if (AEABI && !OABI_COMPAT)
        select HAVE_ARCH_TRACEHOOK
        select HAVE_ARM_SMCCC if CPU_V7
@@ -311,6 +312,14 @@ config MMU
          Select if you want MMU-based virtualised addressing space
          support by paged memory management. If unsure, say 'Y'.
 
+config ARCH_MMAP_RND_BITS_MIN
+       default 8
+
+config ARCH_MMAP_RND_BITS_MAX
+       default 14 if PAGE_OFFSET=0x40000000
+       default 15 if PAGE_OFFSET=0x80000000
+       default 16
+
 #
 # The "ARM system type" choice list is ordered alphabetically by option
 # text.  Please add new entries in the option alphabetic order.
index 407dc786583aec0e6077f50a8374f99002ca8233..4b4058db0781f63e307d4f5101a74d5330ddf337 100644 (file)
@@ -173,8 +173,7 @@ unsigned long arch_mmap_rnd(void)
 {
        unsigned long rnd;
 
-       /* 8 bits of randomness in 20 address space bits */
-       rnd = (unsigned long)get_random_int() % (1 << 8);
+       rnd = (unsigned long)get_random_int() & ((1 << mmap_rnd_bits) - 1);
 
        return rnd << PAGE_SHIFT;
 }