MIPS: VDSO: Reduce VDSO_RANDOMIZE_SIZE to 64MB for 64bit
Subsystems (2)
PATCH v2 1/1 MIPS: VDSO: Reduce VDSO_RANDOMIZE_SIZE to 64MB for 64bit
Commit ea7e0480a4b695d0aa6b3 ("MIPS: VDSO: Always map near top of user memory") set VDSO_RANDOMIZE_SIZE to 256MB for 64bit kernel. But take a look at arch/mips/mm/mmap.c we can see that MIN_GAP is 128MB, which means the mmap_base may be at (user_address_top - 128MB). This make the stack be surrounded by mmaped areas, then stack expanding fails and causes a segmentation fault. Therefore, VDSO_RANDOMIZE_SIZE should be less than MIN_GAP and this patch reduce it to 64MB.
By the way, not all VDSO_RANDOMIZE_SIZE can be used for vdso_base() randomization because VDSO need some room to locate itself (in this patch we reserve 64KB).
--- arch/mips/include/asm/processor.h | 2 +- arch/mips/kernel/vdso.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/mips/include/asm/processor.h +1 -1
@@ -81,7 +81,7 @@ extern unsigned int vced_count, vcei_count;#endif -#define VDSO_RANDOMIZE_SIZE (TASK_IS_32BIT_ADDR ? SZ_1M : SZ_256M) +#define VDSO_RANDOMIZE_SIZE (TASK_IS_32BIT_ADDR ? SZ_1M : SZ_64M)extern unsigned long mips_stack_top (void );#define STACK_TOP mips_stack_top()
arch/mips/kernel/vdso.c +1 -1
@@ -106,7 +106,7 @@ static unsigned long vdso_base(void) base =STACK_TOP +PAGE_SIZE ;if (current->flags &PF_RANDOMIZE ) { - base +=get_random_int () & (VDSO_RANDOMIZE_SIZE -1 ); + base +=get_random_int () & (VDSO_RANDOMIZE_SIZE -SZ_64K -1 ); base =PAGE_ALIGN (base); }
Signature · 1 line
2.7.0
Hi Huacai,
Quoted 11 lines · Huacai Chen
By the way, not all
VDSO_RANDOMIZE_SIZEcan be used forvdso_base()randomization because VDSO need some room to locate itself (in this patch we reserve 64KB).%
arch/mips/kernel/vdso.c +0
-0
arch/mips/kernel/vdso.c static unsigned long vdso_base(void) · line 111
Quoted 7 lines
arch/mips/kernel/vdso.c +1
-1@@ -106,7 +106,7 @@ static unsigned long vdso_base(void) base =STACK_TOP +PAGE_SIZE ;if (current->flags &PF_RANDOMIZE ) { - base +=get_random_int () & (VDSO_RANDOMIZE_SIZE -1 ); + base +=get_random_int () & (VDSO_RANDOMIZE_SIZE -SZ_64K -1 ); base =PAGE_ALIGN (base); }
This change in v2 is unnecessary - STACK_TOP already accounts for the size of the VDSO, so we don't need to leave space for it a second time here.
v1 of your patch is in mips-fixes, which I'll submit a pull request for soon.
Thanks,
Paul