mm/rmap: fix PTE table overruns during batched reference checks

With a folded PMD, pmd_addr_end() simply returns the supplied end.
folio_referenced_one() can therefore walk past the PTE table when
checking references to a large folio.

Folded PMDs are uncommon, but can occur even on arm64, for example
with 64K pages and a 42-bit virtual address space.

Use pte_table_clamped_end() to clamp the range to the PTE table and
VMA boundaries.

Fixes: 52e054f718 ("mm: rmap: support batched checks of the references for large folios")
Cc: [email protected]
Reported-by: Chris Mason <[email protected]>
Reviewed-by: Baolin Wang <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: David Hildenbrand (Arm) <[email protected]>
This commit is contained in:
David Hildenbrand (Arm)
2026-11-13 11:14:48 +01:00
parent d8bbf58589
commit 2d9b9352ef
+1 -1
View File
@@ -973,7 +973,7 @@ static bool folio_referenced_one(struct folio *folio,
pteval = ptep_get(pvmw.pte);
if (pvmw.pte && pte_present(pteval) && folio_test_large(folio)) {
const unsigned long end_addr = pmd_addr_end(address, vma->vm_end);
const unsigned long end_addr = pte_table_clamped_end(address, vma->vm_end);
const unsigned int max_nr = (end_addr - address) >> PAGE_SHIFT;
nr = folio_pte_batch(folio, pvmw.pte, pteval, max_nr);