]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
[PATCH] mincore: vma crossing fix
authorNick Piggin <npiggin@suse.de>
Wed, 14 Feb 2007 11:39:01 +0000 (12:39 +0100)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Thu, 15 Feb 2007 17:57:03 +0000 (09:57 -0800)
My mincore also forgot about crossing vmas.

Signed-off-by: Nick Piggin <npiggin@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/mincore.c

index 9c1d0a426e95f7b10cd14ee986d9cbe69fcc37f9..5efe0ded69b1857935d0295e9999210e4999a516 100644 (file)
@@ -77,8 +77,16 @@ static long do_mincore(unsigned long addr, unsigned char *vec, unsigned long pag
         * PTE array for our address.
         */
        nr = PTRS_PER_PTE - ((addr >> PAGE_SHIFT) & (PTRS_PER_PTE-1));
-       if (nr > pages)
-               nr = pages;
+
+       /*
+        * Don't overrun this vma
+        */
+       nr = min(nr, (vma->vm_end - addr) >> PAGE_SHIFT);
+
+       /*
+        * Don't return more than the caller asked for
+        */
+       nr = min(nr, pages);
 
        pgd = pgd_offset(vma->vm_mm, addr);
        if (pgd_none_or_clear_bad(pgd))