Re: [PATCH] iommufd: reject mapping an iommufd file into an IOAS
From: Jiahao Xu
Date: Sun Nov 15 2026 - 22:39:43 EST
Agreed -- the blocklist is the wrong direction. A vfio device fd bound to
this iommufd holds an iommufd_ctx reference of its own, so it reaches the
same cycle, and any other fd type that can own an iommufd_ctx would too.
The reversal looks doable with what mm already enforces. memfd_pin_folios()
accepts only these two kinds of file:
if (!shmem_file(memfd) && !is_file_hugepages(memfd))
return -EINVAL;
and both predicates are inline helpers, so iopt_map_file_pages() can apply
the same test before the reference is taken:
if (!shmem_file(file) && !is_file_hugepages(file)) {
fput(file);
return -EINVAL;
}
with <linux/shmem_fs.h> and <linux/hugetlb.h> added to io_pagetable.c.
With that in place iopt_pages can only ever hold exactly the two kinds of
file memfd_pin_folios() is able to pin, every fd that owns an iommufd_ctx
(iommufd itself, vfio, ...) is rejected before iopt_alloc_file_pages()
runs get_file(), and the dma-buf case stays on its own branch untouched.
That is one file and about six added lines, and it makes the
iommufd_ctx_from_file() check in what I sent unnecessary.
Shall I send v2 in that form, or would you rather see the validation
somewhere else?