Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[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: William Irwin <wli@holomorphy.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

William Lee Irwin III and committed by
Linus Torvalds
cafdd8ba c33880aa

+3 -3
+3 -3
mm/rmap.c
··· 626 626 pgd_t *pgd; 627 627 pud_t *pud; 628 628 pmd_t *pmd; 629 - pte_t *pte; 629 + pte_t *pte, *original_pte; 630 630 pte_t pteval; 631 631 struct page *page; 632 632 unsigned long address; ··· 658 658 if (!pmd_present(*pmd)) 659 659 goto out_unlock; 660 660 661 - for (pte = pte_offset_map(pmd, address); 661 + for (original_pte = pte = pte_offset_map(pmd, address); 662 662 address < end; pte++, address += PAGE_SIZE) { 663 663 664 664 if (!pte_present(*pte)) ··· 694 694 (*mapcount)--; 695 695 } 696 696 697 - pte_unmap(pte); 697 + pte_unmap(original_pte); 698 698 out_unlock: 699 699 spin_unlock(&mm->page_table_lock); 700 700 }