* [PATCH 1/2] mm/userfaultfd: recheck WP registration in the hugetlb UFFDIO_COPY retry [not found] <20261029221129.89068-1-azpijr@gmail.com> @ 2026-10-29 22:11 ` Jose A. Perez de Azpillaga 2026-10-31 9:24 ` Mike Rapoport 0 siblings, 1 reply; 3+ messages in thread From: Jose A. Perez de Azpillaga @ 2026-10-29 22:11 UTC (permalink / raw) To: Andrew Morton, Mike Rapoport, David Hildenbrand, Shuah Khan, Peter Xu Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel, linux-kselftest, Muchun Song, Oscar Salvador, Jose A. Perez de Azpillaga, stable mfill_atomic_hugetlb() drops its locks to copy the source page with page faults enabled and then looks the VMA up again. The retry doesn't check that the VMA is still registered for WP, so if the range is re-registered without WP in that window, a UFFDIO_COPY_MODE_WP copy installs a uffd-wp PTE in a VMA without VM_UFFD_WP. That is one of the leftover uffd bits hugetlb_fault() has to tolerate. The non-hugetlb retry goes through mfill_get_vma() again and fails with -EINVAL. Do the same check in the hugetlb retry. Fixes: 6041c6917903 ("mm/hugetlb: take care of UFFDIO_COPY_MODE_WP") Cc: stable@vger.kernel.org Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com> --- mm/userfaultfd.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 3b71712edab4..a70ecfc8a998 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -810,6 +810,10 @@ static __always_inline ssize_t mfill_atomic_hugetlb( if (vma_hpagesize != vma_kernel_pagesize(dst_vma)) goto out_unlock_vma; + /* The range may have been re-registered without WP meanwhile. */ + if ((flags & MFILL_ATOMIC_WP) && !(dst_vma->vm_flags & VM_UFFD_WP)) + goto out_unlock_vma; + /* * If memory mappings are changing because of non-cooperative * operation (e.g. mremap) running in parallel, bail out and -- 2.55.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] mm/userfaultfd: recheck WP registration in the hugetlb UFFDIO_COPY retry 2026-10-29 22:11 ` [PATCH 1/2] mm/userfaultfd: recheck WP registration in the hugetlb UFFDIO_COPY retry Jose A. Perez de Azpillaga @ 2026-10-31 9:24 ` Mike Rapoport 2026-10-31 12:40 ` Jose A. Perez de Azpillaga 0 siblings, 1 reply; 3+ messages in thread From: Mike Rapoport @ 2026-10-31 9:24 UTC (permalink / raw) To: Jose A. Perez de Azpillaga Cc: Andrew Morton, David Hildenbrand, Shuah Khan, Peter Xu, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel, linux-kselftest, Muchun Song, Oscar Salvador, stable Hi Jose, On Thu, Oct 29, 2026 at 11:11:01PM +0100, Jose A. Perez de Azpillaga wrote: > mfill_atomic_hugetlb() drops its locks to copy the source page with page > faults enabled and then looks the VMA up again. The retry doesn't check > that the VMA is still registered for WP, so if the range is re-registered > without WP in that window, a UFFDIO_COPY_MODE_WP copy installs a uffd-wp > PTE in a VMA without VM_UFFD_WP. That is one of the leftover uffd bits > hugetlb_fault() has to tolerate. The "leftover" sentence will be confusing for future readers > The non-hugetlb retry goes through mfill_get_vma() again and fails with > -EINVAL. Do the same check in the hugetlb retry. No need to reference non-hugetlb path, just describe the added check. > Fixes: 6041c6917903 ("mm/hugetlb: take care of UFFDIO_COPY_MODE_WP") > Cc: stable@vger.kernel.org > Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com> With those fixed: Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> > --- > mm/userfaultfd.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > index 3b71712edab4..a70ecfc8a998 100644 > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -810,6 +810,10 @@ static __always_inline ssize_t mfill_atomic_hugetlb( > if (vma_hpagesize != vma_kernel_pagesize(dst_vma)) > goto out_unlock_vma; > > + /* The range may have been re-registered without WP meanwhile. */ > + if ((flags & MFILL_ATOMIC_WP) && !(dst_vma->vm_flags & VM_UFFD_WP)) > + goto out_unlock_vma; > + > /* > * If memory mappings are changing because of non-cooperative > * operation (e.g. mremap) running in parallel, bail out and > -- > 2.55.0 > -- Sincerely yours, Mike. ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] mm/userfaultfd: recheck WP registration in the hugetlb UFFDIO_COPY retry 2026-10-31 9:24 ` Mike Rapoport @ 2026-10-31 12:40 ` Jose A. Perez de Azpillaga 0 siblings, 0 replies; 3+ messages in thread From: Jose A. Perez de Azpillaga @ 2026-10-31 12:40 UTC (permalink / raw) To: Mike Rapoport Cc: Andrew Morton, David Hildenbrand, Shuah Khan, Peter Xu, Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel, linux-kselftest, Muchun Song, Oscar Salvador, stable On 10/31/26 10:24 AM, Mike Rapoport wrote: > Hi Jose, > > On Thu, Oct 29, 2026 at 11:11:01PM +0100, Jose A. Perez de Azpillaga wrote: >> mfill_atomic_hugetlb() drops its locks to copy the source page with page >> faults enabled and then looks the VMA up again. The retry doesn't check >> that the VMA is still registered for WP, so if the range is re-registered >> without WP in that window, a UFFDIO_COPY_MODE_WP copy installs a uffd-wp >> PTE in a VMA without VM_UFFD_WP. That is one of the leftover uffd bits >> hugetlb_fault() has to tolerate. > > The "leftover" sentence will be confusing for future readers sure, will drop it. > >> The non-hugetlb retry goes through mfill_get_vma() again and fails with >> -EINVAL. Do the same check in the hugetlb retry. > > No need to reference non-hugetlb path, just describe the added check. okay, will do in v2. > >> Fixes: 6041c6917903 ("mm/hugetlb: take care of UFFDIO_COPY_MODE_WP") >> Cc: stable@vger.kernel.org >> Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com> > > With those fixed: > > Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org> thanks for the review :) > >> --- >> mm/userfaultfd.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c >> index 3b71712edab4..a70ecfc8a998 100644 >> --- a/mm/userfaultfd.c >> +++ b/mm/userfaultfd.c >> @@ -810,6 +810,10 @@ static __always_inline ssize_t mfill_atomic_hugetlb( >> if (vma_hpagesize != vma_kernel_pagesize(dst_vma)) >> goto out_unlock_vma; >> >> + /* The range may have been re-registered without WP meanwhile. */ >> + if ((flags & MFILL_ATOMIC_WP) && !(dst_vma->vm_flags & VM_UFFD_WP)) >> + goto out_unlock_vma; >> + >> /* >> * If memory mappings are changing because of non-cooperative >> * operation (e.g. mremap) running in parallel, bail out and >> -- >> 2.55.0 >> > -- cheers, jose a. p-a ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-31 12:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261029221129.89068-1-azpijr@gmail.com>
2026-10-29 22:11 ` [PATCH 1/2] mm/userfaultfd: recheck WP registration in the hugetlb UFFDIO_COPY retry Jose A. Perez de Azpillaga
2026-10-31 9:24 ` Mike Rapoport
2026-10-31 12:40 ` Jose A. Perez de Azpillaga
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox