ANDROID: 16K: Reduce mmap rand bits
The emulated page size in userspace is larger than the kernel page size. This means that the kernel can no longer provide the max amount of mmap rand bits as before. The maximum must be reduced by the difference between the emulated page shift and the real page shift. This is only necessary for the 64-bit case and not for the compat (32-bit) case. Also move initialization of mmap_rnd_bits_* globals to init_mmap_rnd_bits(), which is called at core_init time. This is necessary since the values are no longer build time constants. Bug: 383389337 Bug: 315325080 Bug: 302403436 Change-Id: I0f45a9f40b4f4cd06e98e0bfa62732c5d70056be Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This commit is contained in:
committed by
Carlos Llamas
parent
80e2a42d97
commit
796be8fd27
@@ -90,13 +90,13 @@ extern int sysctl_legacy_va_layout;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
|
||||
extern const int mmap_rnd_bits_min;
|
||||
extern int mmap_rnd_bits_min __ro_after_init;
|
||||
extern int mmap_rnd_bits_max __ro_after_init;
|
||||
extern int mmap_rnd_bits __read_mostly;
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
|
||||
extern const int mmap_rnd_compat_bits_min;
|
||||
extern const int mmap_rnd_compat_bits_max;
|
||||
extern int mmap_rnd_compat_bits_min __ro_after_init;
|
||||
extern int mmap_rnd_compat_bits_max __ro_after_init;
|
||||
extern int mmap_rnd_compat_bits __read_mostly;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -66,13 +66,13 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(vm_unmapped_area);
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
|
||||
const int mmap_rnd_bits_min = CONFIG_ARCH_MMAP_RND_BITS_MIN;
|
||||
int mmap_rnd_bits_min __ro_after_init = CONFIG_ARCH_MMAP_RND_BITS_MIN;
|
||||
int mmap_rnd_bits_max __ro_after_init = CONFIG_ARCH_MMAP_RND_BITS_MAX;
|
||||
int mmap_rnd_bits __read_mostly = CONFIG_ARCH_MMAP_RND_BITS;
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
|
||||
const int mmap_rnd_compat_bits_min = CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MIN;
|
||||
const int mmap_rnd_compat_bits_max = CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MAX;
|
||||
int mmap_rnd_compat_bits_min __ro_after_init = CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MIN;
|
||||
int mmap_rnd_compat_bits_max __ro_after_init = CONFIG_ARCH_MMAP_RND_COMPAT_BITS_MAX;
|
||||
int mmap_rnd_compat_bits __read_mostly = CONFIG_ARCH_MMAP_RND_COMPAT_BITS;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -9,10 +9,12 @@
|
||||
#include <linux/errno.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kstrtox.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/page_size_compat.h>
|
||||
|
||||
#define MIN_PAGE_SHIFT_COMPAT (PAGE_SHIFT + 1)
|
||||
#define MAX_PAGE_SHIFT_COMPAT 16 /* Max of 64KB */
|
||||
#define __MMAP_RND_BITS(x) (x - (__PAGE_SHIFT - PAGE_SHIFT))
|
||||
|
||||
DEFINE_STATIC_KEY_FALSE(page_shift_compat_enabled);
|
||||
|
||||
@@ -39,3 +41,18 @@ static int __init early_page_shift_compat(char *buf)
|
||||
return 0;
|
||||
}
|
||||
early_param("androidboot.page_shift", early_page_shift_compat);
|
||||
|
||||
static int __init init_mmap_rnd_bits(void)
|
||||
{
|
||||
if (!static_branch_unlikely(&page_shift_compat_enabled))
|
||||
return 0;
|
||||
|
||||
#ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
|
||||
mmap_rnd_bits_min = __MMAP_RND_BITS(CONFIG_ARCH_MMAP_RND_BITS_MIN);
|
||||
mmap_rnd_bits_max = __MMAP_RND_BITS(CONFIG_ARCH_MMAP_RND_BITS_MAX);
|
||||
mmap_rnd_bits = __MMAP_RND_BITS(CONFIG_ARCH_MMAP_RND_BITS);
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
core_initcall(init_mmap_rnd_bits);
|
||||
|
||||
Reference in New Issue
Block a user