mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Changyul Lee <lcy8047@gmail.com>
To: Bjorn Andersson <andersson@kernel.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: linux-remoteproc@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org, Changyul Lee <lcy8047@gmail.com>
Subject: [PATCH] rpmsg: glink: hold idr_lock while completing open_ack
Date: Mon, 16 Nov 2026 22:05:09 -0500	[thread overview]
Message-ID: <20261117030509.1708983-1-lcy8047@gmail.com> (raw)

qcom_glink_rx_open_ack() looks up the channel in lcids under idr_lock,
drops the lock and then completes channel->open_ack.
qcom_glink_create_local() waits for that completion for five seconds.
If the wait times out at the same moment, it removes the lcid under
idr_lock and drops the last two references, which frees the channel.
The OPEN_ACK handler then reads channel->name for the trace event and
calls complete_all() on freed memory.

Keep idr_lock held until complete_all() returns. The timeout path
removes the lcid under the same lock before dropping its references,
so the channel cannot be freed while the lock is held. Taking a
channel reference instead would not work here, because the handler
runs in interrupt context and the final put may call
cancel_work_sync() from qcom_glink_channel_release().

Fixes: b4f8e52b89f6 ("rpmsg: Introduce Qualcomm RPM glink driver")
Signed-off-by: Changyul Lee <lcy8047@gmail.com>
---
Found with a static analysis tool we are developing.

Compile-tested only, with x86_64_defconfig plus MAILBOX, RPMSG_QCOM_GLINK_RPM
and W=1.

 drivers/rpmsg/qcom_glink_native.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c
index f848ab46161d..862565bf965d 100644
--- a/drivers/rpmsg/qcom_glink_native.c
+++ b/drivers/rpmsg/qcom_glink_native.c
@@ -1101,16 +1101,17 @@ static int qcom_glink_rx_open_ack(struct qcom_glink *glink, unsigned int lcid)
 
 	spin_lock(&glink->idr_lock);
 	channel = idr_find(&glink->lcids, lcid);
-	spin_unlock(&glink->idr_lock);
 
 	trace_qcom_glink_cmd_open_ack_rx(glink->label, channel ? channel->name : NULL,
 					 lcid, channel ? channel->rcid : 0);
 	if (!channel) {
+		spin_unlock(&glink->idr_lock);
 		dev_err(glink->dev, "Invalid open ack packet\n");
 		return -EINVAL;
 	}
 
 	complete_all(&channel->open_ack);
+	spin_unlock(&glink->idr_lock);
 
 	return 0;
 }

base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
-- 
2.43.0


                 reply	other threads:[~2026-11-17  3:05 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=20261117030509.1708983-1-lcy8047@gmail.com \
    --to=lcy8047@gmail.com \
    --cc=andersson@kernel.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=mathieu.poirier@linaro.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®