DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hongling Zeng" <zenghongling@kylinos.cn>
Cc: vkoul@kernel.org, Frank.Li@kernel.org,
	linux-sunxi@lists.linux.dev, dmaengine@vger.kernel.org
Subject: Re: [PATCH v4] dmaengine: sun6i-dma: Fix use-after-free in error handling paths
Date: Wed, 08 Jul 2026 03:35:06 +0000	[thread overview]
Message-ID: <20260708033506.CD02C1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260708032518.50886-1-zenghongling@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Race condition in IRQ handler leading to NULL pointer dereference
- [High] Missing tasklet_schedule in sun6i_dma_resume causes stalled transfers
--

--- Patch [1]: [PATCH v4] dmaengine: sun6i-dma: Fix use-after-free in error handling paths ---
commit ece21d8f10ca9ff0dd6adbfa89c44eada4329522
Author: Hongling Zeng <zenghongling@kylinos.cn>

dmaengine: sun6i-dma: Fix use-after-free in error handling paths

The commit refactors the error handling paths in the sun6i-dma driver by
introducing the helper functions sun6i_dma_free_desc() and
sun6i_dma_free_desc_virt(). This resolves a use-after-free issue when
iterating and freeing a virtual LLI list in sun6i_dma_prep_slave_sg() and
sun6i_dma_prep_dma_cyclic().

> drivers/dma/sun6i-dma.c:sun6i_dma_interrupt() {
> ...
> 			if (vchan && (status & vchan->irq_type)) {
> 				if (vchan->cyclic) {
> 					vchan_cyclic_callback(&pchan->desc->vd);
> 				} else {
> 					spin_lock(&vchan->vc.lock);
> 					vchan_cookie_complete(&pchan->desc->vd);
> 					pchan->done = pchan->desc;
> 					spin_unlock(&vchan->vc.lock);
> 				}
> 			}
> ...
> }

[Severity: High]
This is a pre-existing issue, but could this cause a NULL pointer dereference?

Looking at sun6i_dma_terminate_all(), it clears pchan->desc:

> drivers/dma/sun6i-dma.c:sun6i_dma_terminate_all() {
> ...
> 	if (pchan) {
> 		writel(DMA_CHAN_ENABLE_STOP, pchan->base + DMA_CHAN_ENABLE);
> 		writel(DMA_CHAN_PAUSE_RESUME, pchan->base + DMA_CHAN_PAUSE);
> 
> 		vchan->phy = NULL;
> 		pchan->vchan = NULL;
> 		pchan->desc = NULL;
> 		pchan->done = NULL;
> 	}
> ...
> }

If sun6i_dma_terminate_all() runs concurrently with sun6i_dma_interrupt() on
SMP systems, sun6i_dma_terminate_all() holds vchan->vc.lock, stops the
hardware, and sets pchan->desc = NULL. Meanwhile, the IRQ handler reads
pchan->vchan locklessly.

If the IRQ handler evaluates this before it is cleared, it will proceed. For
non-cyclic transfers, the IRQ handler blocks on vchan->vc.lock. When
sun6i_dma_terminate_all() releases the lock, the IRQ handler continues and
evaluates &pchan->desc->vd. Since pchan->desc is NULL, could this pass a NULL
pointer to vchan_cookie_complete() and cause a kernel panic? For cyclic
transfers, the race appears even wider since the handler evaluates
&pchan->desc->vd completely locklessly.

> drivers/dma/sun6i-dma.c:sun6i_dma_resume() {
> ...
> 	} else if (!list_empty(&vchan->vc.desc_issued)) {
> 		spin_lock(&sdev->lock);
> 		list_add_tail(&vchan->node, &sdev->pending);
> 		spin_unlock(&sdev->lock);
> 	}
> ...
> }

[Severity: High]
This is a pre-existing issue, but does this code leave transfers stalled
indefinitely?

If a DMA channel is paused (sun6i_dma_pause) while it has pending descriptors
but is not yet assigned to a physical hardware channel (pchan == NULL), it is
removed from the sdev->pending list.

When the channel is later resumed here in sun6i_dma_resume(), it is re-added
to sdev->pending. However, sun6i_dma_resume() fails to call
tasklet_schedule(&sdev->task). Since the tasklet is responsible for pulling
virtual channels off the pending list and assigning them to physical channels,
will this channel sit in the pending queue indefinitely until an independent
event schedules the tasklet?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260708032518.50886-1-zenghongling@kylinos.cn?part=1

  reply	other threads:[~2026-07-08  3:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  3:25 [PATCH v4] dmaengine: sun6i-dma: Fix use-after-free in error handling paths Hongling Zeng
2026-07-08  3:35 ` sashiko-bot [this message]
2026-07-08 21:03 ` 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=20260708033506.CD02C1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vkoul@kernel.org \
    --cc=zenghongling@kylinos.cn \
    /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