Re: [PATCH v2] mm: mmap: allow for the maximum number of bits for randomizing mmap_base by default

From: Rafael Aquini
Date: Wed Jun 12 2024 - 08:26:57 EST


On Tue, Jun 11, 2024 at 07:43:12PM -0700, Andrew Morton wrote:
> On Tue, 11 Jun 2024 21:35:24 -0400 Rafael Aquini <aquini@xxxxxxxxxx> wrote:
>
> > > Shouldn't we make this the default (at least for 32-bit) so the
> > > regressed kernels are fixed simply by applying this patch?
> > >
> >
> > That is a fair take, indeed. I guess we could do something like
> >
> > config FORCE_MAX_MMAP_RND_BITS
> > bool "Force maximum number of bits to use for ASLR of mmap base address"
> > - default n
> > + default y if !64BIT
>
> "something like" != "exhaustively tested" ;)
>
> I'll toss that in there, but please do let me know when it is suitable
> for an upstream merge.
>

The follow-up patch does work as intended:

[raquini@optiplex-lnx linux]$ make ARCH=i386 defconfig
*** Default configuration is based on 'i386_defconfig'
#
# configuration written to .config
#
[raquini@optiplex-lnx linux]$ grep MMAP_RND_BITS .config
CONFIG_ARCH_MMAP_RND_BITS_MIN=8
CONFIG_ARCH_MMAP_RND_BITS_MAX=16
CONFIG_HAVE_ARCH_MMAP_RND_BITS=y
# CONFIG_FORCE_MAX_MMAP_RND_BITS is not set
CONFIG_ARCH_MMAP_RND_BITS=8

[raquini@optiplex-lnx linux]$ patch -Np1 < patch.diff
patching file arch/Kconfig
[raquini@optiplex-lnx linux]$ make ARCH=i386 defconfig
*** Default configuration is based on 'i386_defconfig'
#
# configuration written to .config
#
[raquini@optiplex-lnx linux]$ grep MMAP_RND_BITS .config
CONFIG_ARCH_MMAP_RND_BITS_MIN=8
CONFIG_ARCH_MMAP_RND_BITS_MAX=16
CONFIG_HAVE_ARCH_MMAP_RND_BITS=y
CONFIG_FORCE_MAX_MMAP_RND_BITS=y
CONFIG_ARCH_MMAP_RND_BITS=16


> I also added cc:stable.
>

Thank you, Andrew.