Re: [PATCH 07/32] mm/khugepaged: check the VMA before walking page tables when collapsing
From: Jose A. Perez de Azpillaga
Date: Sun Nov 29 2026 - 14:55:38 EST
On 11/29/26 11:06 AM, 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: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>
--
cheers,
jose a. p-a