]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
hwmon: (it87) Clamp negative values to zero in set_fan()
authorNikita Zhandarovich <n.zhandarovich@fintech.ru>
Fri, 29 May 2026 14:18:36 +0000 (17:18 +0300)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 9 Jun 2026 15:23:09 +0000 (08:23 -0700)
commit7f8581c70a3bd50a932d3d2d253e99c5ec3eda74
treee8ec7ed86b6cd3eac425ad4cfe8babbfca30d6d3
parent5e9f31543515d685cafed33274433b6360c0e1e4
hwmon: (it87) Clamp negative values to zero in set_fan()

set_fan() parses user input with kstrtol() and passes the resulting
value to FAN16_TO_REG() on chips with 16-bit fan support.

Negative fan speeds are not meaningful and should be rejected before
conversion. Worst scenario, one may be able to abuse undefined
behaviour of signed overflow to possibly induce rpm * 2 == 0 in
FAN16_TO_REG(), thus causing a division by zero.

Instead, clamp val < 0 to zero and keep the conversion in its valid
input domain, avoiding unsafe arithmetic in the register conversion
path.

Found by Linux Verification Center (linuxtesting.org) with static
analysis tool SVACE.

Fixes: 17d648bf5786 ("it87: Add support for the IT8716F")
Signed-off-by: Nikita Zhandarovich <n.zhandarovich@fintech.ru>
Link: https://lore.kernel.org/r/20260529141839.1639287-1-n.zhandarovich@fintech.ru
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/it87.c