public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pradhan, Sanman" <sanman.pradhan@hpe.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v4 1/2] hwmon: (powerz) Fix use-after-free on USB disconnect
Date: Fri, 10 Apr 2026 01:04:34 +0000	[thread overview]
Message-ID: <20260410010435.40681C4CEF7@smtp.kernel.org> (raw)
In-Reply-To: <20260410002521.422645-2-sanman.pradhan@hpe.com>

Sashiko AI review found 1 potential issue(s):
- [High] Unsafe DMA Buffer Cacheline Sharing (Pre-existing Bug)
--

commit f830fe65a5d61278ed5e2ee2dbcd0c937471cfd4
Author: Sanman Pradhan <psanman@juniper.net>
hwmon: (powerz) Fix use-after-free on USB disconnect

This commit prevents a use-after-free by setting the URB pointer to NULL on
device disconnect, and checking for it before starting any read operations. It
also moves the hardware monitoring registration after the private data is set.

> diff --git a/drivers/hwmon/powerz.c b/drivers/hwmon/powerz.c
> --- a/drivers/hwmon/powerz.c
> +++ b/drivers/hwmon/powerz.c
> @@ -108,6 +108,9 @@ static int powerz_read_data(struct usb_device *udev, struct powerz_priv *priv)
>  {
>  	int ret;
>  
> +	if (!priv->urb)
> +		return -ENODEV;
> +
>  	priv->status = -ETIMEDOUT;
>  	reinit_completion(&priv->completion);

This isn't a bug introduced by this patch, but looking at the structure being
modified here:

struct powerz_priv {
        char transfer_buffer[64];
        struct mutex mutex;
        struct completion completion;
        struct urb *urb;
        int status;
};

Can this layout cause memory corruption during DMA?

The transfer_buffer is embedded at the start of the structure and is exactly 64
bytes long. On architectures where the CPU cacheline size or DMA minimum
alignment exceeds 64 bytes (such as 128 bytes on many arm64 platforms),
transfer_buffer will share a cacheline with the mutex and completion members.

When the USB core unmaps the buffer after an inbound transfer, the cache
invalidation operates on the entire cacheline. If the CPU concurrently modifies
the mutex or completion structures (for example, when a thread is placed on
the wait queue via wait_for_completion_interruptible_timeout), will those CPU
writes be destroyed by the DMA cache invalidation, or conversely corrupt the
inbound DMA data?

Should transfer_buffer be allocated separately, or forced to an explicit
alignment to ensure safe DMA?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260410002521.422645-1-sanman.pradhan@hpe.com?part=1

  reply	other threads:[~2026-04-10  1:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10  0:25 [PATCH v4 0/2] hwmon: (powerz) Fix disconnect and signal handling bugs Pradhan, Sanman
2026-04-10  0:25 ` [PATCH v4 1/2] hwmon: (powerz) Fix use-after-free on USB disconnect Pradhan, Sanman
2026-04-10  1:04   ` sashiko-bot [this message]
2026-04-10 15:28   ` Guenter Roeck
2026-04-10  0:25 ` [PATCH v4 2/2] hwmon: (powerz) Fix missing usb_kill_urb() on signal interrupt Pradhan, Sanman
2026-04-10  1:33   ` sashiko-bot
2026-04-10 15:29   ` Guenter Roeck
2026-04-10  5:29 ` [PATCH v4 0/2] hwmon: (powerz) Fix disconnect and signal handling bugs Thomas Weißschuh

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=20260410010435.40681C4CEF7@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sanman.pradhan@hpe.com \
    --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