aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-04-13 08:07:28 -0700
committerGreg Kroah-Hartman <gregkh@suse.de>2011-11-07 13:47:39 -0800
commita2e441bdc3e86699fe95dcf3d54fc83c91d5cd9e (patch)
tree449ab1d01eceaed98a4392b79d2a678a7d5f3d6b
parenta0d5fef19e47dd30bcec109c0aff7749b0261bab (diff)
vm: fix vm_pgoff wrap in stack expansion
commit a626ca6a656450e9f4df91d0dda238fff23285f4 upstream. Commit 982134ba6261 ("mm: avoid wrapping vm_pgoff in mremap()") fixed the case of a expanding mapping causing vm_pgoff wrapping when you used mremap. But there was another case where we expand mappings hiding in plain sight: the automatic stack expansion. This fixes that case too. This one also found by Robert Święcki, using his nasty system call fuzzer tool. Good job. Reported-and-tested-by: Robert Święcki <robert@swiecki.net> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--mm/mmap.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/mm/mmap.c b/mm/mmap.c
index 892b7d3a9de..3e2f805c964 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1721,10 +1721,13 @@ static int expand_downwards(struct vm_area_struct *vma,
size = vma->vm_end - address;
grow = (vma->vm_start - address) >> PAGE_SHIFT;
- error = acct_stack_growth(vma, size, grow);
- if (!error) {
- vma->vm_start = address;
- vma->vm_pgoff -= grow;
+ error = -ENOMEM;
+ if (grow <= vma->vm_pgoff) {
+ error = acct_stack_growth(vma, size, grow);
+ if (!error) {
+ vma->vm_start = address;
+ vma->vm_pgoff -= grow;
+ }
}
}
anon_vma_unlock(vma);