From: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>
To: "Mike Rapoport (Microsoft)" <rppt@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@kernel.org>
Cc: Peter Xu <peterx@redhat.com>,
Suren Baghdasaryan <surenb@google.com>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
linux-mm@kvack.org, Sashiko <sashiko-bot@kernel.org>
Subject: Re: [PATCH v2 1/4] userfaultfd: write-lock the VMA before clearing its uffd state
Date: Fri, 4 Dec 2026 10:27:30 +0100 [thread overview]
Message-ID: <e9d8b6fa-0940-4abf-b81d-b649dfa65706@gmail.com> (raw)
In-Reply-To: <20261203-fixes-uffd-sashiko-v2-1-308ce557a7b6@kernel.org>
On 12/3/26 6:15 PM, Mike Rapoport (Microsoft) wrote:
> 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.
>
> Reported-by: Sashiko <sashiko-bot@kernel.org>
> Closes: https://sashiko.dev/bug/linux-5cddfd13-146a-47fc-97f8-feca4b2339b4
> Fixes: c88033efe9a3 ("mm/userfaultfd: reset ptes when close() for wr-protected ones")
> Reviewed-by: Suren Baghdasaryan <surenb@google.com>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
LGTM:
Reviewed-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
--
cheers,
jose a. p-a
next prev parent reply other threads:[~2026-12-04 9:27 UTC|newest]
Thread overview: 6+ 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 9:27 ` Jose A. Perez de Azpillaga [this message]
2026-12-03 17:15 ` [PATCH v2 2/4] userfaultfd: mark zero pages moved by UFFDIO_MOVE soft-dirty Mike Rapoport (Microsoft)
2026-12-03 17:15 ` [PATCH v2 3/4] userfaultfd: mark THPs " Mike Rapoport (Microsoft)
2026-12-03 17:15 ` [PATCH v2 4/4] selftests/mm: free the test context when uffd_test_ctx_init() fails Mike Rapoport (Microsoft)
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=e9d8b6fa-0940-4abf-b81d-b649dfa65706@gmail.com \
--to=azpijr@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=peterx@redhat.com \
--cc=rppt@kernel.org \
--cc=sashiko-bot@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox