mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] slimbus: fixes for v7.4
@ 2026-12-01 23:28 srini
  2026-12-01 23:28 ` [PATCH 1/2] slimbus: messaging: hold lock until transaction is completed srini
  2026-12-01 23:28 ` [PATCH 2/2] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown srini
  0 siblings, 2 replies; 3+ messages in thread
From: srini @ 2026-12-01 23:28 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Srinivas Kandagatla

From: Srinivas Kandagatla <srini@kernel.org>

Hi Greg,

Here are few slimbus fixes for v7.4, Could you please queue these for v7.4.
The branch is based on char-misc-linus.

Patches include
	- slimbus messaging fix to hold the lock until the transaction
	  is completed.
	- qcom-ngd-ctrl fix for potential DMA buffer leaks on teardown.

Thanks,
Srini

Changyul Lee (1):
  slimbus: messaging: hold lock until transaction is completed

Guangshuo Li (1):
  slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown

 drivers/slimbus/messaging.c     | 10 ++++++----
 drivers/slimbus/qcom-ngd-ctrl.c | 12 ++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)


base-commit: 89f33682b2c34b12b3a7a549ba94a808f0c7c98d
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] slimbus: messaging: hold lock until transaction is completed
  2026-12-01 23:28 [PATCH 0/2] slimbus: fixes for v7.4 srini
@ 2026-12-01 23:28 ` srini
  2026-12-01 23:28 ` [PATCH 2/2] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown srini
  1 sibling, 0 replies; 3+ messages in thread
From: srini @ 2026-12-01 23:28 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Changyul Lee, Srinivas Kandagatla

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown
  2026-12-01 23:28 [PATCH 0/2] slimbus: fixes for v7.4 srini
  2026-12-01 23:28 ` [PATCH 1/2] slimbus: messaging: hold lock until transaction is completed srini
@ 2026-12-01 23:28 ` srini
  1 sibling, 0 replies; 3+ messages in thread
From: srini @ 2026-12-01 23:28 UTC (permalink / raw)
  To: gregkh; +Cc: linux-kernel, Guangshuo Li, stable, Srinivas Kandagatla

From: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>

DMA teardown terminates transfers and releases the channels but leaves
the coherent message buffers allocated. A subsequent initialization
overwrites their addresses, and removal loses them permanently.

Free the buffers after terminating DMA. Clear channels released during
initialization failure so teardown cannot free the same resources again.

This issue was found by our static analysis tool under development.

Fixes: 917809e2280b ("slimbus: ngd: Add qcom SLIMBus NGD driver")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <liguangshuo@mail.sdu.edu.cn>
Signed-off-by: Srinivas Kandagatla <srini@kernel.org>
---
 drivers/slimbus/qcom-ngd-ctrl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/slimbus/qcom-ngd-ctrl.c b/drivers/slimbus/qcom-ngd-ctrl.c
index 8da75c4b50e5..a29e57303046 100644
--- a/drivers/slimbus/qcom-ngd-ctrl.c
+++ b/drivers/slimbus/qcom-ngd-ctrl.c
@@ -706,9 +706,12 @@ static int qcom_slim_ngd_init_rx_msgq(struct qcom_slim_ngd_ctrl *ctrl)
 	return 0;
 
 rx_post_err:
+	dmaengine_terminate_sync(ctrl->dma_rx_channel);
 	dma_free_coherent(dev, size, ctrl->rx_base, ctrl->rx_phys_base);
+	ctrl->rx_base = NULL;
 rel_rx:
 	dma_release_channel(ctrl->dma_rx_channel);
+	ctrl->dma_rx_channel = NULL;
 	return ret;
 }
 
@@ -743,6 +746,7 @@ static int qcom_slim_ngd_init_tx_msgq(struct qcom_slim_ngd_ctrl *ctrl)
 	return 0;
 rel_tx:
 	dma_release_channel(ctrl->dma_tx_channel);
+	ctrl->dma_tx_channel = NULL;
 	return ret;
 }
 
@@ -1210,11 +1214,19 @@ static int qcom_slim_ngd_exit_dma(struct qcom_slim_ngd_ctrl *ctrl)
 {
 	if (ctrl->dma_rx_channel) {
 		dmaengine_terminate_sync(ctrl->dma_rx_channel);
+		dma_free_coherent(ctrl->dev,
+				  QCOM_SLIM_NGD_DESC_NUM * SLIM_MSGQ_BUF_LEN,
+				  ctrl->rx_base, ctrl->rx_phys_base);
+		ctrl->rx_base = NULL;
 		dma_release_channel(ctrl->dma_rx_channel);
 	}
 
 	if (ctrl->dma_tx_channel) {
 		dmaengine_terminate_sync(ctrl->dma_tx_channel);
+		dma_free_coherent(ctrl->dev,
+				  (QCOM_SLIM_NGD_DESC_NUM + 1) * SLIM_MSGQ_BUF_LEN,
+				  ctrl->tx_base, ctrl->tx_phys_base);
+		ctrl->tx_base = NULL;
 		dma_release_channel(ctrl->dma_tx_channel);
 	}
 
-- 
2.53.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-01 23:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 23:28 [PATCH 0/2] slimbus: fixes for v7.4 srini
2026-12-01 23:28 ` [PATCH 1/2] slimbus: messaging: hold lock until transaction is completed srini
2026-12-01 23:28 ` [PATCH 2/2] slimbus: qcom-ngd-ctrl: Fix potential DMA buffer leaks on teardown srini

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®