Skip to content

Commit 3afb76a

Browse files
aquiniakpm00
authored andcommitted
mm: mmap: allow for the maximum number of bits for randomizing mmap_base by default
An ASLR regression was noticed [1] and tracked down to file-mapped areas being backed by THP in recent kernels. The 21-bit alignment constraint for such mappings reduces the entropy for randomizing the placement of 64-bit library mappings and breaks ASLR completely for 32-bit libraries. The reported issue is easily addressed by increasing vm.mmap_rnd_bits and vm.mmap_rnd_compat_bits. This patch just provides a simple way to set ARCH_MMAP_RND_BITS and ARCH_MMAP_RND_COMPAT_BITS to their maximum values allowed by the architecture at build time. [1] https://zolutal.github.io/aslrnt/ [[email protected]: default to `y' if 32-bit, per Rafael] Link: https://lkml.kernel.org/r/[email protected] Fixes: 1854bc6 ("mm/readahead: Align file mappings for non-DAX") Signed-off-by: Rafael Aquini <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Mike Rapoport (IBM) <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Petr Mladek <[email protected]> Cc: Samuel Holland <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c1558bc commit 3afb76a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

arch/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,10 +1046,21 @@ config ARCH_MMAP_RND_BITS_MAX
10461046
config ARCH_MMAP_RND_BITS_DEFAULT
10471047
int
10481048

1049+
config FORCE_MAX_MMAP_RND_BITS
1050+
bool "Force maximum number of bits to use for ASLR of mmap base address"
1051+
default y if !64BIT
1052+
help
1053+
ARCH_MMAP_RND_BITS and ARCH_MMAP_RND_COMPAT_BITS represent the number
1054+
of bits to use for ASLR and if no custom value is assigned (EXPERT)
1055+
then the architecture's lower bound (minimum) value is assumed.
1056+
This toggle changes that default assumption to assume the arch upper
1057+
bound (maximum) value instead.
1058+
10491059
config ARCH_MMAP_RND_BITS
10501060
int "Number of bits to use for ASLR of mmap base address" if EXPERT
10511061
range ARCH_MMAP_RND_BITS_MIN ARCH_MMAP_RND_BITS_MAX
10521062
default ARCH_MMAP_RND_BITS_DEFAULT if ARCH_MMAP_RND_BITS_DEFAULT
1063+
default ARCH_MMAP_RND_BITS_MAX if FORCE_MAX_MMAP_RND_BITS
10531064
default ARCH_MMAP_RND_BITS_MIN
10541065
depends on HAVE_ARCH_MMAP_RND_BITS
10551066
help
@@ -1084,6 +1095,7 @@ config ARCH_MMAP_RND_COMPAT_BITS
10841095
int "Number of bits to use for ASLR of mmap base address for compatible applications" if EXPERT
10851096
range ARCH_MMAP_RND_COMPAT_BITS_MIN ARCH_MMAP_RND_COMPAT_BITS_MAX
10861097
default ARCH_MMAP_RND_COMPAT_BITS_DEFAULT if ARCH_MMAP_RND_COMPAT_BITS_DEFAULT
1098+
default ARCH_MMAP_RND_COMPAT_BITS_MAX if FORCE_MAX_MMAP_RND_BITS
10871099
default ARCH_MMAP_RND_COMPAT_BITS_MIN
10881100
depends on HAVE_ARCH_MMAP_RND_COMPAT_BITS
10891101
help

0 commit comments

Comments
 (0)