From: sashiko-bot@kernel.org
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH] hwmon: (powerz) Avoid cacheline sharing for DMA buffer
Date: Wed, 08 Apr 2026 19:19:21 +0000 [thread overview]
Message-ID: <20260408191922.2A2C9C19421@smtp.kernel.org> (raw)
In-Reply-To: <20260408-powerz-cacheline-alias-v1-1-1254891be0dd@weissschuh.net>
Sashiko AI review found 2 potential issue(s):
- [High] A Use-After-Free (UAF) vulnerability occurs on `priv->urb` due to a race condition between sysfs reads and device disconnection.
- [High] Incorrect error handling of `wait_for_completion_interruptible_timeout()` allows an active URB to leak in-flight, leading to concurrent DMA modification and URB state corruption.
--
commit e653439f03252b9df547ec7df8f35d202c25c060
Author: Thomas Weißschuh <linux@weissschuh.net>
hwmon: (powerz) Avoid cacheline sharing for DMA buffer
This commit uses the high-level DMA helpers to ensure cacheline sharing
cannot occur for the DMA transfer buffer.
https://sashiko.dev/#/message/20260408175814.934BFC19421%40smtp.kernel.org
> diff --git a/drivers/hwmon/powerz.c b/drivers/hwmon/powerz.c
> index 4e663d5b4e330..5e83978956137 100644
> --- a/drivers/hwmon/powerz.c
> +++ b/drivers/hwmon/powerz.c
[ ... ]
> @@ -33,7 +34,9 @@ struct powerz_sensor_data {
> } __packed;
>
> struct powerz_priv {
> - char transfer_buffer[64]; /* first member to satisfy DMA alignment */
> + __dma_from_device_group_begin();
> + char transfer_buffer[64];
> + __dma_from_device_group_end();
> struct mutex mutex;
> struct completion completion;
> struct urb *urb;
While reviewing this patch, I noticed a couple of pre-existing issues in
this driver.
Can a use-after-free occur on priv->urb during device disconnection?
The hwmon device is registered using devm_hwmon_device_register_with_info(),
meaning its sysfs attributes are removed during devres cleanup, which
happens after powerz_disconnect() returns.
If a userspace process performs a sysfs read concurrently, it can block
on mutex_lock(&priv->mutex) in powerz_read(). Once powerz_disconnect()
frees the URB and drops the mutex:
drivers/hwmon/powerz.c:powerz_disconnect() {
...
mutex_lock(&priv->mutex);
usb_kill_urb(priv->urb);
usb_free_urb(priv->urb);
mutex_unlock(&priv->mutex);
}
The blocked sysfs read could wake up, proceed into powerz_read_data(),
and use the freed priv->urb:
drivers/hwmon/powerz.c:powerz_read_data() {
...
usb_fill_bulk_urb(priv->urb, udev, ...);
ret = usb_submit_urb(priv->urb, GFP_KERNEL);
...
}
Additionally, is the error handling for wait_for_completion_interruptible_timeout()
correct in powerz_read_data()?
drivers/hwmon/powerz.c:powerz_read_data() {
...
ret = usb_submit_urb(priv->urb, GFP_KERNEL);
if (ret)
return ret;
if (!wait_for_completion_interruptible_timeout
(&priv->completion, msecs_to_jiffies(5))) {
usb_kill_urb(priv->urb);
return -EIO;
}
...
}
If wait_for_completion_interruptible_timeout() is interrupted by a signal,
it returns -ERESTARTSYS (a negative value). The condition
if (!wait_for_completion_interruptible_timeout(...)) only catches timeouts
(which return 0), bypassing the usb_kill_urb() cleanup.
This could allow the function to return -EIO (since actual_length is 0)
and release priv->mutex while the USB transfer is still active.
Could a subsequent sysfs read then acquire the mutex, modify
priv->transfer_buffer, and call usb_submit_urb() on an active URB?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260408-powerz-cacheline-alias-v1-1-1254891be0dd@weissschuh.net?part=1
prev parent reply other threads:[~2026-04-08 19:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-08 18:45 [PATCH] hwmon: (powerz) Avoid cacheline sharing for DMA buffer Thomas Weißschuh
2026-04-08 19:19 ` sashiko-bot [this message]
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=20260408191922.2A2C9C19421@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=sashiko@lists.linux.dev \
/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