Re: [PATCH] mm/vma: drop mm asynchronously in vma_start_read()
From: Lorenzo Stoakes (ARM)
Date: Tue Nov 24 2026 - 13:51:34 EST
On Tue, Nov 24, 2026 at 07:35:39PM +0100, Vlastimil Babka (SUSE) wrote:
> On 11/24/26 18:49, Suren Baghdasaryan wrote:
> > On Tue, Nov 24, 2026 at 9:33 AM Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:
> >>
> >> On Tue, 24 Nov 2026 17:23:35 +0000 "Lorenzo Stoakes (ARM)" <ljs@xxxxxxxxxx> wrote:
> >>
> >> > On Tue, Nov 24, 2026 at 08:34:40AM -0800, Suren Baghdasaryan wrote:
> >> > > On Tue, Nov 24, 2026 at 8:06 AM Puranjay Mohan <puranjay12@xxxxxxxxx> wrote:
> >> > > >
> >> > > > On Tue, Nov 24, 2026 at 9:28 PM Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx> wrote:
> >> > > > >
> >> > > > > On Tue, Nov 24, 2026 at 07:51:42AM -0800, Suren Baghdasaryan wrote:
> >> > > > > > Actually, VMAs are allocated from a SLAB_TYPESAFE_BY_RCU slub. With
> >> > > > > > that RCU unlocking move you don't need other_mm copy and the comment
> >> > > > > > that comes with it. VMA won't be freed until RCU lock is dropped.
> >> > > > >
> >> > > > > Yeah but they can be reassigned? They won't be _freed_ until a grace period but
> >> > > > > they can go back to the slab and then allocated elsewhere right?
> >> > > > >
> >> > > >
> >> > > > Yes, they can go back to the slab and become a different VMA.
> >> > >
> >> > > Yeah, you are right about that. So, we either have to keep the RCU
> >> > > unlock in place to keep other_mm comment valid (my personal
> >> > > preference) or update the comment next to other_mm to explain the new
> >> > > reason it is needed. Either way is fine with me.
> >> >
> >> > I think let's just change the comment?
> >> >
> >> > Andrew could you change:
> >> >
> >> > * stable and can be freed in the narrow window after vma->vm_refcnt
> >> >
> >> > ->
> >> >
> >> > * stable and can be reused in the narrow window after vma->vm_refcnt
> >> > ^
> >> > |
> >> > just this freed -> reused :)
> >> >
> >>
> >> np.
> >>
> >> --- a/mm/mmap_lock.c~mm-vma-drop-mm-asynchronously-in-vma_start_read-fix
> >> +++ a/mm/mmap_lock.c
> >> @@ -300,7 +300,7 @@ err:
> >> err_unstable:
> >> /*
> >> * If vma got attached to another mm from under us, that mm is not
> >> - * stable and can be freed in the narrow window after vma->vm_refcnt
> >> + * stable and can be reused in the narrow window after vma->vm_refcnt
>
> But this is talking about the mm, not the vma, so the motivation to change
> that was wrong? (it's not a typesafe cache). Moreover...
>
> >> * is dropped and before rcuwait_wake_up(mm) is called. Grab it before
> >> * releasing vma->vm_refcnt.
> >> */
> >
> > Sorry for being pedantic :)
> > There is also this comment later on:
> >
> > other_mm = vma->vm_mm; /* use a copy as vma can be freed after
> > we drop vm_refcnt */
> >
> > That should be replaced too with:
> >
> > other_mm = vma->vm_mm; /* use a copy as vma can be reused
> > after we drop vm_refcnt */
> >
> > Again, just replacing "freed" to "reused".
>
> Nah let's not overthink this. It's freed back to the allocator first. Which
> naturally allows it to be reused, yes. It doesn't matter if the underlying
> page can be freed or not. UAF is a UAF.
Let me just send a v2 that puts the rcu_read_unlock() back where it was, I don't
really want to get into some long debate about nitpicky details. I just have too
much to do sorry.
--
Cheers, Lorenzo