mm: do not grow the stack vma just because of an overrun on preceding vma
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 27 Feb 2013 16:36:04 +0000 (08:36 -0800)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 2 Jul 2017 16:12:47 +0000 (17:12 +0100)
commit641fbf5980efa6a6a2d820344eb03959e29afb6f
tree3d048b55c9829882379e42c702410a71762b2709
parent8ff47baf77d722fe2721b977f633fbf7eaeacfe4
mm: do not grow the stack vma just because of an overrun on preceding vma

commit 09884964335e85e897876d17783c2ad33cf8a2e0 upstream.

The stack vma is designed to grow automatically (marked with VM_GROWSUP
or VM_GROWSDOWN depending on architecture) when an access is made beyond
the existing boundary.  However, particularly if you have not limited
your stack at all ("ulimit -s unlimited"), this can cause the stack to
grow even if the access was really just one past *another* segment.

And that's wrong, especially since we first grow the segment, but then
immediately later enforce the stack guard page on the last page of the
segment.  So _despite_ first growing the stack segment as a result of
the access, the kernel will then make the access cause a SIGSEGV anyway!

So do the same logic as the guard page check does, and consider an
access to within one page of the next segment to be a bad access, rather
than growing the stack to abut the next segment.

Reported-and-tested-by: Heiko Carstens <heiko.carstens@de.ibm.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
mm/mmap.c