Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	David Hildenbrand <david@kernel.org>,
	Jann Horn <jannh@google.com>,
	Noah Weinberger <NoahWeinberger2003@proton.me>,
	Pedro Falcato <pfalcato@suse.de>, Peter Xu <peterx@redhat.com>,
	Vlastimil Babka <vbabka@kernel.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] mm/vma: undo userfaultfd unmap preparation when unmapping fails
Date: Wed, 2 Dec 2026 09:12:16 +0200	[thread overview]
Message-ID: <aw_E0GrHvFiXj_by@kernel.org> (raw)
In-Reply-To: <aw7cP2X55GmrAO9U@gremlin>

On Tue, Dec 01, 2026 at 02:56:49PM +0000, Lorenzo Stoakes (ARM) wrote:
> On Sun, Nov 01, 2026 at 10:24:02AM +0200, Mike Rapoport (Microsoft) wrote:
> > vms_gather_munmap_vmas() collects VMAs to unmap and calls
> > userfaultfd_unmap_prep() for each of these VMAs. This takes a reference
> > to the userfaultfd context, raises ctx->mmap_changing and queues an
> > UFFD_EVENT_UNMAP on the caller's list.
> >
> > If gathering fails half way, e.g. because one of the VMAs is sealed, or
> > the operation fails after the VMAs were gathered, the original mappings
> > stay intact but the queued events remain on the list.
> >
> > Depending on the caller they are either delivered although nothing was
> > unmapped (munmap(), mremap(), mmap(MAP_FIXED)), or silently dropped
> > (brk()). In the latter case the userfaultfd context and the mm_struct it
> > pins are leaked and mmap_changing is never lowered, so UFFDIO_COPY,
> > UFFDIO_ZEROPAGE and all other ioctls that check mmap_changing fail with
> > -EAGAIN forever.
> >
> > With mseal() this is trivially triggered by an unprivileged process.
> 
> Great... :)
> 
> >
> > Collect the events in do_vmi_align_munmap() on a local list and splice
> > it to the caller's list only when the unmap completes, because mremap()
> > may already have events for earlier unmaps on that list.
> >
> > Drop the pending events with a new userfaultfd_unmap_abort() helper when
> > do_vmi_align_munmap() or __mmap_setup() fail.
> >
> > Fixes: 65ac132027a88 ("userfaultfd: fix regression in userfaultfd_unmap_prep()")
> > Reported-by: Noah Weinberger <NoahWeinberger2003@proton.me>
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> 
> Ahem. I see this got merged already without any input from VMA people :)
> 
> The AI slop wave is making the workload nearly unmanageable, so it's easy
> to miss stuff, you are welcome to nag though.
> 
> This gets fixed next cycle when the VMA tree becomes independent, but let's
> try to avoid this for the remainder of the cycle please!
> 
> I wonder if we could have avoided propagating this terrible linked list
> stuff here. But ah well, too late.

Believe me, I tried :)
 
> Maybe not possible for a backport but would have been good to explore at
> least!

Maybe with vm_uffd_state in VMA, but that's a long shot.
 
> --
> Cheers, Lorenzo

-- 
Sincerely yours,
Mike.

      reply	other threads:[~2026-12-02  7:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-01  8:24 [PATCH] mm/vma: undo userfaultfd unmap preparation when unmapping fails Mike Rapoport (Microsoft)
2026-11-01 13:54 ` Tal Zussman
2026-12-01 14:56 ` Lorenzo Stoakes (ARM)
2026-12-02  7:12   ` 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=aw_E0GrHvFiXj_by@kernel.org \
    --to=rppt@kernel.org \
    --cc=NoahWeinberger2003@proton.me \
    --cc=akpm@linux-foundation.org \
    --cc=david@kernel.org \
    --cc=jannh@google.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=peterx@redhat.com \
    --cc=pfalcato@suse.de \
    --cc=stable@vger.kernel.org \
    --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