* [PATCH] iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get()
@ 2026-07-07 3:06 YeeLi
2026-07-13 16:16 ` Jason Gunthorpe
0 siblings, 1 reply; 2+ messages in thread
From: YeeLi @ 2026-07-07 3:06 UTC (permalink / raw)
To: jgg, kevin.tian, joro, will, robin.murphy; +Cc: iommu, linux-kernel, yeeli
From: yeeli <seven.yi.lee@gmail.com>
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@gmail.com>
---
drivers/iommu/iommufd/selftest.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index af07c642a526..7340d9f3c62b 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -2023,7 +2023,12 @@ static int iommufd_test_dmabuf_get(struct iommufd_ucmd *ucmd,
goto err_free;
}
- return dma_buf_fd(dmabuf, open_flags);
+ rc = dma_buf_fd(dmabuf, open_flags);
+ if (rc < 0) {
+ dma_buf_put(dmabuf);
+ return rc;
+ }
+ return rc;
err_free:
kfree(priv->memory);
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get()
2026-07-07 3:06 [PATCH] iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get() YeeLi
@ 2026-07-13 16:16 ` Jason Gunthorpe
0 siblings, 0 replies; 2+ messages in thread
From: Jason Gunthorpe @ 2026-07-13 16:16 UTC (permalink / raw)
To: YeeLi; +Cc: kevin.tian, joro, will, robin.murphy, iommu, linux-kernel
On Tue, Jul 07, 2026 at 11:06:35AM +0800, YeeLi wrote:
> From: yeeli <seven.yi.lee@gmail.com>
>
> 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@gmail.com>
> ---
> drivers/iommu/iommufd/selftest.c | 7 ++++++-
> 1 file changed, 6 insertions(+), 1 deletion(-)
Applied thanks
Jason
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-13 16:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-07 3:06 [PATCH] iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get() YeeLi
2026-07-13 16:16 ` Jason Gunthorpe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox