DMA Engine development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Logan Gunthorpe" <logang@deltatee.com>
Cc: dmaengine@vger.kernel.org, Frank.Li@kernel.org, vkoul@kernel.org
Subject: Re: [PATCH v1 4/5] dmaengine: switchtec-dma: Add pmon sysfs attributes
Date: Tue, 07 Jul 2026 16:58:04 +0000	[thread overview]
Message-ID: <20260707165804.C1A241F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260707162045.23910-5-logang@deltatee.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Missing `.release` callback in `switchtec_ktype` causes Use-After-Free of channel memory when sysfs files are held open during device removal.
- [Low] The `latency_selector_show` function violates sysfs rules by using `strcat()` to build a multi-line menu instead of using `sysfs_emit()`.
--

--- Patch [4]: [PATCH v1 4/5] dmaengine: switchtec-dma: Add pmon sysfs attributes ---
commit 9353b00f22d3df92fe9cfb71beccb84977c35e68
Author: Logan Gunthorpe <logang@deltatee.com>

dmaengine: switchtec-dma: Add pmon sysfs attributes

Switchtec hardware exposes some performance monitor registers which
can be used to monitor various statistics of the hardware. Expose
these as a sysfs interface under the switchtec group in a pmon
sub-group.

> diff --git a/drivers/dma/switchtec_dma.c b/drivers/dma/switchtec_dma.c
> index 4841134bd7b83..2ac43eb58995a 100644
> --- a/drivers/dma/switchtec_dma.c
> +++ b/drivers/dma/switchtec_dma.c

[ ... ]

> @@ -1156,8 +1163,200 @@ static struct attribute_group switchtec_config_group = {
>  	.attrs = switchtec_config_attrs,
>  };
>  
> +#define pmon_show(chan, page, field, reader) ({				     \
> +	struct switchtec_dma_chan *__swdma_chan =			     \
> +		container_of((chan), struct switchtec_dma_chan, dma_chan);   \

[ ... ]

> +static ssize_t latency_selector_show(struct dma_chan *chan, char *page)
> +{
> +	struct switchtec_dma_chan *swdma_chan =
> +		container_of(chan, struct switchtec_dma_chan, dma_chan);
> +	struct chan_fw_regs __iomem *chan_fw = swdma_chan->mmio_chan_fw;
> +	u32 lat = 0;
> +
> +	rcu_read_lock();
> +	if (!rcu_dereference(swdma_chan->swdma_dev->pdev)) {
> +		rcu_read_unlock();
> +		return -ENODEV;
> +	}
> +
> +	lat = readl(&chan_fw->perf_latency_selector);
> +	rcu_read_unlock();
> +
> +	strcat(page, "To select a latency type, write the type number (1 ~ 5) to latency_selector\n\n");
> +
> +	strcat(page, "Latency Types:\n");
> +	strcat(page, "(1) SE Fetch latency");

[Severity: Low]
Should this code use sysfs_emit() instead of strcat() to construct the menu on
the raw page buffer? Sysfs documentation requires using sysfs_emit() and
generally expects a single value per file rather than a multi-line string.

> +	if (lat & SWITCHTEC_LAT_SE_FETCH)
> +		strcat(page, " (*)\n");
> +	else
> +		strcat(page, "\n");

[ ... ]

>  static const struct attribute_group *switchtec_groups[] = {
>  	&switchtec_config_group,
> +	&switchtec_pmon_group,
>  	NULL,
>  };

[Severity: High]
Does the driver's kobj_type (switchtec_ktype) lack a .release callback?

If a userspace process holds a channel's sysfs file open, keeping the
embedded kobject refcount elevated, and the device is unregistered,
switchtec_dma_release() unconditionally frees the channel memory.

When the file is closed later and the refcount drops to zero, the kernel
would access the already-freed kobject to invoke the missing release
function, leading to a Use-After-Free.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260707162045.23910-1-logang@deltatee.com?part=4

  reply	other threads:[~2026-07-07 16:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 16:20 [PATCH v1 0/5] Add sysfs interface to switchtec-dma Logan Gunthorpe
2026-07-07 16:20 ` [PATCH v1 1/5] dmaengine: add support for custom per-channel sysfs attributes Logan Gunthorpe
2026-07-07 16:54   ` sashiko-bot
2026-07-07 16:20 ` [PATCH v1 2/5] dmaengine: ioatdma: use common channel sysfs attribute creation Logan Gunthorpe
2026-07-07 16:48   ` Dave Jiang
2026-07-07 16:59   ` sashiko-bot
2026-07-07 16:20 ` [PATCH v1 3/5] dmaengine: switchtec-dma: Add config sysfs attributes Logan Gunthorpe
2026-07-07 16:55   ` sashiko-bot
2026-07-07 16:20 ` [PATCH v1 4/5] dmaengine: switchtec-dma: Add pmon " Logan Gunthorpe
2026-07-07 16:58   ` sashiko-bot [this message]
2026-07-07 16:20 ` [PATCH v1 5/5] dmaengine: switchtec-dma: Add PCI1008 device ID Logan Gunthorpe
2026-07-07 16:53   ` 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=20260707165804.C1A241F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=dmaengine@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