aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2015-04-14 18:47:48 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-04-14 19:49:05 -0400
commitdd04cff1dceab18226853b555cf07914648a235f (patch)
tree6c543fccf16600754458e12aa61099ae4b638a06 /arch
parent82168140bc4cec7ec9bad39705518541149ff8b7 (diff)
arm64: standardize mmap_rnd() usage
In preparation for splitting out ET_DYN ASLR, this refactors the use of mmap_rnd() to be used similarly to arm and x86. This additionally enables mmap ASLR on legacy mmap layouts, which appeared to be missing on arm64, and was already supported on arm. Additionally removes a copy/pasted declaration of an unused function. Signed-off-by: Kees Cook <keescook@chromium.org> Cc: Russell King <linux@arm.linux.org.uk> Cc: Catalin Marinas <catalin.marinas@arm.com> Reviewed-by: Ingo Molnar <mingo@kernel.org> 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/arm64/include/asm/elf.h1
-rw-r--r--arch/arm64/mm/mmap.c18
2 files changed, 11 insertions, 8 deletions
diff --git a/arch/arm64/include/asm/elf.h b/arch/arm64/include/asm/elf.h
index 1f65be393139..f724db00b235 100644
--- a/arch/arm64/include/asm/elf.h
+++ b/arch/arm64/include/asm/elf.h
@@ -125,7 +125,6 @@ typedef struct user_fpsimd_state elf_fpregset_t;
125 * the loader. We need to make sure that it is out of the way of the program 125 * the loader. We need to make sure that it is out of the way of the program
126 * that it will "exec", and that there is sufficient room for the brk. 126 * that it will "exec", and that there is sufficient room for the brk.
127 */ 127 */
128extern unsigned long randomize_et_dyn(unsigned long base);
129#define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3) 128#define ELF_ET_DYN_BASE (2 * TASK_SIZE_64 / 3)
130 129
131/* 130/*
diff --git a/arch/arm64/mm/mmap.c b/arch/arm64/mm/mmap.c
index 54922d1275b8..ba776c01b552 100644
--- a/arch/arm64/mm/mmap.c
+++ b/arch/arm64/mm/mmap.c
@@ -49,15 +49,14 @@ static int mmap_is_legacy(void)
49 49
50static unsigned long mmap_rnd(void) 50static unsigned long mmap_rnd(void)
51{ 51{
52 unsigned long rnd = 0; 52 unsigned long rnd;
53 53
54 if (current->flags & PF_RANDOMIZE) 54 rnd = (unsigned long)get_random_int() & STACK_RND_MASK;
55 rnd = (long)get_random_int() & STACK_RND_MASK;
56 55
57 return rnd << PAGE_SHIFT; 56 return rnd << PAGE_SHIFT;
58} 57}
59 58
60static unsigned long mmap_base(void) 59static unsigned long mmap_base(unsigned long rnd)
61{ 60{
62 unsigned long gap = rlimit(RLIMIT_STACK); 61 unsigned long gap = rlimit(RLIMIT_STACK);
63 62
@@ -66,7 +65,7 @@ static unsigned long mmap_base(void)
66 else if (gap > MAX_GAP) 65 else if (gap > MAX_GAP)
67 gap = MAX_GAP; 66 gap = MAX_GAP;
68 67
69 return PAGE_ALIGN(STACK_TOP - gap - mmap_rnd()); 68 return PAGE_ALIGN(STACK_TOP - gap - rnd);
70} 69}
71 70
72/* 71/*
@@ -75,15 +74,20 @@ static unsigned long mmap_base(void)
75 */ 74 */
76void arch_pick_mmap_layout(struct mm_struct *mm) 75void arch_pick_mmap_layout(struct mm_struct *mm)
77{ 76{
77 unsigned long random_factor = 0UL;
78
79 if (current->flags & PF_RANDOMIZE)
80 random_factor = mmap_rnd();
81
78 /* 82 /*
79 * Fall back to the standard layout if the personality bit is set, or 83 * Fall back to the standard layout if the personality bit is set, or
80 * if the expected stack growth is unlimited: 84 * if the expected stack growth is unlimited:
81 */ 85 */
82 if (mmap_is_legacy()) { 86 if (mmap_is_legacy()) {
83 mm->mmap_base = TASK_UNMAPPED_BASE; 87 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
84 mm->get_unmapped_area = arch_get_unmapped_area; 88 mm->get_unmapped_area = arch_get_unmapped_area;
85 } else { 89 } else {
86 mm->mmap_base = mmap_base(); 90 mm->mmap_base = mmap_base(random_factor);
87 mm->get_unmapped_area = arch_get_unmapped_area_topdown; 91 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
88 } 92 }
89} 93}