From: Mike Rapoport <rppt@kernel.org>
To: Umang Pokhriyal <umangpokhriyall@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Peter Xu <peterx@redhat.com>,
David Hildenbrand <david@kernel.org>,
Lorenzo Stoakes <ljs@kernel.org>,
"Liam R . Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>, Shuah Khan <shuah@kernel.org>,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 1/2] userfaultfd: validate the whole range before changing write protection
Date: Tue, 3 Nov 2026 20:54:17 +0200 [thread overview]
Message-ID: <auot2ZVM5YjyFlZZ@kernel.org> (raw)
In-Reply-To: <20261102103621.156928-2-umangpokhriyall@gmail.com>
On Mon, Nov 02, 2026 at 04:06:20PM +0530, Umang Pokhriyal wrote:
> mwriteprotect_range() checks each VMA as it walks the range. When a later
> VMA is not registered for write protection, or is a hugetlb VMA the range
> is not aligned to, the call fails after the earlier VMAs were already
> changed. When unprotecting, userfaultfd_writeprotect() then skips
> wake_userfault(), so threads blocked on those pages are not woken although
> the pages are writable again.
>
> An unprivileged process can trigger this with a range that spans an
> unregistered VMA. It hasn't been seen in practice; it was found while
> reviewing the userfaultfd range ioctls with an LLM.
>
> Validate the whole range first, as mrwprotect_range() already does.
>
> Fixes: a1b92a3f1498 ("mm/userfaultfd: support WP on multiple VMAs")
> Cc: stable@vger.kernel.org
> Signed-off-by: Umang Pokhriyal <umangpokhriyall@gmail.com>
> ---
> mm/userfaultfd.c | 20 +++++++++++++++-----
> 1 file changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c
> index 87da92526..b8a9d9574 100644
> --- a/mm/userfaultfd.c
> +++ b/mm/userfaultfd.c
> @@ -1105,21 +1105,31 @@ static int mwriteprotect_range(struct userfaultfd_ctx *ctx, unsigned long start,
> if (atomic_read(&ctx->mmap_changing))
> goto out_unlock;
>
> + /*
> + * Validate every spanned VMA before changing any of them, so an
> + * invalid range is rejected without changing part of it.
> + */
> err = -ENOENT;
Nit: this assignment is now redundant, isn't it?
> for_each_vma_range(vmi, dst_vma, end) {
> -
> if (!userfaultfd_wp(dst_vma)) {
> err = -ENOENT;
> - break;
> + goto out_unlock;
> }
>
> if (vma_is_hugetlb(dst_vma)) {
> - err = -EINVAL;
Same here.
> page_mask = vma_kernel_pagesize(dst_vma) - 1;
> - if ((start & page_mask) || (len & page_mask))
> - break;
> + if ((start & page_mask) || (len & page_mask)) {
> + err = -EINVAL;
> + goto out_unlock;
> + }
> }
> + err = 0;
> + }
> + if (err)
> + goto out_unlock;
If we a breaking on any error to out_unlock, why do we need err = 0 and
this check?
>
> + vma_iter_set(&vmi, start);
> + for_each_vma_range(vmi, dst_vma, end) {
> _start = max(dst_vma->vm_start, start);
> _end = min(dst_vma->vm_end, end);
>
> --
> 2.53.0
>
--
Sincerely yours,
Mike.
next prev parent reply other threads:[~2026-11-03 18:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 10:36 [PATCH 0/2] " Umang Pokhriyal
2026-11-02 10:36 ` [PATCH 1/2] " Umang Pokhriyal
2026-11-03 18:54 ` Mike Rapoport [this message]
2026-11-02 10:36 ` [PATCH 2/2] selftests/mm: test a uffd write-protect range with an unregistered page Umang Pokhriyal
2026-11-03 19:05 ` Mike Rapoport
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=auot2ZVM5YjyFlZZ@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=david@kernel.org \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=peterx@redhat.com \
--cc=shuah@kernel.org \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=umangpokhriyall@gmail.com \
--cc=vbabka@kernel.org \
/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
all inboxes | Powered by JetHome®