]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - mm/mlock.c
mm: make the mlock() stack guard page checks stricter
[net-next-2.6.git] / mm / mlock.c
index 3f82720e05153a59e2fbb566942121763fc9a44d..cbae7c5b95680a1bfca1df7e11a215bfce15b57c 100644 (file)
@@ -135,6 +135,19 @@ void munlock_vma_page(struct page *page)
        }
 }
 
+/* Is the vma a continuation of the stack vma above it? */
+static inline int vma_stack_continue(struct vm_area_struct *vma, unsigned long addr)
+{
+       return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
+}
+
+static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
+{
+       return (vma->vm_flags & VM_GROWSDOWN) &&
+               (vma->vm_start == addr) &&
+               !vma_stack_continue(vma->vm_prev, addr);
+}
+
 /**
  * __mlock_vma_pages_range() -  mlock a range of pages in the vma.
  * @vma:   target vma
@@ -167,6 +180,12 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma,
        if (vma->vm_flags & VM_WRITE)
                gup_flags |= FOLL_WRITE;
 
+       /* We don't try to access the guard page of a stack vma */
+       if (stack_guard_page(vma, start)) {
+               addr += PAGE_SIZE;
+               nr_pages--;
+       }
+
        while (nr_pages > 0) {
                int i;