From: Andrew Morton <akpm@linux-foundation.org>
To: mm-commits@vger.kernel.org,surenb@google.com,peterx@redhat.com,
david@kernel.org,rppt@kernel.org,akpm@linux-foundation.org
Subject: + userfaultfd-write-lock-the-vma-before-clearing-its-uffd-state.patch added to mm-new branch
Date: Thu, 03 Dec 2026 23:04:01 -0800 [thread overview]
Message-ID: <20261204070401.D5D6C1F000C2@smtp.kernel.org> (raw)
In-Reply-To: <20261203-fixes-uffd-sashiko-v2-1-308ce557a7b6@kernel.org>
The patch titled
Subject: userfaultfd: write-lock the VMA before clearing its uffd state
has been added to the -mm mm-new branch. Its filename is
userfaultfd-write-lock-the-vma-before-clearing-its-uffd-state.patch
This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/userfaultfd-write-lock-the-vma-before-clearing-its-uffd-state.patch
This patch will later appear in the mm-new branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews. Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.
The mm-new branch of mm.git is not included in linux-next
If a few days of testing in mm-new is successful, the patch will me moved
into mm.git's mm-unstable branch, which is included in linux-next
Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's
*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days
------------------------------------------------------
From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
Subject: userfaultfd: write-lock the VMA before clearing its uffd state
Date: Thu, 03 Dec 2026 19:15:21 +0200
Patch series "userfaultfd: fixes for sashiko reports", v2.
These are fixes for userfaultfd bugs reported by sashiko, plus a THP
variant of one of them found while looking at the reports.
The first patch closes a race between closing a userfaultfd and uffd
operations of another userfaultfd of the same mm that can leave a
writable PTE with the uffd marker bit set.
The next two make UFFDIO_MOVE mark moved zero pages and THPs soft-dirty,
like it does for other PTEs and for the huge zero page.
The last one makes uffd-unit-tests free the test context when its setup
fails.
This patch (of 4):
UFFDIO_COPY and other uffd operations run under the per-VMA lock. They
check that the VMA is registered with a userfaultfd, but not that it is
registered with the userfaultfd that issued the operation.
When a userfaultfd is closed, userfaultfd_release_all() clears the uffd
state of its VMAs without write-locking them. Another userfaultfd of the
same mm can then install a write-protected PTE in a part of the VMA that
userfaultfd_clear_ptes() has already walked. The PTE keeps its uffd bit
after the VMA is unregistered, and a later write fault makes it writable
with the uffd bit still set.
close(uffd1) UFFDIO_COPY(uffd2, MODE_WP)
userfaultfd_release_all()
mmap_write_lock()
userfaultfd_clear_vma()
userfaultfd_clear_ptes()
change_protection()
// walks past addr
lock_vma_under_rcu()
validate_dst_vma()
// installs PTE with the uffd bit
// at addr
vma_end_read()
userfaultfd_reset_ctx()
vma_start_write()
mmap_write_unlock()
write fault at addr
do_wp_page()
// the PTE becomes writable with the uffd bit set
UFFDIO_UNREGISTER is not affected since commit 35f7ecd55ce7
("mm/userfaultfd: write-lock the VMA before waking waiters when
unregistering").
Write-lock the VMA in userfaultfd_clear_ptes() before walking it.
Link: https://lore.kernel.org/20261203-fixes-uffd-sashiko-v2-0-308ce557a7b6@kernel.org
Link: https://patch.msgid.link/20261203-fixes-uffd-sashiko-v2-1-308ce557a7b6@kernel.org
Fixes: c88033efe9a3 ("mm/userfaultfd: reset ptes when close() for wr-protected ones")
Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://sashiko.dev/bug/linux-5cddfd13-146a-47fc-97f8-feca4b2339b4
Reviewed-by: Suren Baghdasaryan <surenb@google.com>
Cc: David Hildenbrand <david@kernel.org>
Cc: Peter Xu <peterx@redhat.com>
mm/userfaultfd.c | 3 +++
1 file changed, 3 insertions(+)
--- a/mm/userfaultfd.c~userfaultfd-write-lock-the-vma-before-clearing-its-uffd-state
+++ a/mm/userfaultfd.c
@@ -2221,6 +2221,9 @@ static void userfaultfd_clear_ptes(struc
if (!userfaultfd_protected(vma))
return;
+ /* keep uffd operations under the per-VMA lock away from the walk */
+ vma_start_write(vma);
+
if (userfaultfd_wp(vma))
mm_cp_flags |= MM_CP_UFFD_WP_RESOLVE;
if (userfaultfd_rwp(vma))
_
Patches currently in -mm which might be from rppt@kernel.org are
mm-cma-simplify-cma_declare_contiguous_multi.patch
mm-fake-numa-fix-leak-of-the-distance-table-copy-on-errors.patch
mm-secretmem-disable-memfd_secret-if-secretmem_init-fails.patch
mm-cma-fix-handling-of-free-ranges-that-cross-4g-for-multi-range-areas.patch
userfaultfd-write-lock-the-vma-before-clearing-its-uffd-state.patch
userfaultfd-mark-zero-pages-moved-by-uffdio_move-soft-dirty.patch
userfaultfd-mark-thps-moved-by-uffdio_move-soft-dirty.patch
selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails.patch
hibernation-make-swsusp_page-helpers-static.patch
hibernation-ensure-secretmem-pages-dont-reach-a-snapshot.patch
hibernate-handle-potential-errors-in-hibernate_mapunmap_page.patch
hibernation-kfence-explicitly-map-unmap-kfence-pages.patch
hibernation-make-hibernation-unavailable-when-debug_pagealloc-is-on.patch
next prev parent reply other threads:[~2026-12-04 7:04 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 17:15 [PATCH v2 0/4] userfaultfd: fixes for sashiko reports Mike Rapoport (Microsoft)
2026-12-03 17:15 ` [PATCH v2 1/4] userfaultfd: write-lock the VMA before clearing its uffd state Mike Rapoport (Microsoft)
2026-12-04 7:04 ` Andrew Morton [this message]
2026-12-04 9:27 ` Jose A. Perez de Azpillaga
2026-12-03 17:15 ` [PATCH v2 2/4] userfaultfd: mark zero pages moved by UFFDIO_MOVE soft-dirty Mike Rapoport (Microsoft)
2026-12-04 7:04 ` + userfaultfd-mark-zero-pages-moved-by-uffdio_move-soft-dirty.patch added to mm-new branch Andrew Morton
2026-12-04 9:31 ` [PATCH v2 2/4] userfaultfd: mark zero pages moved by UFFDIO_MOVE soft-dirty Jose A. Perez de Azpillaga
2026-12-03 17:15 ` [PATCH v2 3/4] userfaultfd: mark THPs " Mike Rapoport (Microsoft)
2026-12-04 7:04 ` + userfaultfd-mark-thps-moved-by-uffdio_move-soft-dirty.patch added to mm-new branch Andrew Morton
2026-12-04 9:32 ` [PATCH v2 3/4] userfaultfd: mark THPs moved by UFFDIO_MOVE soft-dirty Jose A. Perez de Azpillaga
2026-12-03 17:15 ` [PATCH v2 4/4] selftests/mm: free the test context when uffd_test_ctx_init() fails Mike Rapoport (Microsoft)
2026-12-04 7:04 ` + selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails.patch added to mm-new branch Andrew Morton
2026-12-04 9:39 ` [PATCH v2 4/4] selftests/mm: free the test context when uffd_test_ctx_init() fails Jose A. Perez de Azpillaga
2026-12-05 17:09 ` Andrew Morton
2026-12-05 17:09 ` + selftests-mm-free-the-test-context-when-uffd_test_ctx_init-fails-fix.patch added to mm-new branch Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204070401.D5D6C1F000C2@smtp.kernel.org \
--to=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=mm-commits@vger.kernel.org \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.