Message ID | 20210303095116.3814443-1-namit@vmware.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v3] mm/userfaultfd: fix memory corruption due to writeprotect | expand |
> On Mar 3, 2021, at 1:51 AM, Nadav Amit <nadav.amit@gmail.com> wrote: > > From: Nadav Amit <namit@vmware.com> > > Userfaultfd self-test fails occasionally, indicating a memory > corruption. Please ignore - I will resend.
diff --git a/mm/memory.c b/mm/memory.c index 9e8576a83147..06da04f98936 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -3092,6 +3092,13 @@ static vm_fault_t do_wp_page(struct vm_fault *vmf) return handle_userfault(vmf, VM_UFFD_WP); } + /* + * Userfaultfd write-protect can defer flushes. Ensure the TLB + * is flushed in this case before copying. + */ + if (userfaultfd_wp(vmf->vma) && mm_tlb_flush_pending(vmf->vma->vm_mm)) + flush_tlb_page(vmf->vma, vmf->address); + vmf->page = vm_normal_page(vma, vmf->address, vmf->orig_pte); if (!vmf->page) { /*