From: Chris Mason secretmem folios are removed from the directmap. GUP refuses secretmem VMAs for that reason, but migrate_vma_setup() hands out secretmem folios to drivers. Consequently, drivers that are not aware of this might access these folios through the directmap, resulting in a kernel page fault. For example, test_hmm copies the folio content using copy_highpage(), and nouveau and amdkfd use dma_map_page(), where swiotlb bounce buffering reads the folio through the directmap. Note that migrate_vma_pages() refuses to migrate file folios to device memory, but only after the driver already copied the folio content. Let's fix it by refusing secretmem VMAs in migrate_vma_setup(), just like GUP refuses them. This has low urgency, as it requires a driver to migrate secretmem to device memory. Fixes: 1507f51255c9 ("mm: introduce memfd_secret system call to create "secret" memory areas") Cc: stable@vger.kernel.org Signed-off-by: Chris Mason [ david: adjust description and comment ] Tested-by: Gregory Price (Meta) Reviewed-by: Gregory Price (Meta) Signed-off-by: David Hildenbrand (Arm) --- mm/migrate_device.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/migrate_device.c b/mm/migrate_device.c index a953e7acbea61..578a4419bb083 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -772,6 +773,9 @@ int migrate_vma_setup(struct migrate_vma *args) return -EINVAL; if (vma_test_single_mask(vma, VMA_SHADOW_STACK)) return -EINVAL; + /* secretmem folios have no directmap; GUP refuses them as well. */ + if (vma_is_secretmem(args->vma)) + return -EINVAL; if (nr_pages <= 0) return -EINVAL; if (args->start < vma->vm_start || args->start >= vma->vm_end) -- 2.56.1