mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: Gui-Dong Han <hanguidong02@gmail.com>
Cc: jdelvare@suse.com, linux-hwmon@vger.kernel.org,
	linux-kernel@vger.kernel.org, baijiaju1990@gmail.com,
	stable@vger.kernel.org
Subject: Re: [PATCH] hwmon: (ftsteutates) Fix TOCTOU race in fts_read()
Date: Fri, 6 Jun 2025 06:28:15 -0700	[thread overview]
Message-ID: <98f33209-be61-4a5f-8f0d-41f6570f79dc@roeck-us.net> (raw)
In-Reply-To: <20250606071640.501262-1-hanguidong02@gmail.com>

On Fri, Jun 06, 2025 at 07:16:40AM +0000, Gui-Dong Han wrote:
> In the fts_read() function, when handling hwmon_pwm_auto_channels_temp,
> the code accesses the shared variable data->fan_source[channel] twice
> without holding any locks. It is first checked against
> FTS_FAN_SOURCE_INVALID, and if the check passes, it is read again
> when used as an argument to the BIT() macro.
> 
> This creates a Time-of-Check to Time-of-Use (TOCTOU) race condition.
> Another thread executing fts_update_device() can modify the value of
> data->fan_source[channel] between the check and its use. If the value
> is changed to FTS_FAN_SOURCE_INVALID (0xff) during this window, the
> BIT() macro will be called with a large shift value (BIT(255)).
> A bit shift by a value greater than or equal to the type width is
> undefined behavior and can lead to a crash or incorrect values being
> returned to userspace.
> 
> Fix this by reading data->fan_source[channel] into a local variable
> once, eliminating the race condition. Additionally, add a bounds check
> to ensure the value is less than BITS_PER_LONG before passing it to
> the BIT() macro, making the code more robust against undefined behavior.
> 
> This possible bug was found by an experimental static analysis tool
> developed by our team.
> 
> Fixes: 1c5759d8ce05 ("hwmon: (ftsteutates) Replace fanX_source with pwmX_auto_channels_temp")
> Cc: stable@vger.kernel.org
> Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>

Applied.

Thanks,
Guenter

      reply	other threads:[~2025-06-06 13:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-06  7:16 Gui-Dong Han
2025-06-06 13:28 ` Guenter Roeck [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=98f33209-be61-4a5f-8f0d-41f6570f79dc@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=baijiaju1990@gmail.com \
    --cc=hanguidong02@gmail.com \
    --cc=jdelvare@suse.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.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

all inboxes | Powered by JetHome®