[PATCH v2 10/13] mm/migrate_device: refuse to migrate shadow stacks

From: Lorenzo Stoakes (ARM)

Date: Fri Nov 13 2026 - 16:47:32 EST


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.

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 ]
Reviewed-by: Alistair Popple <apopple@xxxxxxxxxx>
Reviewed-by: Balbir Singh <balbirs@xxxxxxxxxx>
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 b4660eeb975a..e0bf6afe0768 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