[Devel] [PATCH 05/11] ms/mm: expose arch_mmap_rnd when available
Dmitry Safonov
dsafonov at virtuozzo.com
Thu May 18 11:39:44 PDT 2017
From: Kees Cook <keescook at chromium.org>
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).
Signed-off-by: Kees Cook <keescook at chromium.org>
Cc: Hector Marco-Gisbert <hecmargi at upv.es>
Cc: Russell King <linux at arm.linux.org.uk>
Reviewed-by: Ingo Molnar <mingo at kernel.org>
Cc: Catalin Marinas <catalin.marinas at arm.com>
Cc: Will Deacon <will.deacon at arm.com>
Cc: Ralf Baechle <ralf at linux-mips.org>
Cc: Benjamin Herrenschmidt <benh at kernel.crashing.org>
Cc: Paul Mackerras <paulus at samba.org>
Cc: Michael Ellerman <mpe at ellerman.id.au>
Cc: Martin Schwidefsky <schwidefsky at de.ibm.com>
Cc: Heiko Carstens <heiko.carstens at de.ibm.com>
Cc: Alexander Viro <viro at zeniv.linux.org.uk>
Cc: Oleg Nesterov <oleg at redhat.com>
Cc: Andy Lutomirski <luto at amacapital.net>
Cc: "David A. Long" <dave.long at linaro.org>
Cc: Andrey Ryabinin <a.ryabinin at samsung.com>
Cc: Arun Chandran <achandran at mvista.com>
Cc: Yann Droneaud <ydroneaud at opteya.com>
Cc: Min-Hua Chen <orca.chen at gmail.com>
Cc: Paul Burton <paul.burton at imgtec.com>
Cc: Alex Smith <alex at alex-smith.me.uk>
Cc: Markos Chandras <markos.chandras at imgtec.com>
Cc: Vineeth Vijayan <vvijayan at mvista.com>
Cc: Jeff Bailey <jeffbailey at google.com>
Cc: Michael Holzheu <holzheu at linux.vnet.ibm.com>
Cc: Ben Hutchings <ben at decadent.org.uk>
Cc: Behan Webster <behanw at converseincode.com>
Cc: Ismael Ripoll <iripoll at upv.es>
Cc: Jan-Simon Mller <dl9pf at gmx.de>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
[ms commit 2b68f6caeac2
ported only x86 part as other archs need special care..]
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
arch/Kconfig | 7 +++++++
arch/x86/Kconfig | 1 +
arch/x86/mm/mmap.c | 4 ++--
include/linux/elf-randomize.h | 10 ++++++++++
4 files changed, 20 insertions(+), 2 deletions(-)
create mode 100644 include/linux/elf-randomize.h
diff --git a/arch/Kconfig b/arch/Kconfig
index b5a4cb176d36..2b3b7d550a46 100644
--- a/arch/Kconfig
+++ b/arch/Kconfig
@@ -466,6 +466,13 @@ config HAVE_STACK_VALIDATION
Architecture supports the 'objtool check' host tool command, which
performs compile-time stack metadata validation.
+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
#
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 6ad29a57f171..29902c4630b4 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -86,6 +86,7 @@ config X86
select ARCH_HAS_KCOV if X86_64
select HAVE_USER_RETURN_NOTIFIER
select ARCH_BINFMT_ELF_RANDOMIZE_PIE
+ select ARCH_HAS_ELF_RANDOMIZE
select HAVE_ARCH_JUMP_LABEL
select HAVE_TEXT_POKE_SMP
select HAVE_GENERIC_HARDIRQS
diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
index 0e426764499a..cb7cd6e3e686 100644
--- a/arch/x86/mm/mmap.c
+++ b/arch/x86/mm/mmap.c
@@ -65,7 +65,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;
@@ -114,7 +114,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();
mm->mmap_legacy_base = mmap_legacy_base(random_factor);
diff --git a/include/linux/elf-randomize.h b/include/linux/elf-randomize.h
new file mode 100644
index 000000000000..7a4eda02d2b1
--- /dev/null
+++ b/include/linux/elf-randomize.h
@@ -0,0 +1,10 @@
+#ifndef _ELF_RANDOMIZE_H
+#define _ELF_RANDOMIZE_H
+
+#ifndef CONFIG_ARCH_HAS_ELF_RANDOMIZE
+static inline unsigned long arch_mmap_rnd(void) { return 0; }
+#else
+extern unsigned long arch_mmap_rnd(void);
+#endif
+
+#endif
--
2.12.2
More information about the Devel
mailing list