Re: [PATCH 07/32] mm/khugepaged: check the VMA before walking page tables when collapsing
From: Baolin Wang
Date: Wed Dec 02 2026 - 04:07:42 EST
On 11/29/26 6:06 PM, David Hildenbrand (Arm) wrote:
MADV_COLLAPSE and khugepaged can end up traversing page tables of a VMA
through find_pmd_or_thp_or_none() before verifying that the VMA is still
as expected.
Calling find_pmd_or_thp_or_none() on a mapping with PUDs
(hugetlb/dax/PFNMAP) is invalid, as it treats every present PUD entry as
a pointer to a PMD table.
Consequently, we can end up interpreting the memory mapped by a PUD leaf
as a PMD table.
Let's fix it by performing the thp_vma_allowable_order() check before
the page table walk.
Further, let's also make find_pmd_or_thp_or_none() harder to get wrong
by rejecting any pgd/p4d/pud leaves.
This has high urgency, as unprivileged users can trigger it, although
getting relevant PUD mappings (e.g., hugetlb) should be rather uncommon
in most setups.
Fixes: 58ac9a8993a1 ("mm/khugepaged: attempt to map file/shmem-backed pte-mapped THPs by pmds")
Cc: stable@xxxxxxxxxxxxxxx
Reported-by: Chris Mason <mason@xxxxxxxxxx>
Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
---
LGTM.
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>