1 From d6c763afab142a85e4770b4bc2a5f40f256d5c5d Mon Sep 17 00:00:00 2001
2 From: Yann Droneaud <ydroneaud@opteya.com>
3 Date: Mon, 17 Nov 2014 23:02:19 +0000
4 Subject: arm64/mm: Remove hack in mmap randomize layout
6 From: Yann Droneaud <ydroneaud@opteya.com>
8 commit d6c763afab142a85e4770b4bc2a5f40f256d5c5d upstream.
10 Since commit 8a0a9bd4db63 ('random: make get_random_int() more
11 random'), get_random_int() returns a random value for each call,
12 so comment and hack introduced in mmap_rnd() as part of commit
13 1d18c47c735e ('arm64: MMU fault handling and page table management')
16 Commit 1d18c47c735e seems to use the same hack introduced by
17 commit a5adc91a4b44 ('powerpc: Ensure random space between stack
18 and mmaps'), latter copied in commit 5a0efea09f42 ('sparc64: Sharpen
19 address space randomization calculations.').
21 But both architectures were cleaned up as part of commit
22 fa8cbaaf5a68 ('powerpc+sparc64/mm: Remove hack in mmap randomize
23 layout') as hack is no more needed since commit 8a0a9bd4db63.
25 So the present patch removes the comment and the hack around
26 get_random_int() on AArch64's mmap_rnd().
28 Cc: David S. Miller <davem@davemloft.net>
29 Cc: Anton Blanchard <anton@samba.org>
30 Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
31 Acked-by: Will Deacon <will.deacon@arm.com>
32 Acked-by: Dan McGee <dpmcgee@gmail.com>
33 Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
34 Signed-off-by: Will Deacon <will.deacon@arm.com>
35 Cc: Matthias Brugger <mbrugger@suse.com>
36 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
39 arch/arm64/mm/mmap.c | 12 ++----------
40 1 file changed, 2 insertions(+), 10 deletions(-)
42 --- a/arch/arm64/mm/mmap.c
43 +++ b/arch/arm64/mm/mmap.c
44 @@ -47,22 +47,14 @@ static int mmap_is_legacy(void)
45 return sysctl_legacy_va_layout;
49 - * Since get_random_int() returns the same value within a 1 jiffy window, we
50 - * will almost always get the same randomisation for the stack and mmap
51 - * region. This will mean the relative distance between stack and mmap will be
54 - * To avoid this we can shift the randomness by 1 bit.
56 static unsigned long mmap_rnd(void)
58 unsigned long rnd = 0;
60 if (current->flags & PF_RANDOMIZE)
61 - rnd = (long)get_random_int() & (STACK_RND_MASK >> 1);
62 + rnd = (long)get_random_int() & STACK_RND_MASK;
64 - return rnd << (PAGE_SHIFT + 1);
65 + return rnd << PAGE_SHIFT;
68 static unsigned long mmap_base(void)