Skip to content

Commit

Permalink
vm: fix vm_pgoff wrap in stack expansion
Browse files Browse the repository at this point in the history
Commit 982134b ("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>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
torvalds committed Apr 13, 2011
1 parent 60d48c1 commit a626ca6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions mm/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1814,11 +1814,14 @@ 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;
perf_event_mmap(vma);
error = -ENOMEM;
if (grow <= vma->vm_pgoff) {
error = acct_stack_growth(vma, size, grow);
if (!error) {
vma->vm_start = address;
vma->vm_pgoff -= grow;
perf_event_mmap(vma);
}
}
}
vma_unlock_anon_vma(vma);
Expand Down

0 comments on commit a626ca6

Please sign in to comment.