]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
mm: make stack guard page logic use vm_prev pointer
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 20 Aug 2010 23:49:40 +0000 (16:49 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 21 Aug 2010 15:50:00 +0000 (08:50 -0700)
Like the mlock() change previously, this makes the stack guard check
code use vma->vm_prev to see what the mapping below the current stack
is, rather than have to look it up with find_vma().

Also, accept an abutting stack segment, since that happens naturally if
you split the stack with mlock or mprotect.

Tested-by: Ian Campbell <ijc@hellion.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/memory.c

index b6e5fd23cc5a48e13f49b0d824ca3cc9713bd3ab..2ed2267439df0f894011ab62adef6d7efe68db9a 100644 (file)
@@ -2770,11 +2770,18 @@ static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned lo
 {
        address &= PAGE_MASK;
        if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
-               address -= PAGE_SIZE;
-               if (find_vma(vma->vm_mm, address) != vma)
-                       return -ENOMEM;
+               struct vm_area_struct *prev = vma->vm_prev;
+
+               /*
+                * Is there a mapping abutting this one below?
+                *
+                * That's only ok if it's the same stack mapping
+                * that has gotten split..
+                */
+               if (prev && prev->vm_end == address)
+                       return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
 
-               expand_stack(vma, address);
+               expand_stack(vma, address - PAGE_SIZE);
        }
        return 0;
 }