diff options
author | Kees Cook <keescook@chromium.org> | 2015-04-14 18:47:41 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-14 19:49:05 -0400 |
commit | fbbc400f3924ce095b466c776dc294727ec0a202 (patch) | |
tree | 5a813c2801006ddb815155adac68ad56dd1fe372 /arch | |
parent | a87938b2e246b81b4fb713edb371a9fa3c5c3c86 (diff) |
arm: factor out mmap ASLR into mmap_rnd
To address the "offset2lib" ASLR weakness[1], this separates ET_DYN ASLR
from mmap ASLR, as already done on s390. The architectures that are
already randomizing mmap (arm, arm64, mips, powerpc, s390, and x86), have
their various forms of arch_mmap_rnd() made available via the new
CONFIG_ARCH_HAS_ELF_RANDOMIZE. For these architectures,
arch_randomize_brk() is collapsed as well.
This is an alternative to the solutions in:
https://lkml.org/lkml/2015/2/23/442
I've been able to test x86 and arm, and the buildbot (so far) seems happy
with building the rest.
[1] http://cybersecurity.upv.es/attacks/offset2lib/offset2lib.html
This patch (of 10):
In preparation for splitting out ET_DYN ASLR, this moves the ASLR
calculations for mmap on ARM into a separate routine, similar to x86.
This also removes the redundant check of personality (PF_RANDOMIZE is
already set before calling arch_pick_mmap_layout).
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: Hector Marco-Gisbert <hecmargi@upv.es>
Cc: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Ingo 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: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/mm/mmap.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c index 5e85ed371364..15a8160096b3 100644 --- a/arch/arm/mm/mmap.c +++ b/arch/arm/mm/mmap.c | |||
@@ -169,14 +169,22 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0, | |||
169 | return addr; | 169 | return addr; |
170 | } | 170 | } |
171 | 171 | ||
172 | static unsigned long mmap_rnd(void) | ||
173 | { | ||
174 | unsigned long rnd; | ||
175 | |||
176 | /* 8 bits of randomness in 20 address space bits */ | ||
177 | rnd = (unsigned long)get_random_int() % (1 << 8); | ||
178 | |||
179 | return rnd << PAGE_SHIFT; | ||
180 | } | ||
181 | |||
172 | void arch_pick_mmap_layout(struct mm_struct *mm) | 182 | void arch_pick_mmap_layout(struct mm_struct *mm) |
173 | { | 183 | { |
174 | unsigned long random_factor = 0UL; | 184 | unsigned long random_factor = 0UL; |
175 | 185 | ||
176 | /* 8 bits of randomness in 20 address space bits */ | 186 | if (current->flags & PF_RANDOMIZE) |
177 | if ((current->flags & PF_RANDOMIZE) && | 187 | random_factor = mmap_rnd(); |
178 | !(current->personality & ADDR_NO_RANDOMIZE)) | ||
179 | random_factor = (get_random_int() % (1 << 8)) << PAGE_SHIFT; | ||
180 | 188 | ||
181 | if (mmap_is_legacy()) { | 189 | if (mmap_is_legacy()) { |
182 | mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; | 190 | mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; |