iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get()
PATCH 1/1 iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get()
From: yeeli <[email protected]>
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.
--- drivers/iommu/iommufd/selftest.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/iommu/iommufd/selftest.c +6 -1
@@ -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);
Signature · 1 line
2.34.1
Quoted 10 lines · YeeLi
From: yeeli <[email protected]>
iommufd/selftest: Fix dmabuf leak in
iommufd_test_dmabuf_get()When
dma_buf_export()succeeds butdma_buf_fd()fails (e.g.-EMFILEfrom fd exhaustion), the dmabuf is leaked with nodma_buf_put()called.Reproducer: exhaust fd table near
RLIMIT_NOFILE, then repeatedly callIOMMU_TEST_OP_DMABUF_GET— htop shows unbounded memory growth.
Quoted 6 lines
Fix by calling
dma_buf_put(dmabuf)on error and returning directly.Signed-off-by yeeli <[email protected]>--- drivers/iommu/iommufd/selftest.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Applied thanks
Jason