Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: Shawn Shao <shawnq1@163.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Peter Xu <peterx@redhat.com>,
	linux-mm@kvack.org
Subject: Re: [PATCH] mm/userfaultfd: validate context for range operations
Date: Thu, 3 Dec 2026 15:45:10 +0200	[thread overview]
Message-ID: <axFyZiSIJyXqFLEI@kernel.org> (raw)
In-Reply-To: <20261202131600.3164107-1-shawnq1@163.com>

Hi Shawn,

On Wed, Dec 02, 2026 at 01:16:00PM +0000, Shawn Shao wrote:
> Hello,
>
> userfaultfd range operations locate destination VMAs through ctx->mm, but
> they do not consistently verify that the VMA is registered through the
> context issuing the operation. A fill or protection operation can therefore
> cross the VMA's context boundary and can route a fault wakeup through a
> different context.

What is the actual problem? Operations on a range registered with another
userfaultfd of the same mm were allowed from the beginning, the check that
the range is registered was there to catch userspace errors (see the
comment c1a4de99fada added to __mcopy_atomic()).

The only real issue with that I'm aware of is a race between close() of a
userfaultfd and UFFDIO_COPY on another userfaultfd, and it's fixed by
write-locking the VMA before clearing the uffd state:

https://lore.kernel.org/all/20261202-fixes-uffd-sashiko-v1-0-a6f5a874334a@kernel.org

If you see something else that breaks, please describe in the changelog
what happens, how it can be triggered and what is the effect.

And making such operations fail with -ENOENT is a user visible change,
the changelog should say so and explain why it's safe.

> Require an exact context match in the shared fill validation and in the
> write-protect and read-write-protect range walks. Keep the same validation
> on the hugetlb fill retry path.
>
> HEAD commit:    693c2e04e3f1d4c59af236e1211b7b8cb165a790
> git tree:       c2ddff65ad678839e4004d5e4f7f5d28aadd0e80
> source version: Linux 7.4.0-rc5
> architecture:   x86-64
> compiler:       gcc 11.4.0, GNU ld 2.38
>
> The issue reproduces on Linux 7.4.0-rc4 at commit
> 7cd8495c0f16275c4f9abe1cef09a7b5fcd6d046, with git tree
> 194227446ae61b4971eea1b7bed06856fe3cc477. The affected code is present in
> the HEAD revision above. The patch was built and tested on that revision.
>
> A source reproducer and positive/control results are available for private
> review.

None of this belongs in a changelog. If the reproducer triggers a bug,
describe what it does and what it shows.

> Fixes: 86039bd3b4e6 ("userfaultfd: add new syscall to provide memory externalization")
> Fixes: ffd05793963a ("userfaultfd: wp: support write protection for userfault vma range")
> Fixes: 6eab8f2cc646 ("userfaultfd: add UFFDIO_REGISTER_MODE_RWP and UFFDIO_RWPROTECT plumbing")

I doubt these are accurate.

-- 
Sincerely yours,
Mike.


      parent reply	other threads:[~2026-12-03 13:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 13:16 [PATCH] mm/userfaultfd: validate context for range operations Shawn Shao
2026-12-03 13:26 ` sashiko-bot
2026-12-03 13:45 ` Mike Rapoport [this message]

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=axFyZiSIJyXqFLEI@kernel.org \
    --to=rppt@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=shawnq1@163.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