Re: [PATCH] iommufd: reject mapping an iommufd file into an IOAS

From: Jason Gunthorpe

Date: Mon Nov 16 2026 - 20:20:04 EST


On Tue, Nov 17, 2026 at 09:13:33AM +0800, Jiahao Xu wrote:
> > And how do you let dmabuf go through?
>
> It does not reach the check, dma-bufs are taken by the branch above it.
> dma_buf_get() only succeeds for a dma-buf fd:
>
> file = fget(fd);
> if (!file)
> return ERR_PTR(-EBADF);
> if (!is_dma_buf_file(file)) {
> fput(file);
> return ERR_PTR(-EINVAL);
> }
>
> so with a dma-buf fd iopt_map_file_pages() goes through
> iopt_alloc_dmabuf_pages() and the else branch with fget() is not entered
> at all. iopt_pages keeps pages->dmabuf there, with type
> IOPT_ADDRESS_DMABUF, and never a struct file, so dma-buf mappings are
> unchanged.
>
> The shmem/hugetlb test is not a new restriction either. The file branch
> already ends in memfd_pin_folios() when the pages get pinned
>
> nfolios = memfd_pin_folios(user->file, start, end, user->ufolios,
> nfolios, &offset);
>
> and memfd_pin_folios() rejects anything that is not shmem or file-hugetlb
> with -EINVAL. The check only moves that rejection to before
> iopt_alloc_file_pages() takes the reference, which is the one thing the
> leak needs. A v2 doing exactly that compiles and passes checkpatch, I
> have it ready to send if you are happy with the shape.

OK

Jason