Skip to contentSkip to conversation

iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get()

PATCH In review YeeLi 2 participants 2 messages Jul 7 – Jul 13

Subsystems (2)
lore
Share & tools
lore

YeeLi

author
#0 lore raw

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
index af07c642a526..7340d9f3c62b 100644
@@ -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
#1 lore raw
Quoted 10 lines · YeeLi

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.

Quoted 6 lines

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(-)

Applied thanks

Jason