Re: [PATCH v2 30/35] mm/hugetlb: unshare PMDs of a split VMA if allocating its lock fails

From: Jose A. Perez de Azpillaga

Date: Fri Dec 04 2026 - 06:46:35 EST


On 12/3/26 12:37 PM, David Hildenbrand (Arm) wrote:
> From: Chris Mason <mason@xxxxxxxxxx>
>
> If we split a VMA that has shared PMD page tables mapped, and allocating
> the hugetlb VMA lock for the new VMA fails, a fault in the new VMA can
> race with a hole punch and access page tables that were already freed.
>
> __split_vma() calls hugetlb_vm_op_open() for the new VMA, which
> allocates its hugetlb VMA lock in hugetlb_vma_lock_alloc(). If that
> allocation fails, the new VMA is left without a lock.
>
> A VMA that has shared PMD page tables needs the hugetlb VMA lock, since
> the lock synchronizes huge_pmd_unshare() with concurrent page table
> walks, including faults.
>
> want_pmd_share() and page_table_shareable() prevent new sharing without
> the lock, but a split leaves previously shared page tables in place for
> the new VMA, and hugetlb_vm_op_open() can't currently return an error if
> the allocation fails.
>
> This can, for example, happen for an OOM victim. Then, nothing prevents
> a hole punch from unsharing the page table of the new VMA while a fault
> in the new VMA is still using it, and the last other sharer from freeing
> it:
>
> fault in the new VMA hole punch, then munmap()
> ==================== =========================
> hugetlb_vma_lock_read()
> no lock, does nothing
> huge_pte_alloc()
> pointer into shared table
> folio_zero_user()
> hugetlb_vma_trylock_write()
> no lock, returns 1
> huge_pmd_unshare(new VMA)
> pud_clear()
> last sharer frees the table
> huge_pte_lock()
> set_huge_pte_at()
>
> Let's fix it by unsharing the PMD page tables of a new VMA that has no
> lock. Also, exit hugetlb_split() early if the original VMA has no lock,
> as it cannot have shared PMD page tables then.
>
> This has low urgency, as it requires allocating the hugetlb VMA lock to
> fail during a split, which is practically only possible for OOM victims,
> and a race with a hole punch.
>
> Fixes: 131a79b474e9 ("hugetlb: fix vma lock handling during split vma and range unmapping")
> Cc: <stable@xxxxxxxxxxxxxxx>
> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
> [ david: return early if the original VMA has no lock, adjust comment
> and description ]
> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

with sashiko's arm/parisc atomic context point addressed feel free to add:

Reviewed-by: Jose A. Perez de Azpillaga <azpijr@xxxxxxxxx>

--
cheers,
jose a. p-a