Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc8eb3ef authored by dcashman's avatar dcashman Committed by Mark Salyzyn
Browse files

arm: mm: support ARCH_MMAP_RND_BITS.



Bug: 24047224
Signed-off-by: default avatarDaniel Cashman <dcashman@google.com>
Change-Id: Ie4b6d175f636a8ee4b25cdc0a0407d440278ff63
parent 565ef503
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -296,6 +296,30 @@ config MMU
	  Select if you want MMU-based virtualised addressing space
	  support by paged memory management. If unsure, say 'Y'.

config ARCH_MMAP_RND_BITS_MIN
	int
	default 8

config ARCH_MMAP_RND_BITS_MAX
	int
	default 14 if MMU && PAGE_OFFSET=0x40000000
	default 15 if MMU && PAGE_OFFSET=0x80000000
	default 16 if MMU
	default 8

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_MIN
	help
	  This value can be used to select the number of bits to use to
	  determine the random offset to the base address of vma regions
	  resulting from mmap allocations. This value will be bounded
	  by the architecture's minimum and maximum supported values.

	  This value can be changed after boot using the
	  /proc/sys/kernel/mmap_rnd_bits tunable

#
# The "ARM system type" choice list is ordered alphabetically by option
# text.  Please add new entries in the option alphabetic order.
+5 −2
Original line number Diff line number Diff line
@@ -11,6 +11,10 @@
#include <linux/random.h>
#include <asm/cachetype.h>

int mmap_rnd_bits_min = CONFIG_ARCH_MMAP_RND_BITS_MIN;
int mmap_rnd_bits_max = CONFIG_ARCH_MMAP_RND_BITS_MAX;
int mmap_rnd_bits = CONFIG_ARCH_MMAP_RND_BITS;

#define COLOUR_ALIGN(addr,pgoff)		\
	((((addr)+SHMLBA-1)&~(SHMLBA-1)) +	\
	 (((pgoff)<<PAGE_SHIFT) & (SHMLBA-1)))
@@ -173,10 +177,9 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
{
	unsigned long random_factor = 0UL;

	/* 8 bits of randomness in 20 address space bits */
	if ((current->flags & PF_RANDOMIZE) &&
	    !(current->personality & ADDR_NO_RANDOMIZE))
		random_factor = (get_random_int() % (1 << 8)) << PAGE_SHIFT;
		random_factor = (get_random_int() % (1 << mmap_rnd_bits)) << PAGE_SHIFT;

	if (mmap_is_legacy()) {
		mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;