From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796367842; b=0DDp/TG4Ot/6lj/XYSH+qK9eI2AlaqK2VBsvwaK5gmj6q/1VlNlWzw4VSqw6Cg4f4xKG OZJceGO51Jh9/Z7yoX/1q7dpDTtUK3gPgIYe5FxnImZVppzggNasZB8RtU6YlULI2ZNDi f7XdvwBJilOVknlTaXF0i6PF6JVQNZrQ7AaDsp8NYs1aVVtlP9iwlBomT94Q1WolEloEp U8yX60tr22gqSajHoCCBVELB7pWGGVd0Onnjm7Kf+Ylyryek7ovxqltKBE1lXdYKPL7z7 oM3TdHMuqgAop0MH3rC9LYckdOr84qPBCmkRDJ9ZbZUMvmgOiQ9ZyVPnLE0YUY9XtVA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796367842; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=KRASBazN5LbPglFgPDaMJAMZ7bF6w68DBZXmUC/Bcnk=; b=J8qdHSrbYmD9tbDmTEI93AP/j78NWuOq29grQAaGR8cBnT73tEzHnRnnWWA89AVIkQaI oTNGvo5P0PYHIoqfwf5pFxajRN3nj92x7aXA58NYotOfVgUjYR6aZc9cZnLgQ/wAG65CI v542nlhtNi0+KSmJdT5aUoEgElk092vAQJNlqX84JzIixMsqLuv2Lb0g+0TZFwy7/6Bo2 zyojXKIDI4p0+le3MB758X7zB1rZU2jL9aHuO4HN/OSL6fEqxAMCGHkoeHoGiBYdgSPe/ 892tOs5h70fjLy8Xo2WruyYJAn24hcD1I4jDyUqaOIEebJCUnHZVSPYrb3AALnld4Cw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=zeD823bN; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F22B606A322 for ; Fri, 4 Dec 2026 07:04:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=zeD823bN Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5D6C1F000C2; Fri, 4 Dec 2026 07:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796367841; bh=KRASBazN5LbPglFgPDaMJAMZ7bF6w68DBZXmUC/Bcnk=; h=Date:To:From:In-Reply-To:References:Subject; b=zeD823bNTyqIzV7TcoRQp4IpDWjbt0PJQR+mIxMb6nnF670TSC+eFuXolm4B7okUk zMYL57Gp8oLsm0qginG2FqRx50rekI0lpn0bWuYX3vBnKOngzUprdONX2vSH8o86lw TrxKH1gN8LiWvjXe12naFDRjzdqGYAAHWw64rhBE= Date: Thu, 03 Dec 2026 23:04:01 -0800 To: mm-commits@vger.kernel.org,surenb@google.com,peterx@redhat.com, david@kernel.org,rppt@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261203-fixes-uffd-sashiko-v2-1-308ce557a7b6@kernel.org> References: <20261203-fixes-uffd-sashiko-v2-1-308ce557a7b6@kernel.org> Subject: + userfaultfd-write-lock-the-vma-before-clearing-its-uffd-state.patch added to mm-new branch Message-Id: <20261204070401.D5D6C1F000C2@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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)" 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) Signed-off-by: Andrew Morton Reported-by: Sashiko Closes: https://sashiko.dev/bug/linux-5cddfd13-146a-47fc-97f8-feca4b2339b4 Reviewed-by: Suren Baghdasaryan Cc: David Hildenbrand Cc: Peter Xu 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