Re: [PATCH 07/32] mm/khugepaged: check the VMA before walking page tables when collapsing

From: Zi Yan

Date: Mon Nov 30 2026 - 11:31:49 EST


On 29 Nov 2026, at 5:06, 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>
> ---
> mm/khugepaged.c | 10 +++++-----
> mm/rmap.c | 6 +++---
> 2 files changed, 8 insertions(+), 8 deletions(-)
>

LGTM.

Reviewed-by: Zi Yan <ziy@xxxxxxxxxx>

Best Regards,
Yan, Zi