From: Yuho Choi <dbgh9129@gmail.com>
To: Vinicius Costa Gomes <vinicius.gomes@intel.com>,
Vinod Koul <vkoul@kernel.org>
Cc: Dave Jiang <dave.jiang@intel.com>, Frank Li <Frank.Li@kernel.org>,
dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
Yuho Choi <dbgh9129@gmail.com>
Subject: [PATCH v1] dmaengine: idxd: fix deadlock and double free in idxd_cdev_open()
Date: Thu, 16 Apr 2026 18:19:57 -0400 [thread overview]
Message-ID: <20260416221957.51250-1-dbgh9129@gmail.com> (raw)
The failed_dev_add and failed_dev_name error paths in idxd_cdev_open()
call put_device(fdev) while still holding wq->wq_lock. This triggers
idxd_file_dev_release() synchronously, which calls
mutex_lock(&wq->wq_lock) — deadlocking on the same mutex.
Additionally, the original code fell through from failed_dev_add and
failed_dev_name to the failed: label, which called kfree(ctx) a second
time after idxd_file_dev_release() had already freed it. The subsequent
idxd_xa_pasid_remove(ctx) then uses the freed pointer.
Fix both issues by releasing wq_lock before put_device(fdev) and
returning immediately, so the release callback acquires the lock without
contention and no further cleanup is attempted on the freed context.
Fixes: e6fd6d7e5f0fe ("dmaengine: idxd: add a device to represent the file opened")
Signed-off-by: Yuho Choi <dbgh9129@gmail.com>
---
drivers/dma/idxd/cdev.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/dma/idxd/cdev.c b/drivers/dma/idxd/cdev.c
index 0366c7cf35020..19a449333782b 100644
--- a/drivers/dma/idxd/cdev.c
+++ b/drivers/dma/idxd/cdev.c
@@ -307,7 +307,9 @@ static int idxd_cdev_open(struct inode *inode, struct file *filp)
failed_dev_add:
failed_dev_name:
+ mutex_unlock(&wq->wq_lock);
put_device(fdev);
+ return rc;
failed_ida:
failed_set_pasid:
if (device_user_pasid_enabled(idxd))
--
2.50.1 (Apple Git-155)
reply other threads:[~2026-04-16 22:20 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260416221957.51250-1-dbgh9129@gmail.com \
--to=dbgh9129@gmail.com \
--cc=Frank.Li@kernel.org \
--cc=dave.jiang@intel.com \
--cc=dmaengine@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vinicius.gomes@intel.com \
--cc=vkoul@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