Re: [PATCH mm-hotfixes] mm: do not copy page tables unnecessarily for VM_UFFD_WP
From: David Hildenbrand (Red Hat)
Date: Wed Jan 14 2026 - 06:14:48 EST
On 1/14/26 12:00, Lorenzo Stoakes wrote:
Commit ab04b530e7e8 ("mm: introduce copy-on-fork VMAs and make
VM_MAYBE_GUARD one") aggregates flags checks in vma_needs_copy(), including
VM_UFFD_WP.
However in doing so, it incorrectly performed this check against
src_vma. This check was done on the assumption that all relevant flags are
copied upon fork.
However the userfaultfd logic is very innovative in that it implements
custom logic on fork in dup_userfaultfd(), including a rather well hidden
case where lacking UFFD_FEATURE_EVENT_FORK causes VM_UFFD_WP to not be
propagated to the destination VMA.
And indeed, vma_needs_copy(), prior to this patch, did check this property
on dst_vma, not src_vma.
Since all the other relevant flags are copied on fork, we can simply fix
this by checking against dst_vma.
While we're here, we fix a comment against VM_COPY_ON_FORK (noting that it
did indeed already reference dst_vma) to make it abundantly clear that we
must check against the destination VMA.
Reported-by: Chris Mason <clm@xxxxxxxx>
Closes: https://lore.kernel.org/all/20260113231257.3002271-1-clm@xxxxxxxx/
Fixes: ab04b530e7e8 ("mm: introduce copy-on-fork VMAs and make VM_MAYBE_GUARD one")
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@xxxxxxxxxx>
Acked-by: David Hildenbrand (Red Hat) <david@xxxxxxxxxx>
--
Cheers
David