From 2994f3aa26c5cb28981ba2ee4c9d2bdd2ef2bbc1 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Thu, 1 Jun 2017 03:22:38 -0400 Subject: [PATCH] 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 Signed-off-by: Levente Polyak Signed-off-by: anupritaisno1 --- mm/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/util.c b/mm/util.c index 70b975249..5ab0673cd 100755 --- a/mm/util.c +++ b/mm/util.c @@ -372,9 +372,9 @@ unsigned long arch_randomize_brk(struct mm_struct *mm) { /* Is the current task 32bit ? */ 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)