From: srini@kernel.org
To: gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, Changyul Lee <lcy8047@gmail.com>,
Srinivas Kandagatla <srini@kernel.org>
Subject: [PATCH 1/2] slimbus: messaging: hold lock until transaction is completed
Date: Tue, 1 Dec 2026 23:28:14 +0000 [thread overview]
Message-ID: <20261201232815.537957-2-srini@kernel.org> (raw)
In-Reply-To: <20261201232815.537957-1-srini@kernel.org>
From: Changyul Lee <lcy8047@gmail.com>
slim_msg_response() releases ctrl->txn_lock right after idr_find()
and then uses txn. If the request times out in the meantime, it
returns, and txn is no longer valid.
Keep ctrl->txn_lock held until complete() returns, so the timeout
path in slim_free_txn_tid() waits until slim_msg_response() is done
with txn. Call idr_remove() directly, since slim_free_txn_tid() takes
the same lock.
Tested on v7.3 with a delay after idr_find(), in QEMU with KASAN
and on a DragonBoard 845c. Without this patch, both reproduced the
use-after-free in slim_msg_response(). With this patch, neither did.
Fixes: afbdcc7c384b ("slimbus: Add messaging APIs to slimbus framework")
Assisted-by: LLM
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
drivers/slimbus/messaging.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/drivers/slimbus/messaging.c b/drivers/slimbus/messaging.c
index ee127ef42046..28a029623059 100644
--- a/drivers/slimbus/messaging.c
+++ b/drivers/slimbus/messaging.c
@@ -29,22 +29,24 @@ void slim_msg_response(struct slim_controller *ctrl, u8 *reply, u8 tid, u8 len)
spin_lock_irqsave(&ctrl->txn_lock, flags);
txn = idr_find(&ctrl->tid_idr, tid);
- spin_unlock_irqrestore(&ctrl->txn_lock, flags);
-
- if (txn == NULL)
+ if (txn == NULL) {
+ spin_unlock_irqrestore(&ctrl->txn_lock, flags);
return;
+ }
msg = txn->msg;
if (msg == NULL || msg->rbuf == NULL) {
+ spin_unlock_irqrestore(&ctrl->txn_lock, flags);
dev_err(ctrl->dev, "Got response to invalid TID:%d, len:%d\n",
tid, len);
return;
}
- slim_free_txn_tid(ctrl, txn);
+ idr_remove(&ctrl->tid_idr, txn->tid);
memcpy(msg->rbuf, reply, len);
if (txn->comp)
complete(txn->comp);
+ spin_unlock_irqrestore(&ctrl->txn_lock, flags);
/* Remove runtime-pm vote now that response was received for TID txn */
pm_runtime_mark_last_busy(ctrl->dev);
--
2.53.0
next prev parent reply other threads:[~2026-12-01 23:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 23:28 [PATCH 0/2] slimbus: fixes for v7.4 srini
2026-12-01 23:28 ` srini [this message]
2026-12-01 23:28 ` [PATCH 2/2] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown srini
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=20261201232815.537957-2-srini@kernel.org \
--to=srini@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=lcy8047@gmail.com \
--cc=linux-kernel@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.