mm: mmap: allow for the maximum number of bits for randomizing mmap_base by default
authorRafael Aquini <aquini@redhat.com>
Thu, 6 Jun 2024 18:06:22 +0000 (14:06 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jun 2024 11:49:13 +0000 (13:49 +0200)
commit 3afb76a66b5559a7b595155803ce23801558a7a9 upstream.

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/

[akpm@linux-foundation.org: default to `y' if 32-bit, per Rafael]
Link: https://lkml.kernel.org/r/20240606180622.102099-1-aquini@redhat.com
Fixes: 1854bc6e2420 ("mm/readahead: Align file mappings for non-DAX")
Signed-off-by: Rafael Aquini <aquini@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Paul E. McKenney <paulmck@kernel.org>
Cc: Petr Mladek <pmladek@suse.com>
Cc: Samuel Holland <samuel.holland@sifive.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/Kconfig

index 09603e0bc2cc1655afdb4199a466b672b9462f6d..507fd894265d2c43f71ea41527d32423564f8e30 100644 (file)
@@ -1037,10 +1037,21 @@ config ARCH_MMAP_RND_BITS_MAX
 config ARCH_MMAP_RND_BITS_DEFAULT
        int
 
+config FORCE_MAX_MMAP_RND_BITS
+       bool "Force maximum number of bits to use for ASLR of mmap base address"
+       default y if !64BIT
+       help
+         ARCH_MMAP_RND_BITS and ARCH_MMAP_RND_COMPAT_BITS represent the number
+         of bits to use for ASLR and if no custom value is assigned (EXPERT)
+         then the architecture's lower bound (minimum) value is assumed.
+         This toggle changes that default assumption to assume the arch upper
+         bound (maximum) value instead.
+
 config ARCH_MMAP_RND_BITS
        int "Number of bits to use for ASLR of mmap base address" if EXPERT
        range ARCH_MMAP_RND_BITS_MIN ARCH_MMAP_RND_BITS_MAX
        default ARCH_MMAP_RND_BITS_DEFAULT if ARCH_MMAP_RND_BITS_DEFAULT
+       default ARCH_MMAP_RND_BITS_MAX if FORCE_MAX_MMAP_RND_BITS
        default ARCH_MMAP_RND_BITS_MIN
        depends on HAVE_ARCH_MMAP_RND_BITS
        help
@@ -1075,6 +1086,7 @@ config ARCH_MMAP_RND_COMPAT_BITS
        int "Number of bits to use for ASLR of mmap base address for compatible applications" if EXPERT
        range ARCH_MMAP_RND_COMPAT_BITS_MIN ARCH_MMAP_RND_COMPAT_BITS_MAX
        default ARCH_MMAP_RND_COMPAT_BITS_DEFAULT if ARCH_MMAP_RND_COMPAT_BITS_DEFAULT
+       default ARCH_MMAP_RND_COMPAT_BITS_MAX if FORCE_MAX_MMAP_RND_BITS
        default ARCH_MMAP_RND_COMPAT_BITS_MIN
        depends on HAVE_ARCH_MMAP_RND_COMPAT_BITS
        help