mm: propagate error from stack expansion even for guard page
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 6 Jan 2015 21:00:05 +0000 (13:00 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 6 Jan 2015 21:00:05 +0000 (13:00 -0800)
commitfee7e49d45149fba60156f5b59014f764d3e3728
tree002f1613fbaec50a2637abb0777128c3830fced7
parentb1940cd21c0f4abdce101253e860feff547291b0
mm: propagate error from stack expansion even for guard page

Jay Foad reports that the address sanitizer test (asan) sometimes gets
confused by a stack pointer that ends up being outside the stack vma
that is reported by /proc/maps.

This happens due to an interaction between RLIMIT_STACK and the guard
page: when we do the guard page check, we ignore the potential error
from the stack expansion, which effectively results in a missing guard
page, since the expected stack expansion won't have been done.

And since /proc/maps explicitly ignores the guard page (commit
d7824370e263: "mm: fix up some user-visible effects of the stack guard
page"), the stack pointer ends up being outside the reported stack area.

This is the minimal patch: it just propagates the error.  It also
effectively makes the guard page part of the stack limit, which in turn
measn that the actual real stack is one page less than the stack limit.

Let's see if anybody notices.  We could teach acct_stack_growth() to
allow an extra page for a grow-up/grow-down stack in the rlimit test,
but I don't want to add more complexity if it isn't needed.

Reported-and-tested-by: Jay Foad <jay.foad@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/mm.h
mm/memory.c