Re: [PATCH v2 06/35] mm/hugetlb: keep HPAGE_RESV_UNMAPPED when forking

From: Jose A. Perez de Azpillaga

Date: Fri Dec 04 2026 - 05:32:33 EST


On 12/3/26 12:37 PM, David Hildenbrand (Arm) wrote:
> If a COW fault of the owner of a MAP_PRIVATE hugetlb reservation fails to
> allocate a folio, the owner keeps the folio, and unmap_ref_private()
> unmaps it from all other private VMAs that map it.
>
> We mark these VMAs with HPAGE_RESV_UNMAPPED, such that future faults in
> them fail instead of looking like the data was lost.
>
> However, when a process whose VMA has HPAGE_RESV_UNMAPPED set forks,
> hugetlb_dup_vma_private() clears vm_private_data of the child's VMA,
> including HPAGE_RESV_UNMAPPED.
>
> Consequently, faults in the grandchild of the original process can map a
> page cache folio or a new zeroed folio without any signal, silently
> losing the data.
>
> Reproduced by forking a child after writing to a folio in a private
> mapping, exhausting the pool such that the COW fault of the owner fails,
> and letting the child fork a grandchild after freeing up the pool again:
> the child gets SIGBUS when accessing the folio, but the grandchild reads
> zeroes.
>
> Let's fix it by keeping HPAGE_RESV_UNMAPPED when clearing the private
> data of the child's VMA.
>
> This has low urgency, as it requires a failed COW fault due to an
> exhausted pool, followed by a fork(). No need to CC stable.
>
> Fixes: 04f2cbe35699 ("hugetlb: guarantee that COW faults for a process that called mmap(MAP_PRIVATE) on hugetlbfs will succeed")
> 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