Commit 109c32ff authored by Matt Redfearn's avatar Matt Redfearn Committed by Ralf Baechle

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: default avatarMatt Redfearn <matt.redfearn@imgtec.com>
Reviewed-by: default avatarKees 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: default avatarRalf Baechle <ralf@linux-mips.org>
parent d9ae4f18
...@@ -14,6 +14,8 @@ config MIPS ...@@ -14,6 +14,8 @@ config MIPS
select HAVE_PERF_EVENTS select HAVE_PERF_EVENTS
select PERF_USE_VMALLOC select PERF_USE_VMALLOC
select HAVE_ARCH_KGDB select HAVE_ARCH_KGDB
select HAVE_ARCH_MMAP_RND_BITS if MMU
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if MMU && COMPAT
select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_SECCOMP_FILTER
select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRACEHOOK
select HAVE_CBPF_JIT if !CPU_MICROMIPS select HAVE_CBPF_JIT if !CPU_MICROMIPS
...@@ -3073,6 +3075,20 @@ config MMU ...@@ -3073,6 +3075,20 @@ config MMU
bool bool
default y default y
config ARCH_MMAP_RND_BITS_MIN
default 12 if 64BIT
default 8
config ARCH_MMAP_RND_BITS_MAX
default 18 if 64BIT
default 15
config ARCH_MMAP_RND_COMPAT_BITS_MIN
default 8
config ARCH_MMAP_RND_COMPAT_BITS_MAX
default 15
config I8253 config I8253
bool bool
select CLKSRC_I8253 select CLKSRC_I8253
......
...@@ -146,14 +146,14 @@ unsigned long arch_mmap_rnd(void) ...@@ -146,14 +146,14 @@ unsigned long arch_mmap_rnd(void)
{ {
unsigned long rnd; unsigned long rnd;
rnd = get_random_long(); #ifdef CONFIG_COMPAT
rnd <<= PAGE_SHIFT;
if (TASK_IS_32BIT_ADDR) if (TASK_IS_32BIT_ADDR)
rnd &= 0xfffffful; rnd = get_random_long() & ((1UL << mmap_rnd_compat_bits) - 1);
else else
rnd &= 0xffffffful; #endif /* CONFIG_COMPAT */
rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1);
return rnd; return rnd << PAGE_SHIFT;
} }
void arch_pick_mmap_layout(struct mm_struct *mm) void arch_pick_mmap_layout(struct mm_struct *mm)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment