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

From: Lorenzo Stoakes (ARM)

Date: Thu Nov 12 2026 - 14:59:19 EST


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.

--
Cheers, Lorenzo