Skip to content

Commit

Permalink
mips: extract logic for mmap_rnd()
Browse files Browse the repository at this point in the history
In preparation for splitting out ET_DYN ASLR, extract the mmap ASLR
selection into a separate function.

Signed-off-by: Kees Cook <[email protected]>
Reviewed-by: Ingo Molnar <[email protected]>
Cc: Ralf Baechle <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
kees authored and torvalds committed Apr 14, 2015
1 parent dd04cff commit 1f0569d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions arch/mips/mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,26 @@ unsigned long arch_get_unmapped_area_topdown(struct file *filp,
addr0, len, pgoff, flags, DOWN);
}

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

rnd = (unsigned long)get_random_int();
rnd <<= PAGE_SHIFT;
if (TASK_IS_32BIT_ADDR)
rnd &= 0xfffffful;
else
rnd &= 0xffffffful;

return rnd;
}

void arch_pick_mmap_layout(struct mm_struct *mm)
{
unsigned long random_factor = 0UL;

if (current->flags & PF_RANDOMIZE) {
random_factor = get_random_int();
random_factor = random_factor << PAGE_SHIFT;
if (TASK_IS_32BIT_ADDR)
random_factor &= 0xfffffful;
else
random_factor &= 0xffffffful;
}
if (current->flags & PF_RANDOMIZE)
random_factor = mmap_rnd();

if (mmap_is_legacy()) {
mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
Expand Down

0 comments on commit 1f0569d

Please sign in to comment.