Commit cafdd8ba authored by William Lee Irwin III's avatar William Lee Irwin III Committed by Linus Torvalds

[PATCH] try_to_unmap_cluster() passes out-of-bounds pte to pte_unmap()

try_to_unmap_cluster() does:
        for (pte = pte_offset_map(pmd, address);
                        address < end; pte++, address += PAGE_SIZE) {
		...
	}

	pte_unmap(pte);

It may take a little staring to notice, but pte can actually fall off the
end of the pte page in this iteration, which makes life difficult for
kmap_atomic() and the users not expecting it to BUG().  Of course, we're
somewhat lucky in that arithmetic elsewhere in the function guarantees that
at least one iteration is made, lest this force larger rearrangements to be
made.  This issue and patch also apply to non-mm mainline and with trivial
adjustments, at least two related kernels.

Discovered during internal testing at Oracle.
Signed-off-by: default avatarWilliam Irwin <wli@holomorphy.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent c33880aa
...@@ -626,7 +626,7 @@ static void try_to_unmap_cluster(unsigned long cursor, ...@@ -626,7 +626,7 @@ static void try_to_unmap_cluster(unsigned long cursor,
pgd_t *pgd; pgd_t *pgd;
pud_t *pud; pud_t *pud;
pmd_t *pmd; pmd_t *pmd;
pte_t *pte; pte_t *pte, *original_pte;
pte_t pteval; pte_t pteval;
struct page *page; struct page *page;
unsigned long address; unsigned long address;
...@@ -658,7 +658,7 @@ static void try_to_unmap_cluster(unsigned long cursor, ...@@ -658,7 +658,7 @@ static void try_to_unmap_cluster(unsigned long cursor,
if (!pmd_present(*pmd)) if (!pmd_present(*pmd))
goto out_unlock; goto out_unlock;
for (pte = pte_offset_map(pmd, address); for (original_pte = pte = pte_offset_map(pmd, address);
address < end; pte++, address += PAGE_SIZE) { address < end; pte++, address += PAGE_SIZE) {
if (!pte_present(*pte)) if (!pte_present(*pte))
...@@ -694,7 +694,7 @@ static void try_to_unmap_cluster(unsigned long cursor, ...@@ -694,7 +694,7 @@ static void try_to_unmap_cluster(unsigned long cursor,
(*mapcount)--; (*mapcount)--;
} }
pte_unmap(pte); pte_unmap(original_pte);
out_unlock: out_unlock:
spin_unlock(&mm->page_table_lock); spin_unlock(&mm->page_table_lock);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment