Commit f2f5d44bb48707fa2ea231bc554c9f6ccfb1a883

Authored by Linus Torvalds
Committed by Greg Kroah-Hartman
1 parent c03aed64c4

mm: Don't count the stack guard page towards RLIMIT_STACK

commit 690eac53daff34169a4d74fc7bfbd388c4896abb upstream.

Commit fee7e49d4514 ("mm: propagate error from stack expansion even for
guard page") made sure that we return the error properly for stack
growth conditions.  It also theorized that counting the guard page
towards the stack limit might break something, but also said "Let's see
if anybody notices".

Somebody did notice.  Apparently android-x86 sets the stack limit very
close to the limit indeed, and including the guard page in the rlimit
check causes the android 'zygote' process problems.

So this adds the (fairly trivial) code to make the stack rlimit check be
against the actual real stack size, rather than the size of the vma that
includes the guard page.

Reported-and-tested-by: Chih-Wei Huang <cwhuang@android-x86.org>
Cc: Jay Foad <jay.foad@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 5 additions and 2 deletions Side-by-side Diff

... ... @@ -2099,14 +2099,17 @@
2099 2099 {
2100 2100 struct mm_struct *mm = vma->vm_mm;
2101 2101 struct rlimit *rlim = current->signal->rlim;
2102   - unsigned long new_start;
  2102 + unsigned long new_start, actual_size;
2103 2103  
2104 2104 /* address space limit tests */
2105 2105 if (!may_expand_vm(mm, grow))
2106 2106 return -ENOMEM;
2107 2107  
2108 2108 /* Stack limit test */
2109   - if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
  2109 + actual_size = size;
  2110 + if (size && (vma->vm_flags & (VM_GROWSUP | VM_GROWSDOWN)))
  2111 + actual_size -= PAGE_SIZE;
  2112 + if (actual_size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
2110 2113 return -ENOMEM;
2111 2114  
2112 2115 /* mlock limit tests */