Patchwork [2/3] vm: fix vm_pgoff wrap in stack expansion - CVE-2011-2496

login
register
mail settings
Submitter Paolo Pisati
Date Oct. 11, 2011, 3:39 p.m.
Message ID <1318347561-1410-3-git-send-email-paolo.pisati@canonical.com>
Download mbox | patch
Permalink /patch/118999/
State New
Headers show

Comments

Paolo Pisati - Oct. 11, 2011, 3:39 p.m.
From: Linus Torvalds <torvalds@linux-foundation.org>

vm: fix vm_pgoff wrap in stack expansion

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>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

CVE-2011-2496

BugLink: http://bugs.launchpad.net/bugs/869243

commit upstream a626ca6a656450e9f4df91d0dda238fff23285f4

Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
---
 mm/mmap.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

Patch

diff --git a/mm/mmap.c b/mm/mmap.c
index a53ad79..1508d86 100644
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -1779,10 +1779,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);