Skip to content

Commit 6a0b41d

Browse files
0x7f454c46KAGA-KOKO
authored andcommitted
x86/mm: Introduce arch_rnd() to compute 32/64 mmap random base
The compat (32bit) mmap() sycall issued by a 64-bit task results in a mapping above 4GB. That's outside the compat mode address space and prevents CRIU to restore 32bit processes from a 64bit application. As a first step to address this, split out the address base randomizing calculation from arch_mmap_rnd() into a helper function, which can be used independent of mmap_ia32() based decisions. [ tglx: Massaged changelog ] Suggested-by: Thomas Gleixner <[email protected]> Signed-off-by: Dmitry Safonov <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Andy Lutomirski <[email protected]> Cc: Cyrill Gorcunov <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: "Kirill A. Shutemov" <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Thomas Gleixner <[email protected]>
1 parent 4495c08 commit 6a0b41d

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

arch/x86/mm/mmap.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ static unsigned long stack_maxrandom_size(void)
5555
#define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
5656
#define MAX_GAP (TASK_SIZE/6*5)
5757

58+
#ifdef CONFIG_COMPAT
59+
# define mmap32_rnd_bits mmap_rnd_compat_bits
60+
# define mmap64_rnd_bits mmap_rnd_bits
61+
#else
62+
# define mmap32_rnd_bits mmap_rnd_bits
63+
# define mmap64_rnd_bits mmap_rnd_bits
64+
#endif
65+
5866
static int mmap_is_legacy(void)
5967
{
6068
if (current->personality & ADDR_COMPAT_LAYOUT)
@@ -66,20 +74,14 @@ static int mmap_is_legacy(void)
6674
return sysctl_legacy_va_layout;
6775
}
6876

69-
unsigned long arch_mmap_rnd(void)
77+
static unsigned long arch_rnd(unsigned int rndbits)
7078
{
71-
unsigned long rnd;
72-
73-
if (mmap_is_ia32())
74-
#ifdef CONFIG_COMPAT
75-
rnd = get_random_long() & ((1UL << mmap_rnd_compat_bits) - 1);
76-
#else
77-
rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1);
78-
#endif
79-
else
80-
rnd = get_random_long() & ((1UL << mmap_rnd_bits) - 1);
79+
return (get_random_long() & ((1UL << rndbits) - 1)) << PAGE_SHIFT;
80+
}
8181

82-
return rnd << PAGE_SHIFT;
82+
unsigned long arch_mmap_rnd(void)
83+
{
84+
return arch_rnd(mmap_is_ia32() ? mmap32_rnd_bits : mmap64_rnd_bits);
8385
}
8486

8587
static unsigned long mmap_base(unsigned long rnd)

0 commit comments

Comments
 (0)