mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
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 commit6aab341e0a("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. Fixes:6aab341e0a("mm: re-architect the VM_UNPAGED logic") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason <mason@kernel.org> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> [ david: simplify comment and description ] Reviewed-by: Pedro Falcato <pfalcato@suse.de> Tested-by: Muhammad Usama Anjum <usama.anjum@arm.com> Link: https://patch.msgid.link/20261031-fixes_core-v3-35-d6437171ecc3@kernel.org Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
This commit is contained in:
parent
22d043c1da
commit
8db6921cc0
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user