FAILED: patch "[PATCH] mm/memory: reject remote COW faults on PFN mappings" failed to apply to 6.6-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.6-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.6.y
git checkout FETCH_HEAD
git cherry-pick -x 8db6921cc07b74197a3866d62ed262b68aeadcf3
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.6.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 8db6921cc07b74197a3866d62ed262b68aeadcf3 Mon Sep 17 00:00:00 2001
From: Chris Mason <[email protected]>
Date: Sat, 31 Oct 2026 10:40:04 +0100
Subject: [PATCH] mm/memory: reject remote COW faults on PFN mappings
When handling a COW fault without a normal source page (PFN mappings), __wp_page_copy_user() copies from the faulting user address. For remote faults, this accesses the wrong address space, resulting in wrong data getting copied.
For example, user_events updates an enable bit in the registering process's memory. If that memory needs to be faulted in, user_event_enabler_fault_fixup() calls fixup_user_fault() from a work item. Placing the enable bit in a private PFN mapping can trigger this remote COW path.
Reject these faults with VM_FAULT_SIGBUS when the target mm differs from current->mm: remote faults. Ordinary (non-PFN) mappings are not affected.
The user-address copy dates back to commit 6aab341e0a28 ("mm: re-architect the VM_UNPAGED logic"); likely, actual ways to get remote faults in there on COW PFN mappings appeared afterwards. But the fix is simple and straight forward.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/memory.c | 9 +++++++++ 1 file changed, 9 insertions(+)
mm/memory.c +9 -0
@@ -3761,6 +3761,13 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src,return 0 ; } +/* +* __copy_from_user_inatomic() only works as expected for local faults. +* Reject remote faults. +*/ +if (unlikely (mm != current->mm)) +return -EFAULT ; +/* * If the source page was a PFN mapping, we don't have * a "struct page" for it. We do a best-effort copy by
@@ -4086,6 +4093,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)folio_put (old_folio);delayacct_wpcopy_end (); +if (err == -EFAULT ) +return VM_FAULT_SIGBUS ;return err == -EHWPOISON ?VM_FAULT_HWPOISON :0 ; }kmsan_copy_page_meta (&new_folio->page, vmf->page);
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/2 mm: call wp_page_copy() under the VMA lock
From: "Matthew Wilcox (Oracle)" <[email protected]>
[ Upstream commit 164b06f238b986317131e6b61b2f22aabcbc2cc0 ]
It is usually safe to call wp_page_copy() under the VMA lock. The only unsafe situation is when no anon_vma has been allocated for this VMA, and we have to look at adjacent VMAs to determine if their anon_vma can be shared. Since this happens only for the first COW of a page in this VMA, the majority of calls to wp_page_copy() do not need to fall back to the mmap_sem.
Add vmf_anon_prepare() as an alternative to anon_vma_prepare() which will return RETRY if we currently hold the VMA lock and need to allocate an anon_vma. This lets us drop the check in do_wp_page().
Stable-dep-of: 8db6921cc07b ("mm/memory: reject remote COW faults on PFN mappings")
--- mm/memory.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-)
mm/memory.c +26 -13
@@ -3050,6 +3050,21 @@ static inline void wp_page_reuse(struct vm_fault *vmf)count_vm_event (PGREUSE ); } +static vm_fault_t vmf_anon_prepare (struct vm_fault *vmf) +{ +struct vm_area_struct *vma = vmf->vma; + +if (likely (vma->anon_vma)) +return 0 ; +if (vmf->flags &FAULT_FLAG_VMA_LOCK ) { +vma_end_read (vma); +return VM_FAULT_RETRY ; + } +if (__anon_vma_prepare (vma)) +return VM_FAULT_OOM ; +return 0 ; +} +/* * Handle the case of a page which we actually need to copy to a new page, * either due to COW or unsharing.
@@ -3077,27 +3092,29 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)pte_t entry;int page_copied =0 ;struct mmu_notifier_range range; -int ret; +vm_fault_t ret;delayacct_wpcopy_start ();if (vmf->page) old_folio =page_folio (vmf->page); -if (unlikely (anon_vma_prepare (vma))) - goto oom; + ret =vmf_anon_prepare (vmf); +if (unlikely (ret)) + goto out;if (is_zero_pfn (pte_pfn (vmf->orig_pte))) { new_folio =vma_alloc_zeroed_movable_folio (vma, vmf->address);if (!new_folio) goto oom; }else { +int err; new_folio =vma_alloc_folio (GFP_HIGHUSER_MOVABLE ,0 , vma, vmf->address, false);if (!new_folio) goto oom; - ret =__wp_page_copy_user (&new_folio->page, vmf->page, vmf); -if (ret) { + err =__wp_page_copy_user (&new_folio->page, vmf->page, vmf); +if (err) {/* * COW failed, if the fault was solved by other, * it's fine. If not, userspace would re-fault on
@@ -3110,7 +3127,7 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)folio_put (old_folio);delayacct_wpcopy_end (); -return ret == -EHWPOISON ?VM_FAULT_HWPOISON :0 ; +return err == -EHWPOISON ?VM_FAULT_HWPOISON :0 ; }kmsan_copy_page_meta (&new_folio->page, vmf->page); }
@@ -3220,11 +3237,13 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf) oom_free_new:folio_put (new_folio); oom: + ret =VM_FAULT_OOM ; +out:if (old_folio)folio_put (old_folio);delayacct_wpcopy_end (); -return VM_FAULT_OOM ; +return ret; }/**
@@ -3449,12 +3468,6 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf)return 0 ; } copy: -if ((vmf->flags &FAULT_FLAG_VMA_LOCK ) && !vma->anon_vma) { -pte_unmap_unlock (vmf->pte, vmf->ptl); -vma_end_read (vmf->vma); -return VM_FAULT_RETRY ; - } -/* * Ok, we need to copy. Oh, well.. */
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 mm/memory: reject remote COW faults on PFN mappings
From: Chris Mason <[email protected]>
[ Upstream commit 8db6921cc07b74197a3866d62ed262b68aeadcf3 ]
When handling a COW fault without a normal source page (PFN mappings), __wp_page_copy_user() copies from the faulting user address. For remote faults, this accesses the wrong address space, resulting in wrong data getting copied.
For example, user_events updates an enable bit in the registering process's memory. If that memory needs to be faulted in, user_event_enabler_fault_fixup() calls fixup_user_fault() from a work item. Placing the enable bit in a private PFN mapping can trigger this remote COW path.
Reject these faults with VM_FAULT_SIGBUS when the target mm differs from current->mm: remote faults. Ordinary (non-PFN) mappings are not affected.
The user-address copy dates back to commit 6aab341e0a28 ("mm: re-architect the VM_UNPAGED logic"); likely, actual ways to get remote faults in there on COW PFN mappings appeared afterwards. But the fix is simple and straight forward.
Fix generated by an LLM and sent by Chris Mason in private.
--- mm/memory.c | 9 +++++++++ 1 file changed, 9 insertions(+)
mm/memory.c +9 -0
@@ -2837,6 +2837,13 @@ static inline int __wp_page_copy_user(struct page *dst, struct page *src,return 0 ; } +/* +* __copy_from_user_inatomic() only works as expected for local faults. +* Reject remote faults. +*/ +if (unlikely (mm != current->mm)) +return -EFAULT ; +/* * If the source page was a PFN mapping, we don't have * a "struct page" for it. We do a best-effort copy by
@@ -3127,6 +3134,8 @@ static vm_fault_t wp_page_copy(struct vm_fault *vmf)folio_put (old_folio);delayacct_wpcopy_end (); +if (err == -EFAULT ) +return VM_FAULT_SIGBUS ;return err == -EHWPOISON ?VM_FAULT_HWPOISON :0 ; }kmsan_copy_page_meta (&new_folio->page, vmf->page);
Signature · 1 line
2.53.0