Re: [PATCH 09/13] mm/migrate_device: fix use-after-free of the anon rmap

From: Alistair Popple

Date: Sun Nov 15 2026 - 18:21:55 EST


On 2026-11-13 at 06:05 +1100, "Lorenzo Stoakes (ARM)" <ljs@xxxxxxxxxx> wrote...
> On Thu, Nov 12, 2026 at 10:04:10AM +1100, Alistair Popple wrote:
> > > Resolve this by pinning the anon rmap of each folio which possesses one in
> > > migrate_device_range(), migrate_device_pfns() and
> > > migrate_device_coherent_folio() before its PTEs are replaced, and
> > > unpinning it once the walk is done.
> >
> > I was going to ask why this wouldn't also be an issue for migrate_vma_setup()
> > which does something similar. But in that case mmap_lock is held across setup
> > and finalize which I guess is what saves us there?
>
> Yeah, exactly.

Good. That confirms my understanding so:

Reviewed-by: Alistair Popple <apopple@xxxxxxxxxx>

> --
> Cheers, Lorenzo