Skip to content

Commit c03aed6

Browse files
torvaldsgregkh
authored andcommitted
mm: propagate error from stack expansion even for guard page
commit fee7e49 upstream. 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 d782437: "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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 53bcf5c commit c03aed6

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

‎include/linux/mm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ extern int expand_downwards(struct vm_area_struct *vma,
19361936
#if VM_GROWSUP
19371937
extern int expand_upwards(struct vm_area_struct *vma, unsigned long address);
19381938
#else
1939-
#define expand_upwards(vma, address) do { } while (0)
1939+
#define expand_upwards(vma, address) (0)
19401940
#endif
19411941

19421942
/* Look up the first VMA which satisfies addr < vm_end, NULL if none. */

‎mm/memory.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,7 +2613,7 @@ static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned lo
26132613
if (prev && prev->vm_end == address)
26142614
return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
26152615

2616-
expand_downwards(vma, address - PAGE_SIZE);
2616+
return expand_downwards(vma, address - PAGE_SIZE);
26172617
}
26182618
if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
26192619
struct vm_area_struct *next = vma->vm_next;
@@ -2622,7 +2622,7 @@ static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned lo
26222622
if (next && next->vm_start == address + PAGE_SIZE)
26232623
return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
26242624

2625-
expand_upwards(vma, address + PAGE_SIZE);
2625+
return expand_upwards(vma, address + PAGE_SIZE);
26262626
}
26272627
return 0;
26282628
}

0 commit comments

Comments
 (0)