Re: [PATCH] iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get()

From: Jason Gunthorpe

Date: Mon Jul 13 2026 - 12:22:29 EST


On Tue, Jul 07, 2026 at 11:06:35AM +0800, YeeLi wrote:
> From: yeeli <seven.yi.lee@xxxxxxxxx>
>
> iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get()
>
> When dma_buf_export() succeeds but dma_buf_fd() fails (e.g. -EMFILE
> from fd exhaustion), the dmabuf is leaked with no dma_buf_put() called.
>
> Reproducer: exhaust fd table near RLIMIT_NOFILE, then repeatedly call
> IOMMU_TEST_OP_DMABUF_GET — htop shows unbounded memory growth.
>
> Fix by calling dma_buf_put(dmabuf) on error and returning directly.
>
> Signed-off-by: yeeli <seven.yi.lee@xxxxxxxxx>
> ---
> drivers/iommu/iommufd/selftest.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)

Applied thanks

Jason