FAULT_FLAG_UNSHARE breaks COW without making the mapping writable. Unlike FAULT_FLAG_WRITE, it must leave write protection in place so that a later write still faults. A read-only long-term pin can trigger an unshare fault on a huge zero PMD. do_huge_zero_wp_pmd() treats it as a write fault: it marks the replacement THP dirty, makes it writable if the VMA allows writes, and drops any UFFD write protection. Consequently, a later write no longer faults, which, for example, bypasses UFFD write protection. Let's fix it by returning VM_FAULT_FALLBACK for unshare faults, so the caller splits the PMD. The PTE fault path already handles unsharing while keeping the mapping read-only and preserving UFFD write protection and soft-dirty state. This has low urgency, as it requires a read-only long-term pin of a huge zero PMD. No need to CC stable. Fixes: 1ced09e0331f ("mm: allocate THP on hugezeropage wp-fault") Reported-by: Chris Mason Reviewed-by: Jose A. Perez de Azpillaga Tested-by: Gregory Price (Meta) Reviewed-by: Gregory Price (Meta) Reviewed-by: Zi Yan Signed-off-by: David Hildenbrand (Arm) --- mm/huge_memory.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index f40875208b193..2c6dea7ac8354 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2186,6 +2186,10 @@ static vm_fault_t do_huge_zero_wp_pmd(struct vm_fault *vmf) struct folio *folio; vm_fault_t ret = 0; + /* map_anon_folio_pmd_pf() does not handle unsharing correctly yet. */ + if (vmf->flags & FAULT_FLAG_UNSHARE) + return VM_FAULT_FALLBACK; + folio = vma_alloc_anon_folio_pmd(vma, vmf->address); if (unlikely(!folio)) return VM_FAULT_FALLBACK; @@ -2228,7 +2232,7 @@ vm_fault_t do_huge_pmd_wp_page(struct vm_fault *vmf) if (!(ret & VM_FAULT_FALLBACK)) return ret; - /* Fallback to splitting PMD if THP cannot be allocated */ + /* Fall back to PTE level. */ goto fallback; } -- 2.56.1