tree e372cdb3856c9585587283c21b5b99a792a1a41d
parent e6cb99413da42af413c11a394538ddc8b9d201e1
author David Gibson <[EMAIL PROTECTED]> Sat, 06 Aug 2005 01:59:35 -0700
committer Linus Torvalds <[EMAIL PROTECTED]> Sat, 06 Aug 2005 02:22:37 -0700

[PATCH] Fix hugepage crash on failing mmap()

This patch fixes a crash in the hugepage code.  unmap_hugepage_area() was
assuming that (due to prefault) PTEs must exist for all the area in
question.  However, this may not be the case, if mmap() encounters an error
before the prefault and calls unmap_region() to clean up any partial
mapping.

Depending on the hugepage configuration, this crash can be triggered by an
unpriveleged user.

Signed-off-by: David Gibson <[EMAIL PROTECTED]>
Cc: William Lee Irwin III <[EMAIL PROTECTED]>
Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>

 mm/hugetlb.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/mm/hugetlb.c b/mm/hugetlb.c
--- a/mm/hugetlb.c
+++ b/mm/hugetlb.c
@@ -301,6 +301,7 @@ void unmap_hugepage_range(struct vm_area
 {
        struct mm_struct *mm = vma->vm_mm;
        unsigned long address;
+       pte_t *ptep;
        pte_t pte;
        struct page *page;
 
@@ -309,9 +310,17 @@ void unmap_hugepage_range(struct vm_area
        BUG_ON(end & ~HPAGE_MASK);
 
        for (address = start; address < end; address += HPAGE_SIZE) {
-               pte = huge_ptep_get_and_clear(mm, address, huge_pte_offset(mm, 
address));
+               ptep = huge_pte_offset(mm, address);
+               if (! ptep)
+                       /* This can happen on truncate, or if an
+                        * mmap() is aborted due to an error before
+                        * the prefault */
+                       continue;
+
+               pte = huge_ptep_get_and_clear(mm, address, ptep);
                if (pte_none(pte))
                        continue;
+
                page = pte_page(pte);
                put_page(page);
        }
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to