All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guenter Roeck" <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org
Subject: Re: [PATCH] hwmon: Fix potential UAF in pec_store
Date: Fri, 21 Aug 2026 05:18:43 +0000	[thread overview]
Message-ID: <20260821051843.8CD1D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260821050808.667204-1-linux@roeck-us.net>

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

Pre-existing issues:
- [Medium] The function `pec_store()` mixes `goto`-based error handling (`goto put;`) with scope-based cleanup (`scoped_guard`), which violates subsystem guidelines.
--

--- Patch [1]: [PATCH] hwmon: Fix potential UAF in pec_store ---
commit faaeb6b5ca43335968fb5512ec894ab84e5edc9c
Author: Guenter Roeck <linux@roeck-us.net>

hwmon: Fix potential UAF in pec_store

This patch fixes a potential use-after-free in pec_store() by replacing
guard() with scoped_guard(). The previous guard() usage attempted to unlock
the mutex after dropping the final device reference when jumping to the 'put'
label.

> diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
> index 29dc90a2c3fe7..8cf717ae8b1dd 100644
> --- a/drivers/hwmon/hwmon.c
> +++ b/drivers/hwmon/hwmon.c
> @@ -371,18 +371,17 @@ static ssize_t pec_store(struct device *dev, struct device_attribute *devattr,
>  	 * handling is not required.
>  	 */
>  	hwdev = to_hwmon_device(hdev);
> -	guard(mutex)(&hwdev->lock);
> -	if (hwdev->chip->ops->write) {
> -		err = hwdev->chip->ops->write(hdev, hwmon_chip, hwmon_chip_pec, 0, val);
> -		if (err && err != -EOPNOTSUPP)
> -			goto put;
> +	scoped_guard(mutex, &hwdev->lock) {
> +		if (hwdev->chip->ops->write) {
> +			err = hwdev->chip->ops->write(hdev, hwmon_chip, hwmon_chip_pec, 0, val);
> +			if (err && err != -EOPNOTSUPP)
> +				goto put;

[Severity: Medium]
This is a pre-existing issue, but does this code mix goto-based error
handling with scope-based cleanup helpers?

According to the subsystem guidelines in include/linux/cleanup.h, mixing goto
and cleanup helpers in the same function creates confusing ownership semantics
and should be avoided. Would it be better to also convert the 'hdev' reference
management to use __free(put_device) to fully eliminate the goto pattern?

> +		}
> +		if (!val)
> +			client->flags &= ~I2C_CLIENT_PEC;
> +		else
> +			client->flags |= I2C_CLIENT_PEC;
>  	}
> -
> -	if (!val)
> -		client->flags &= ~I2C_CLIENT_PEC;
> -	else
> -		client->flags |= I2C_CLIENT_PEC;
> -
>  	err = count;
>  put:
>  	put_device(hdev);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260821050808.667204-1-linux@roeck-us.net?part=1

      reply	other threads:[~2026-08-21  5:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21  5:08 [PATCH] hwmon: Fix potential UAF in pec_store Guenter Roeck
2026-08-21  5:18 ` 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=20260821051843.8CD1D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.