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

Commit ac24a02f authored by Kees Cook's avatar Kees Cook Committed by Trilok Soni
Browse files

mm: expose arch_mmap_rnd when available



When an architecture fully supports randomizing the ELF load location,
a per-arch mmap_rnd() function is used to find a randomized mmap base.
In preparation for randomizing the location of ET_DYN binaries
separately from mmap, this renames and exports these functions as
arch_mmap_rnd(). Additionally introduces CONFIG_ARCH_HAS_ELF_RANDOMIZE
for describing this feature on architectures that support it
(which is a superset of ARCH_BINFMT_ELF_RANDOMIZE_PIE, since s390
already supports a separated ET_DYN ASLR from mmap ASLR without the
ARCH_BINFMT_ELF_RANDOMIZE_PIE logic).

Change-Id: Iefab73a7499071e3984bf54814bdd047356f8c38
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Cc: Hector Marco-Gisbert <hecmargi@upv.es>
Cc: Russell King <linux@arm.linux.org.uk>
Reviewed-by: default avatarIngo Molnar <mingo@kernel.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: "David A. Long" <dave.long@linaro.org>
Cc: Andrey Ryabinin <a.ryabinin@samsung.com>
Cc: Arun Chandran <achandran@mvista.com>
Cc: Yann Droneaud <ydroneaud@opteya.com>
Cc: Min-Hua Chen <orca.chen@gmail.com>
Cc: Paul Burton <paul.burton@imgtec.com>
Cc: Alex Smith <alex@alex-smith.me.uk>
Cc: Markos Chandras <markos.chandras@imgtec.com>
Cc: Vineeth Vijayan <vvijayan@mvista.com>
Cc: Jeff Bailey <jeffbailey@google.com>
Cc: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Cc: Ben Hutchings <ben@decadent.org.uk>
Cc: Behan Webster <behanw@converseincode.com>
Cc: Ismael Ripoll <iripoll@upv.es>
Cc: Jan-Simon Mller <dl9pf@gmx.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
Git-commit: 2b68f6caeac271620cd2f9362aeaed360e317df0
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git


[sewango@codeaurora.org: resolve trivial merge conflicts]
Signed-off-by: default avatarSe Wang (Patrick) Oh <sewango@codeaurora.org>
parent 5ec78319
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -484,6 +484,13 @@ config HAVE_IRQ_EXIT_ON_IRQ_STACK
	  This spares a stack switch and improves cache usage on softirq
	  processing.

config ARCH_HAS_ELF_RANDOMIZE
	bool
	help
	  An architecture supports choosing randomized locations for
	  stack, mmap, brk, and ET_DYN. Defined functions:
	  - arch_mmap_rnd()

#
# ABI hall of shame
#
+1 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ config ARM
	default y
	select ARCH_BINFMT_ELF_RANDOMIZE_PIE
	select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
	select ARCH_HAS_ELF_RANDOMIZE
	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
	select ARCH_HAVE_CUSTOM_GPIO_H
	select ARCH_MIGHT_HAVE_PC_PARPORT
+2 −2
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
	return addr;
}

static unsigned long mmap_rnd(void)
unsigned long arch_mmap_rnd(void)
{
	unsigned long rnd;

@@ -184,7 +184,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
	unsigned long random_factor = 0UL;

	if (current->flags & PF_RANDOMIZE)
		random_factor = mmap_rnd();
		random_factor = arch_mmap_rnd();

	if (mmap_is_legacy()) {
		mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ config ARM64
	def_bool y
	select ARCH_BINFMT_ELF_RANDOMIZE_PIE
	select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
	select ARCH_HAS_ELF_RANDOMIZE
	select ARCH_HAS_SG_CHAIN
	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
	select ARCH_USE_CMPXCHG_LOCKREF
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ static int mmap_is_legacy(void)
	return sysctl_legacy_va_layout;
}

static unsigned long mmap_rnd(void)
unsigned long arch_mmap_rnd(void)
{
	unsigned long rnd;

@@ -77,7 +77,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
	unsigned long random_factor = 0UL;

	if (current->flags & PF_RANDOMIZE)
		random_factor = mmap_rnd();
		random_factor = arch_mmap_rnd();

	/*
	 * Fall back to the standard layout if the personality bit is set, or
Loading