mm: fix madvise infinine loop
authorNick Piggin <npiggin@suse.de>
Wed, 28 Mar 2007 19:29:38 +0000 (21:29 +0200)
committerAdrian Bunk <bunk@stusta.de>
Wed, 28 Mar 2007 19:29:38 +0000 (21:29 +0200)
madvise(MADV_REMOVE) can go into an infinite loop or cause an oops if the
call covers a region from the start of a vma, and extending past that vma.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Acked-by: Hugh Dickins <hugh@veritas.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
mm/madvise.c

index 4e196155a0c3635801bd0f8dcff0b18ce1bbcf37..77916e9fc52bc466abb08d55457b8c79b0e05854 100644 (file)
@@ -155,11 +155,14 @@ static long madvise_dontneed(struct vm_area_struct * vma,
  * Other filesystems return -ENOSYS.
  */
 static long madvise_remove(struct vm_area_struct *vma,
+                               struct vm_area_struct **prev,
                                unsigned long start, unsigned long end)
 {
        struct address_space *mapping;
         loff_t offset, endoff;
 
+       *prev = vma;
+
        if (vma->vm_flags & (VM_LOCKED|VM_NONLINEAR|VM_HUGETLB))
                return -EINVAL;
 
@@ -199,7 +202,7 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev,
                error = madvise_behavior(vma, prev, start, end, behavior);
                break;
        case MADV_REMOVE:
-               error = madvise_remove(vma, start, end);
+               error = madvise_remove(vma, prev, start, end);
                break;
 
        case MADV_WILLNEED: