Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/2] dmaengine: mediatek: mtk-cqdma: fix active descriptor lookup in tx_status
@ 2026-12-02  6:45 Ziheng Wei
  2026-12-02  6:45 ` [PATCH v3 2/2] dmaengine: mediatek: mtk-cqdma: read residue under locks " Ziheng Wei
  2026-12-02 20:31 ` [PATCH v3 1/2] dmaengine: mediatek: mtk-cqdma: fix active descriptor lookup " Frank Li
  0 siblings, 2 replies; 4+ messages in thread
From: Ziheng Wei @ 2026-12-02  6:45 UTC (permalink / raw)
  To: Sean Wang, Vinod Koul
  Cc: Frank Li, Frank Li, Matthias Brugger, AngeloGioacchino Del Regno,
	dmaengine, linux-arm-kernel, linux-mediatek, linux-kernel, stable

mtk_cqdma_issue_vchan_pending() links active descriptors onto pc->queue
via struct mtk_cqdma_vdesc::node, whereas mtk_cqdma_find_active_desc()
walks pc->queue using struct virt_dma_desc::node.

Because the recovered pointer is shifted inside struct mtk_cqdma_vdesc,
vd->tx.cookie reads an unrelated field instead of the descriptor cookie.
In typical runs this fails to match cookie so mtk_cqdma_find_active_desc()
returns NULL and mtk_cqdma_tx_status() silently reports zero residue,
which hid the bug; if the misread field happens to match cookie,
to_cqdma_vdesc(vd)->residue reads past the end of the allocation.

In addition, multiple virtual channels share pc->queue and maintain
independent per-channel cookies, so scanning pc->queue without checking
cvd->ch == c can match another virtual channel's active descriptor.

Walk pc->queue as struct mtk_cqdma_vdesc and check cvd->ch == c.

Found by LLM-assisted static analysis and runtime-tested in QEMU+KASAN
(slab-out-of-bounds before the fix; 0 KASAN findings after).

Fixes: b1f01e48df5a ("dmaengine: mediatek: Add MediaTek Command-Queue DMA controller for MT6765 SoC")
Cc: stable@vger.kernel.org
Signed-off-by: Ziheng Wei <zihengw03@163.com>
---
v2 -> v3:
- Split the lookup fix and locking fix into two patches (Frank Li).
- Explain why the wrong list entry type went unnoticed previously
  (Frank Li).

v2: https://lore.kernel.org/r/20261130134245.1412154-1-zihengw03@163.com
v1: https://lore.kernel.org/r/20261130103317.1383850-1-zihengw03@163.com

 drivers/dma/mediatek/mtk-cqdma.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/mediatek/mtk-cqdma.c b/drivers/dma/mediatek/mtk-cqdma.c
index a7000608d..758452c5d 100644
--- a/drivers/dma/mediatek/mtk-cqdma.c
+++ b/drivers/dma/mediatek/mtk-cqdma.c
@@ -419,12 +419,12 @@ static struct virt_dma_desc *mtk_cqdma_find_active_desc(struct dma_chan *c,
 							dma_cookie_t cookie)
 {
 	struct mtk_cqdma_vchan *cvc = to_cqdma_vchan(c);
+	struct mtk_cqdma_vdesc *cvd;
 	struct virt_dma_desc *vd;
 
-	list_for_each_entry(vd, &cvc->pc->queue, node)
-		if (vd->tx.cookie == cookie) {
-			return vd;
-		}
+	list_for_each_entry(cvd, &cvc->pc->queue, node)
+		if (cvd->ch == c && cvd->vd.tx.cookie == cookie)
+			return &cvd->vd;
 
 	list_for_each_entry(vd, &cvc->vc.desc_issued, node)
 		if (vd->tx.cookie == cookie)

base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
-- 
2.43.0



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

end of thread, other threads:[~2026-12-02 20:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02  6:45 [PATCH v3 1/2] dmaengine: mediatek: mtk-cqdma: fix active descriptor lookup in tx_status Ziheng Wei
2026-12-02  6:45 ` [PATCH v3 2/2] dmaengine: mediatek: mtk-cqdma: read residue under locks " Ziheng Wei
2026-12-02 20:33   ` Frank Li
2026-12-02 20:31 ` [PATCH v3 1/2] dmaengine: mediatek: mtk-cqdma: fix active descriptor lookup " Frank Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox