In the Linux kernel, the following vulnerability has been resolved:
hwmon: (ftsteutates) Fix TOCTOU race in fts_read()
In the ftsread() function, when handling hwmonpwmautochannelstemp, the code accesses the shared variable data->fansource[channel] twice without holding any locks. It is first checked against FTSFANSOURCE_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 ftsupdatedevice() can modify the value of data->fansource[channel] between the check and its use. If the value is changed to FTSFANSOURCEINVALID (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->fansource[channel] into a local variable once, eliminating the race condition. Additionally, add a bounds check to ensure the value is less than BITSPER_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.