Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: Add support for ARCH_MMAP_RND_{COMPAT_}BITS

arch_mmap_rnd() uses hard-coded limits of 16MB for the randomisation
of mmap within 32bit processes and 256MB in 64bit processes. Since v4.4
other arches support tuning this value in /proc/sys/vm/mmap_rnd_bits.
Add support for this to MIPS.

Set the minimum(default) number of bits randomisation for 32bit to 8 -
which with 4k pagesize is unchanged from the current 16MB total
randomness. The minimum(default) for 64bit is 12bits, again with 4k
pagesize this is the same as the current 256MB.

This patch is necessary for MIPS32 to pass the Android CTS tests, with
the number of random bits set to 15.

Signed-off-by: Matt Redfearn <matt.redfearn@imgtec.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Paul Gortmaker <paul.gortmaker@windriver.com>
Cc: Daniel Cashman <dcashman@android.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mips@linux-mips.org
Cc: kernel-hardening@lists.openwall.com
Cc: linux-kernel@vger.kernel.org
Patchwork: https://patchwork.linux-mips.org/patch/14617/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Matt Redfearn and committed by
Ralf Baechle
109c32ff d9ae4f18

+21 -5
+16
arch/mips/Kconfig
··· 14 14 select HAVE_PERF_EVENTS 15 15 select PERF_USE_VMALLOC 16 16 select HAVE_ARCH_KGDB 17 + select HAVE_ARCH_MMAP_RND_BITS if MMU 18 + select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT 17 19 select HAVE_ARCH_SECCOMP_FILTER 18 20 select HAVE_ARCH_TRACEHOOK 19 21 select HAVE_CBPF_JIT if !CPU_MICROMIPS ··· 3074 3072 config MMU 3075 3073 bool 3076 3074 default y 3075 + 3076 + config ARCH_MMAP_RND_BITS_MIN 3077 + default 12 if 64BIT 3078 + default 8 3079 + 3080 + config ARCH_MMAP_RND_BITS_MAX 3081 + default 18 if 64BIT 3082 + default 15 3083 + 3084 + config ARCH_MMAP_RND_COMPAT_BITS_MIN 3085 + default 8 3086 + 3087 + config ARCH_MMAP_RND_COMPAT_BITS_MAX 3088 + default 15 3077 3089 3078 3090 config I8253 3079 3091 bool
+5 -5
arch/mips/mm/mmap.c
··· 146 146 { 147 147 unsigned long rnd; 148 148 149 - rnd = get_random_long(); 150 - rnd <<= PAGE_SHIFT; 149 + #ifdef CONFIG_COMPAT 151 150 if (TASK_IS_32BIT_ADDR) 152 - rnd &= 0xfffffful; 151 + rnd = get_random_long() & ((1UL << mmap_rnd_compat_bits) - 1); 153 152 else 154 - rnd &= 0xffffffful; 153 + #endif /* CONFIG_COMPAT */ 154 + rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1); 155 155 156 - return rnd; 156 + return rnd << PAGE_SHIFT; 157 157 } 158 158 159 159 void arch_pick_mmap_layout(struct mm_struct *mm)