mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: YeeLi <seven.yi.lee@gmail.com>
To: jgg@ziepe.ca, kevin.tian@intel.com, joro@8bytes.org,
	will@kernel.org, robin.murphy@arm.com
Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
	yeeli <seven.yi.lee@gmail.com>
Subject: [PATCH] iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get()
Date: Tue,  7 Jul 2026 11:06:35 +0800	[thread overview]
Message-ID: <20260707030635.221577-1-seven.yi.lee@gmail.com> (raw)

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


             reply	other threads:[~2026-07-07  3:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07  3:06 YeeLi [this message]
2026-07-13 16:16 ` Jason Gunthorpe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260707030635.221577-1-seven.yi.lee@gmail.com \
    --to=seven.yi.lee@gmail.com \
    --cc=iommu@lists.linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=joro@8bytes.org \
    --cc=kevin.tian@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®