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 v5 08/12] dmaengine: switchtec-dma: disable channels before freeing on registration failure
Date: Mon, 31 Aug 2026 22:50:25 +0000 [thread overview]
Message-ID: <20260831225025.C782E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260831191403.207631-9-logang@deltatee.com>
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Pre-existing issues:
- [High] Missing check for ioremap failure in switchtec_dma_create() leads to NULL pointer dereference.
- [High] The channel status IRQ handler dereferences uninitialized structures if the IRQ fires before dma_async_device_register() completes.
- [High] Missing bounds check on untrusted `chan_cnt` read from the PCI device allows out-of-bounds MMIO pointer arithmetic and memory writes.
--
commit 9d90eebe0f109c6aab9cf75114365b10451e1028
Author: Logan Gunthorpe <logang@deltatee.com>
Subject: dmaengine: switchtec-dma: disable channels before freeing on registration failure
When switchtec_dma_create() fails after channels have been added to
dma_dev->channels, the channel status IRQ is still live while the channels
are released and freed. Add switchtec_dma_chans_disable() to free the
channel status IRQ before releasing and freeing channels in both error paths.
Link: https://lore.kernel.org/dmaengine/20260717223431.625EE1F000E9@smtp.kernel.org
Link: https://lore.kernel.org/dmaengine/20260721162822.05CDD1F000E9@smtp.kernel.org
> diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
> --- a/drivers/dma/switchtec_dma.c
> +++ b/drivers/dma/switchtec_dma.c
[ ... ]
> swdma_dev->bar = ioremap(pci_resource_start(pdev, 0),
> pci_resource_len(pdev, 0));
>
> RCU_INIT_POINTER(swdma_dev->pdev, pdev);
>
> nr_vecs = pci_msix_vec_count(pdev);
> rc = pci_alloc_irq_vectors(pdev, nr_vecs, nr_vecs, PCI_IRQ_MSIX);
> if (rc < 0)
> goto err_exit;
>
> irq = readw(swdma_dev->bar + SWITCHTEC_REG_CHAN_STS_VEC);
[Severity: High]
This is a pre-existing issue, but does this code cause a NULL pointer
dereference if ioremap() fails? The swdma_dev->bar pointer does not appear
to be checked before being unconditionally dereferenced by readw() during
device probe.
> pci_dbg(pdev, "Channel pause irq vector %d\n", irq);
>
> rc = pci_request_irq(pdev, irq, NULL, switchtec_dma_chan_status_isr,
> swdma_dev, KBUILD_MODNAME);
> if (rc)
> goto err_exit;
[Severity: High]
This is a pre-existing issue, but does this request the IRQ too early? If
the hardware asserts the IRQ immediately, the ISR will run before the
channels are fully initialized.
Looking at switchtec_dma_chan_status_isr():
list_for_each_entry(chan, &dma_dev->channels, device_node) {
swdma_chan = container_of(chan, struct switchtec_dma_chan,
dma_chan);
chan_dev = &swdma_chan->dma_chan.dev->device;
chan_hw = swdma_chan->mmio_chan_hw;
Could this dereference an invalid pointer if the channels list is empty or
if chan->dev is not yet initialized by dma_async_device_register()?
> swdma_dev->chan_status_irq = irq;
>
> chan_cnt = readl(swdma_dev->bar + SWITCHTEC_REG_CHAN_CNT);
> if (!chan_cnt) {
> pci_err(pdev, "No channel configured.\n");
> rc = -ENXIO;
> goto err_exit;
> }
>
> chan_cnt = switchtec_dma_chans_enumerate(swdma_dev, pdev, chan_cnt);
[Severity: High]
This is a pre-existing issue, but is there a missing upper bounds check on
chan_cnt? Since chan_cnt is read directly from hardware, an untrusted
device could provide a very large count.
In switchtec_dma_chan_init(), this unvalidated count is used for pointer
arithmetic:
swdma_chan->mmio_chan_fw =
swdma_dev->bar + SWITCHTEC_DMAC_CHAN_CFG_STS_OFFSET +
i * SWITCHTEC_DMA_CHAN_FW_REGS_SIZE;
swdma_chan->mmio_chan_hw =
swdma_dev->bar + SWITCHTEC_DMAC_CHAN_CTRL_OFFSET +
i * SWITCHTEC_DMA_CHAN_HW_REGS_SIZE;
Could this allow out-of-bounds MMIO pointer arithmetic and memory writes
outside the valid bar resource window?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260831191403.207631-1-logang@deltatee.com?part=8
next prev parent reply other threads:[~2026-08-31 22:50 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 19:13 [PATCH v5 00/12] dmaengine: miscellaneous fixes for ioat, switchtec_dma and plx_dma Logan Gunthorpe
2026-08-31 19:13 ` [PATCH v5 01/12] dmaengine: switchtec-dma: fix double-free in switchtec_dma_free_desc() Logan Gunthorpe
2026-08-31 21:28 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 02/12] dmaengine: switchtec-dma: fix resource leak in alloc_chan_resources Logan Gunthorpe
2026-08-31 21:38 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 03/12] dmaengine: switchtec-dma: always clear DMA base registers on chan_stop() Logan Gunthorpe
2026-08-31 21:51 ` sashiko-bot
2026-08-31 22:43 ` Logan Gunthorpe
2026-08-31 19:13 ` [PATCH v5 04/12] dmaengine: switchtec-dma: halt channel on alloc_chan_resources error Logan Gunthorpe
2026-08-31 22:04 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 05/12] dmaengine: switchtec-dma: fix channel leak on registration failure Logan Gunthorpe
2026-08-31 22:18 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 06/12] dmaengine: switchtec-dma: make switchtec_dma_chans_release() void Logan Gunthorpe
2026-08-31 22:24 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 07/12] dmaengine: switchtec-dma: fix chan_status_irq cleanup on create() error Logan Gunthorpe
2026-08-31 22:35 ` sashiko-bot
2026-08-31 19:13 ` [PATCH v5 08/12] dmaengine: switchtec-dma: disable channels before freeing on registration failure Logan Gunthorpe
2026-08-31 22:50 ` sashiko-bot [this message]
2026-08-31 19:13 ` [PATCH v5 09/12] dmaengine: switchtec-dma: fix use-after-free of swdma_dev in remove() Logan Gunthorpe
2026-08-31 23:04 ` sashiko-bot
2026-08-31 19:14 ` [PATCH v5 10/12] dmaengine: ioat: disable relaxed ordering before registering the device Logan Gunthorpe
2026-08-31 23:13 ` sashiko-bot
2026-08-31 19:14 ` [PATCH v5 11/12] dmaengine: ioat: use sysfs_emit() in per-channel sysfs show() Logan Gunthorpe
2026-08-31 23:19 ` sashiko-bot
2026-08-31 19:14 ` [PATCH v5 12/12] dmaengine: plx_dma: fix NULL pointer deref in plx_dma_isr() Logan Gunthorpe
2026-08-31 23:30 ` sashiko-bot
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=20260831225025.C782E1F000E9@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