Re: [PATCH 10/13] mm/migrate_device: refuse to migrate shadow stacks
From: Alistair Popple
Date: Wed Nov 11 2026 - 18:31:42 EST
On 2026-11-12 at 05:13 +1100, "Lorenzo Stoakes (ARM)" <ljs@xxxxxxxxxx> wrote...
> From: Chris Mason <mason@xxxxxxxxxx>
>
> The kernel blocks ordinary writes to a shadow stack. But pte_write() is
> true for a shadow stack entry, and migrate_vma_setup() sets
> MIGRATE_PFN_WRITE for each page where pte_write() is true.
Does hmm_range_fault() have a similar problem? It allows devices to mirror PTEs
into their own page tables, and AFAICT it doesn't check for shadow stack VMAs
and would see the PTEs as writeable. Thus devices would mirror the PTE into
their page tables as writeable.
This change looks good though, so:
Reviewed-by: Alistair Popple <apopple@xxxxxxxxxx>
> Notably, the nouveau GPU driver takes that flag as permission to map its
> copy of the page writable for the GPU, meaning that the next CPU access
> migrates the page back into the shadow stack, and the page then holds what
> the GPU wrote.
>
> Be consistent and disallow this for migration.
>
> Fixes: 54007f818206 ("mm: Introduce VM_SHADOW_STACK for shadow stack memory")
> Cc: <stable@xxxxxxxxxxxxxxx>
> Signed-off-by: Chris Mason <mason@xxxxxxxxxx>
> [ ljs: removed unnecessary comment, refined commit msg ]
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
> ---
> mm/migrate_device.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/mm/migrate_device.c b/mm/migrate_device.c
> index 5fe11dd01291..a59864f2e9a6 100644
> --- a/mm/migrate_device.c
> +++ b/mm/migrate_device.c
> @@ -759,6 +759,8 @@ int migrate_vma_setup(struct migrate_vma *args)
> /* The migrate_vma page walk has no hugetlb support. */
> if (!vma_is_mm_backed(vma) || vma_is_hugetlb(vma) || vma_is_dax(vma))
> return -EINVAL;
> + if (vma_test_single_mask(vma, VMA_SHADOW_STACK))
> + return -EINVAL;
> if (nr_pages <= 0)
> return -EINVAL;
> if (args->start < vma->vm_start || args->start >= vma->vm_end)
>
> --
> 2.56.0
>