Skip to content

Commit a0ee26f

Browse files
sulixgregkh
authored andcommitted
mm: only enforce minimum stack gap size if it's sensible
commit 69b50d4 upstream. The generic mmap_base code tries to leave a gap between the top of the stack and the mmap base address, but enforces a minimum gap size (MIN_GAP) of 128MB, which is too large on some setups. In particular, on arm tasks without ADDR_LIMIT_32BIT, the STACK_TOP value is less than 128MB, so it's impossible to fit such a gap in. Only enforce this minimum if MIN_GAP < MAX_GAP, as we'd prefer to honour MAX_GAP, which is defined proportionally, so scales better and always leaves us with both _some_ stack space and some room for mmap. This fixes the usercopy KUnit test suite on 32-bit arm, as it doesn't set any personality flags so gets the default (in this case 26-bit) task size. This test can be run with: ./tools/testing/kunit/kunit.py run --arch arm usercopy --make_options LLVM=1 Link: https://lkml.kernel.org/r/[email protected] Fixes: dba79c3 ("arm: use generic mmap top-down layout and brk randomization") Signed-off-by: David Gow <[email protected]> Reviewed-by: Kees Cook <[email protected]> Cc: Alexandre Ghiti <[email protected]> Cc: Linus Walleij <[email protected]> Cc: Luis Chamberlain <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Russell King <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 5e8afe3 commit a0ee26f

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

mm/util.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static unsigned long mmap_base(unsigned long rnd, struct rlimit *rlim_stack)
463463
if (gap + pad > gap)
464464
gap += pad;
465465

466-
if (gap < MIN_GAP)
466+
if (gap < MIN_GAP && MIN_GAP < MAX_GAP)
467467
gap = MIN_GAP;
468468
else if (gap > MAX_GAP)
469469
gap = MAX_GAP;

0 commit comments

Comments
 (0)