All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Suyuan Wang" <shyckless@gmail.com>
Cc: dmaengine@vger.kernel.org, vkoul@kernel.org, Frank.Li@kernel.org
Subject: Re: [PATCH 1/2] dmaengine: at_xdmac: Kill the channel tasklets in remove again
Date: Mon, 23 Nov 2026 01:09:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-228507@kernel.org> (raw)
In-Reply-To: <20261123-dma-chancnt-v1-1-f0eea0a4bb63@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] dmaengine: at_xdmac: chan_dev UAF and unclocked MMIO in
  at_xdmac_remove()
--

commit d1b41bac9406538e5524be5f60b8b97177c4c118
Author: Suyuan Wang <stevewong@hust.edu.cn>

dmaengine: at_xdmac: Kill the channel tasklets in remove again

This commit saves atxdmac->dma.chancnt before dma_async_device_unregister()
decrements it to zero so the per-channel tasklet cleanup loop in
at_xdmac_remove() runs again.

> diff --git a/drivers/dma/at_xdmac.c b/drivers/dma/at_xdmac.c
> index ef0dfe9d37ba3..ef4012c225730 100644
> --- a/drivers/dma/at_xdmac.c
> +++ b/drivers/dma/at_xdmac.c
> @@ -2436,6 +2436,8 @@ static int at_xdmac_probe(struct platform_device *pdev)
>  static void at_xdmac_remove(struct platform_device *pdev)
>  {
>  	struct at_xdmac	*atxdmac = (struct at_xdmac *)platform_get_drvdata(pdev);
> +	/* dma_async_device_unregister() decrements dma.chancnt to 0 */
> +	int		nr_channels = atxdmac->dma.chancnt;
>  	int		i;
>  
>  	at_xdmac_off(atxdmac, true);
> @@ -2448,7 +2450,7 @@ static void at_xdmac_remove(struct platform_device *pdev)
>  
>  	free_irq(atxdmac->irq, atxdmac);
>  
> -	for (i = 0; i < atxdmac->dma.chancnt; i++) {
> +	for (i = 0; i < nr_channels; i++) {
>  		struct at_xdmac_chan *atchan = &atxdmac->chan[i];
>  
>  		tasklet_kill(&atchan->tasklet);

[Severity: Medium]
Does re-enabling this loop after dma_async_device_unregister() cause
at_xdmac_free_chan_resources() to dereference a freed chan->chan_dev?

dma_async_device_unregister() unregisters each channel device, triggering
chan_dev_release() -> kfree(chan_dev) and leaving chan->chan_dev dangling.
When the loop below runs at_xdmac_free_chan_resources(&atchan->chan) with a
non-empty free_descs_list, it passes dmaengine_chan_dev(chan)
(&chan->chan_dev->device) to dev_dbg(), which is a use-after-free:

drivers/dma/at_xdmac.c:at_xdmac_free_chan_resources() {
    ...
	list_for_each_entry_safe(desc, _desc, &atchan->free_descs_list, desc_node) {
		dev_dbg(dmaengine_chan_dev(chan), "%s: freeing descriptor %p\n", __func__, desc);
		list_del(&desc->desc_node);
		dma_pool_free(atxdmac->at_xdmac_desc_pool, desc, desc->tx_dma_desc.phys);
	}
    ...
}

In addition, because free_irq() and tasklet_kill() run after
dma_async_device_unregister() and clk_disable_unprepare(), an in-flight
interrupt or scheduled tasklet can also dereference the freed chan->chan_dev
and access XDMAC MMIO registers after the controller clock has been disabled.
Should free_irq(), tasklet_kill(), and at_xdmac_free_chan_resources() run
before dma_async_device_unregister() and clk_disable_unprepare()?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-dma-chancnt-v1-0-f0eea0a4bb63@gmail.com?part=1

  reply	other threads:[~2026-11-23  1:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  0:53 [PATCH 0/2] dmaengine: Kill channel tasklets in remove again Suyuan Wang
2026-11-23  0:53 ` Suyuan Wang via B4 Relay
2026-11-23  0:53 ` [PATCH 1/2] dmaengine: at_xdmac: Kill the " Suyuan Wang
2026-11-23  0:53   ` Suyuan Wang via B4 Relay
2026-11-23  1:09   ` sashiko-bot [this message]
2026-11-23  0:53 ` [PATCH 2/2] dmaengine: idma64: " Suyuan Wang
2026-11-23  0:53   ` Suyuan Wang via B4 Relay
2026-11-23  9:47   ` Andy Shevchenko

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=sashiko-outbox-228507@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shyckless@gmail.com \
    --cc=vkoul@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.