From: sashiko-bot@kernel.org
To: "Logan Gunthorpe" <logang@deltatee.com>
Cc: vkoul@kernel.org, Frank.Li@kernel.org, linux-pci@vger.kernel.org,
dmaengine@vger.kernel.org
Subject: Re: [PATCH v3 06/11] dmaengine: switchtec-dma: fix chan_status_irq cleanup on create() error
Date: Mon, 27 Jul 2026 19:28:32 +0000 [thread overview]
Message-ID: <20260727192832.B1C991F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260727181526.9672-7-logang@deltatee.com>
Thank you for your contribution! Sashiko AI review found 6 potential issue(s) to consider:
Pre-existing issues:
- [High] Unmapping `swdma_dev->bar` after `dma_async_device_unregister` causes a use-after-free.
- [High] Missing NULL check after `ioremap()` in `switchtec_dma_create` leads to a NULL pointer dereference on failure.
- [High] The DMA channel list is initialized after the status IRQ is requested, allowing an early interrupt to trigger a NULL pointer dereference.
- [High] In the error paths of `switchtec_dma_create()`, DMA channels are freed while the status IRQ remains registered, causing a Use-After-Free.
- [High] Invoking client callbacks while holding a driver spinlock causes a recursive locking deadlock if the callback re-enters the driver.
- [High] Incorrect teardown sequence in device remove risks hangs or crashes for active DMA clients.
--
--- Patch [6]: [PATCH v3 06/11] dmaengine: switchtec-dma: fix chan_status_irq cleanup on create() error ---
commit 4abb826d6d25e80cfa344cde79ed065a727edad5
Author: Logan Gunthorpe <logang@deltatee.com>
dmaengine: switchtec-dma: fix chan_status_irq cleanup on create() error
This patch initializes chan_status_irq to -1 and uses the non-negative
value to determine when to call pci_free_irq() instead of free_irq().
This prevents freeing the wrong Linux IRQ and ensures the handler is
properly unregistered when the vector index is 0.
Link: https://lore.kernel.org/dmaengine/20260717223431.625EE1F000E9@smtp.kernel.org
> diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
> index c752a1b05871d..31feb2816e79b 100644
> --- a/drivers/dma/switchtec_dma.c
> +++ b/drivers/dma/switchtec_dma.c
> @@ -1248,6 +1248,8 @@ static int switchtec_dma_create(struct pci_dev *pdev)
> if (!swdma_dev)
> return -ENOMEM;
>
> + swdma_dev->chan_status_irq = -1;
> +
> swdma_dev->bar = ioremap(pci_resource_start(pdev, 0),
> pci_resource_len(pdev, 0));
[Severity: High]
This is a pre-existing issue, but does ioremap() need a NULL check here?
If it fails under memory pressure and returns NULL, swdma_dev->bar will be
assigned NULL.
Shortly after, the code executes:
irq = readw(swdma_dev->bar + SWITCHTEC_REG_CHAN_STS_VEC);
Will this lead to an immediate NULL pointer dereference?
[ ... ]
> @@ -1322,8 +1324,8 @@ static int switchtec_dma_create(struct pci_dev *pdev)
> switchtec_dma_chans_free(swdma_dev);
>
> err_exit:
> - if (swdma_dev->chan_status_irq)
> - free_irq(swdma_dev->chan_status_irq, swdma_dev);
> + if (swdma_dev->chan_status_irq >= 0)
> + pci_free_irq(pdev, swdma_dev->chan_status_irq, swdma_dev);
[Severity: High]
This isn't a bug introduced by this patch, but can this error path lead to a
use-after-free?
If dma_async_device_register() fails, the code jumps to
err_chans_release_exit, which calls switchtec_dma_chans_free(). This frees
the channel structures but leaves them linked in dma_dev->channels.
The status IRQ remains registered until pci_free_irq() is called here.
If an interrupt fires during this window, will
switchtec_dma_chan_status_isr() iterate the list and access the freed
channel objects?
>
> iounmap(swdma_dev->bar);
> kfree(swdma_dev);
While reviewing this file, I noticed a few other pre-existing issues.
[Severity: High]
This is a pre-existing issue, but could an early interrupt trigger a NULL
pointer dereference?
In switchtec_dma_create(), pci_request_irq() is called before the channel
list is initialized:
switchtec_dma_create()
...
rc = pci_request_irq(pdev, irq, NULL, switchtec_dma_chan_status_isr, ...);
If an interrupt fires immediately, switchtec_dma_chan_status_isr() will
execute:
switchtec_dma_chan_status_isr()
...
list_for_each_entry(chan, &dma_dev->channels, device_node) {
Since swdma_dev was allocated with kzalloc_obj(), the list head is NULL.
Does iterating this uninitialized list bypass termination checks and crash?
[Severity: High]
This isn't a bug introduced by this patch, but can unmapping swdma_dev->bar
after unregistering the DMA device cause a use-after-free?
Looking at switchtec_dma_remove(), dma_async_device_unregister() is called
before iounmap():
switchtec_dma_remove()
...
dma_async_device_unregister(&swdma_dev->dma_dev);
iounmap(swdma_dev->bar);
...
When dma_async_device_unregister() drops the final reference to the DMA
device, it triggers the release callback:
switchtec_dma_release()
...
kfree(swdma_dev);
Will this sequence cause iounmap() to dereference the freed swdma_dev
structure?
[Severity: High]
This is a pre-existing issue, but can invoking client callbacks while
holding the driver spinlock cause a recursive locking deadlock?
Looking at switchtec_dma_cleanup_completed():
spin_lock_bh(&swdma_chan->complete_lock);
...
dmaengine_desc_get_callback_invoke(&desc->txd, &res);
If the client callback re-enters the driver API, for example by calling
dmaengine_tx_status(), it will execute switchtec_dma_tx_status(), which
again calls switchtec_dma_cleanup_completed().
Since complete_lock is a non-recursive spinlock, will this inner call
attempt to acquire it and lead to an immediate self-deadlock?
[Severity: High]
This isn't a bug introduced by this patch, but is the teardown sequence in
switchtec_dma_remove() correct?
switchtec_dma_remove()
...
switchtec_dma_chans_release(pdev, swdma_dev);
...
dma_async_device_unregister(&swdma_dev->dma_dev);
Here, switchtec_dma_chans_release() halts the hardware and frees channel IRQs
before dma_async_device_unregister() safely quiesces the DMA engine.
Will this inverted teardown destroy the hardware state while the DMA core
still considers the device active, causing active clients to hang waiting
for completions or crash if they submit new requests?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260727181526.9672-1-logang@deltatee.com?part=6
next prev parent reply other threads:[~2026-07-27 19:28 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 18:15 [PATCH v3 00/11] dmaengine: miscellaneous fixes for ioat, switchtec_dma and plx_dma Logan Gunthorpe
2026-07-27 18:15 ` [PATCH v3 01/11] dmaengine: switchtec-dma: fix double-free in switchtec_dma_free_desc() Logan Gunthorpe
2026-07-27 18:28 ` sashiko-bot
2026-07-27 20:42 ` Frank Li
2026-07-27 18:15 ` [PATCH v3 02/11] dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources Logan Gunthorpe
2026-07-27 18:40 ` sashiko-bot
2026-07-27 18:56 ` Logan Gunthorpe
2026-07-27 20:44 ` Frank Li
2026-07-27 18:15 ` [PATCH v3 03/11] dmaengine: switchtec-dma: halt channel on alloc_chan_resources error Logan Gunthorpe
2026-07-27 18:51 ` sashiko-bot
2026-07-27 20:47 ` Frank Li
2026-07-27 21:28 ` Logan Gunthorpe
2026-07-27 18:15 ` [PATCH v3 04/11] dmaengine: switchtec-dma: fix channel leak on registration failure Logan Gunthorpe
2026-07-27 19:06 ` sashiko-bot
2026-07-27 20:52 ` Frank Li
2026-07-27 18:15 ` [PATCH v3 05/11] dmaengine: switchtec-dma: make switchtec_dma_chans_release() void Logan Gunthorpe
2026-07-27 19:15 ` sashiko-bot
2026-07-27 20:54 ` Frank Li
2026-07-27 18:15 ` [PATCH v3 06/11] dmaengine: switchtec-dma: fix chan_status_irq cleanup on create() error Logan Gunthorpe
2026-07-27 19:28 ` sashiko-bot [this message]
2026-07-27 20:55 ` Frank Li
2026-07-27 18:15 ` [PATCH v3 07/11] dmaengine: switchtec-dma: disable channels before freeing on registration failure Logan Gunthorpe
2026-07-27 19:39 ` sashiko-bot
2026-07-27 21:21 ` Frank Li
2026-07-27 21:51 ` Logan Gunthorpe
2026-07-27 18:15 ` [PATCH v3 08/11] dmaengine: switchtec-dma: fix use-after-free of swdma_dev in remove() Logan Gunthorpe
2026-07-27 19:52 ` sashiko-bot
2026-07-27 21:23 ` Frank Li
2026-07-27 18:15 ` [PATCH v3 09/11] dmaengine: ioat: disable relaxed ordering before registering the device Logan Gunthorpe
2026-07-27 20:06 ` sashiko-bot
2026-07-27 21:27 ` Frank Li
2026-07-27 18:15 ` [PATCH v3 10/11] dmaengine: ioat: use sysfs_emit() in per-channel sysfs show() Logan Gunthorpe
2026-07-27 20:13 ` sashiko-bot
2026-07-27 21:28 ` Frank Li
2026-07-27 18:15 ` [PATCH v3 11/11] dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr() Logan Gunthorpe
2026-07-27 20:23 ` sashiko-bot
2026-07-27 21:29 ` 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=20260727192832.B1C991F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Frank.Li@kernel.org \
--cc=dmaengine@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=logang@deltatee.com \
--cc=sashiko-reviews@lists.linux.dev \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox