Linux Hardware Monitor development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ali Ahmet Memis" <ali@iusegentoo.com>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v2] hwmon: (corsair-psu) serialize debugfs access against hwmon
Date: Thu, 06 Aug 2026 14:35:06 +0000	[thread overview]
Message-ID: <20260806143506.B81821F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260806142139.168611-1-ali@iusegentoo.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Potential data race and buffer corruption on the shared `cmd_buffer` following a command timeout.
- [High] Out-of-bounds read and potential information leak in debugfs handlers for vendor and product strings.
--

--- Patch [1]: [PATCH v2] hwmon: (corsair-psu) serialize debugfs access against hwmon ---
commit 17027f95f57d41549658af1b49c4295c03ed4860
Author: Ali Ahmet Memis <ali@iusegentoo.com>

hwmon: (corsair-psu) serialize debugfs access against hwmon
    
This commit adds guard(hwmon_lock) to the debugfs read paths in 
print_uptime() and ocpmode_show() to serialize them against the hwmon core.
This prevents data races and incorrect sensor readings resulting from
concurrent USB commands interleaving.

Link: https://lore.kernel.org/all/5f0406fa-9692-49f0-bcfe-c013f5fc7b62@roeck-us.net/
Link: https://lore.kernel.org/all/20260806161028.42218ebd@posteo.net/
Link: https://lore.kernel.org/all/20260802123653.19532-1-ali@iusegentoo.com/

> diff --git a/drivers/hwmon/corsair-psu.c b/drivers/hwmon/corsair-psu.c
> index ce958cdaef58a..033166db6bc42 100644
> --- a/drivers/hwmon/corsair-psu.c
> +++ b/drivers/hwmon/corsair-psu.c
> @@ -664,6 +664,8 @@ static void print_uptime(struct seq_file *seqf, u8 cmd)
>  	long val;
>  	int ret;
>  
> +	guard(hwmon_lock)(priv->hwmon_dev);
> +
>  	ret = corsairpsu_get_value(priv, cmd, 0, &val);

[ ... ]

[Severity: High]
This is a pre-existing issue, but can this sequence lead to a data race or
buffer corruption on the shared cmd_buffer if a USB command times out?

If wait_for_completion_timeout() times out in corsairpsu_usb_cmd(), the
completion is left uncompleted. If the hardware later sends a delayed
response, the asynchronous HID interrupt in corsairpsu_raw_event() will
blindly copy the data:

drivers/hwmon/corsair-psu.c:corsairpsu_raw_event() {
    ...
    memcpy(priv->cmd_buffer, data, min(CMD_BUFFER_SIZE, size));
    complete(&priv->wait_completion);
    ...
}

If a new request is concurrently executing in corsairpsu_usb_cmd(), this
delayed copy will race with its setup:

drivers/hwmon/corsair-psu.c:corsairpsu_usb_cmd() {
    ...
    memset(priv->cmd_buffer, 0, CMD_BUFFER_SIZE);
    ...
}


[Severity: High]
This is a pre-existing issue, but does this code potentially cause an
out-of-bounds read and information leak in the debugfs handlers?

When corsairpsu_fwinfo() fetches the vendor and product information, it
copies exactly REPLY_SIZE (24) bytes from the untrusted USB device into
priv->vendor and priv->product:

drivers/hwmon/corsair-psu.c:corsairpsu_usb_cmd() {
    ...
    memcpy(data, priv->cmd_buffer + 2, REPLY_SIZE);
    ...
}

If a malicious device provides exactly 24 non-null characters, these strings
will not be null-terminated. When seq_printf() prints them in vendor_show()
and product_show(), it could read past the array bounds and leak adjacent
kernel heap memory:

drivers/hwmon/corsair-psu.c:vendor_show() {
    ...
    seq_printf(seqf, "%s\n", priv->vendor);
    ...
}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260806142139.168611-1-ali@iusegentoo.com?part=1

  reply	other threads:[~2026-08-06 14:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-02 12:36 [PATCH] hwmon: (corsair-psu) serialize debugfs access against hwmon Ali Ahmet Memis
2026-08-02 12:48 ` sashiko-bot
2026-08-02 12:57 ` Wilken Gottwalt
2026-08-02 14:07   ` Guenter Roeck
2026-08-03 23:19   ` Guenter Roeck
2026-08-03 23:56     ` Ali Ahmet Memis
2026-08-04  2:54       ` Guenter Roeck
2026-08-04  4:11         ` Wilken Gottwalt
2026-08-04  9:47           ` Ali Ahmet Memis
2026-08-04 10:06             ` Ali Ahmet Memis
2026-08-04 16:34           ` Guenter Roeck
2026-08-04 17:53             ` Wilken Gottwalt
2026-08-04 18:37             ` Wilken Gottwalt
2026-08-04 20:14               ` Guenter Roeck
2026-08-06  5:23 ` Wilken Gottwalt
2026-08-06  9:23   ` Guenter Roeck
2026-08-06 12:19     ` Wilken Gottwalt
2026-08-06 14:10 ` Wilken Gottwalt
2026-08-06 14:21 ` [PATCH v2] " Ali Ahmet Memis
2026-08-06 14:35   ` sashiko-bot [this message]
2026-08-06 15:41   ` Guenter Roeck

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=20260806143506.B81821F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ali@iusegentoo.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=sashiko-reviews@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