mm: randomize lower bits of brk

Per PaX, but for this alternate brk randomization approach.

As part of the v5.4 linux-hardened rebase, this commit was adapted from
the arm64 specific brk randomization to all arches that use the generic
topdown mmap layout functions, introduced in e7142bf5d231 ("arm64, mm:
make randomization selected by generic topdown mmap layout").

Signed-off-by: Daniel Micay <danielmicay@gmail.com>
Signed-off-by: Levente Polyak <levente@leventepolyak.net>
Signed-off-by: anupritaisno1 <www.anuprita804@gmail.com>
This commit is contained in:
Daniel Micay 2017-06-01 03:22:38 -04:00 committed by Kreciorek
parent a124bf732b
commit 2994f3aa26

View file

@ -372,9 +372,9 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
{ {
/* Is the current task 32bit ? */ /* Is the current task 32bit ? */
if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task()) if (!IS_ENABLED(CONFIG_64BIT) || is_compat_task())
return randomize_page(mm->brk, SZ_32M); return mm->brk + get_random_long() % SZ_32M;
return randomize_page(mm->brk, SZ_1G); return mm->brk + get_random_long() % SZ_1G;
} }
unsigned long arch_mmap_rnd(void) unsigned long arch_mmap_rnd(void)