diff options
author | Kees Cook <keescook@chromium.org> | 2015-04-14 18:47:51 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-14 19:49:05 -0400 |
commit | 1f0569df0b0285e7ec2432d804a4921b06a61618 (patch) | |
tree | 04f5a3abc1ec569dfa39f679a3f13a7d55692cc9 /arch | |
parent | dd04cff1dceab18226853b555cf07914648a235f (diff) |
mips: extract logic for mmap_rnd()
In preparation for splitting out ET_DYN ASLR, extract the mmap ASLR
selection into a separate function.
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Cc: Ralf Baechle <ralf@linux-mips.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/mips/mm/mmap.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c index f1baadd56e82..9a4f1f5c1f0e 100644 --- a/arch/mips/mm/mmap.c +++ b/arch/mips/mm/mmap.c | |||
@@ -142,18 +142,26 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp, | |||
142 | addr0, len, pgoff, flags, DOWN); | 142 | addr0, len, pgoff, flags, DOWN); |
143 | } | 143 | } |
144 | 144 | ||
145 | static unsigned long mmap_rnd(void) | ||
146 | { | ||
147 | unsigned long rnd; | ||
148 | |||
149 | rnd = (unsigned long)get_random_int(); | ||
150 | rnd <<= PAGE_SHIFT; | ||
151 | if (TASK_IS_32BIT_ADDR) | ||
152 | rnd &= 0xfffffful; | ||
153 | else | ||
154 | rnd &= 0xffffffful; | ||
155 | |||
156 | return rnd; | ||
157 | } | ||
158 | |||
145 | void arch_pick_mmap_layout(struct mm_struct *mm) | 159 | void arch_pick_mmap_layout(struct mm_struct *mm) |
146 | { | 160 | { |
147 | unsigned long random_factor = 0UL; | 161 | unsigned long random_factor = 0UL; |
148 | 162 | ||
149 | if (current->flags & PF_RANDOMIZE) { | 163 | if (current->flags & PF_RANDOMIZE) |
150 | random_factor = get_random_int(); | 164 | random_factor = mmap_rnd(); |
151 | random_factor = random_factor << PAGE_SHIFT; | ||
152 | if (TASK_IS_32BIT_ADDR) | ||
153 | random_factor &= 0xfffffful; | ||
154 | else | ||
155 | random_factor &= 0xffffffful; | ||
156 | } | ||
157 | 165 | ||
158 | if (mmap_is_legacy()) { | 166 | if (mmap_is_legacy()) { |
159 | mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; | 167 | mm->mmap_base = TASK_UNMAPPED_BASE + random_factor; |