Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Frank Li <Frank.li@oss.nxp.com>
To: Ziheng Wei <zihengw03@163.com>
Cc: Sean Wang <sean.wang@mediatek.com>, Vinod Koul <vkoul@kernel.org>,
	Frank Li <Frank.Li@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v3 2/2] dmaengine: mediatek: mtk-cqdma: read residue under locks in tx_status
Date: Wed, 2 Dec 2026 14:33:43 -0600	[thread overview]
Message-ID: <axCAp3dZ_ggk3JdW@SMW015318> (raw)
In-Reply-To: <20261202064537.1605363-2-zihengw03@163.com>

On Wed, Dec 02, 2026 at 02:45:37PM +0800, Ziheng Wei wrote:
> mtk_cqdma_tx_status() looks up the active descriptor while holding
> cvc->pc->lock and cvc->vc.lock, then drops both locks before reading
> to_cqdma_vdesc(vd)->residue.
>
> Once the locks are released, mtk_cqdma_tasklet_cb() and vchan_complete()
> (or mtk_cqdma_terminate_all()) can concurrently update residue or free
> the descriptor, causing a use-after-free when reading cvd->residue.
>
> Read cvd->residue before releasing cvc->vc.lock and cvc->pc->lock.
>
> Found by LLM-assisted static analysis and compile-tested on x86_64.
>
> 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>
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> v2 -> v3:
> - Split out from the lookup fix into a separate patch (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 | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/dma/mediatek/mtk-cqdma.c b/drivers/dma/mediatek/mtk-cqdma.c
> index 758452c5d..1b4fb373f 100644
> --- a/drivers/dma/mediatek/mtk-cqdma.c
> +++ b/drivers/dma/mediatek/mtk-cqdma.c
> @@ -451,13 +451,12 @@ static enum dma_status mtk_cqdma_tx_status(struct dma_chan *c,
>  	spin_lock_irqsave(&cvc->pc->lock, flags);
>  	spin_lock(&cvc->vc.lock);
>  	vd = mtk_cqdma_find_active_desc(c, cookie);
> -	spin_unlock(&cvc->vc.lock);
> -	spin_unlock_irqrestore(&cvc->pc->lock, flags);
> -
>  	if (vd) {
>  		cvd = to_cqdma_vdesc(vd);
>  		bytes = cvd->residue;
>  	}
> +	spin_unlock(&cvc->vc.lock);
> +	spin_unlock_irqrestore(&cvc->pc->lock, flags);
>
>  	dma_set_residue(txstate, bytes);
>
> --
> 2.43.0
>


  reply	other threads:[~2026-12-02 20:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-12-02 20:31 ` [PATCH v3 1/2] dmaengine: mediatek: mtk-cqdma: fix active descriptor lookup " Frank Li

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=axCAp3dZ_ggk3JdW@SMW015318 \
    --to=frank.li@oss.nxp.com \
    --cc=Frank.Li@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=sean.wang@mediatek.com \
    --cc=stable@vger.kernel.org \
    --cc=vkoul@kernel.org \
    --cc=zihengw03@163.com \
    /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