]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hwmon: (dell-smm) Limit fan multiplier to avoid overflow
authorDenis Sergeev <denserg.edu@gmail.com>
Tue, 9 Dec 2025 06:37:06 +0000 (09:37 +0300)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 14 Dec 2025 17:34:38 +0000 (09:34 -0800)
The fan nominal speed returned by SMM is limited to 16 bits, but the
driver allows the fan multiplier to be set via a module parameter.

Clamp the computed fan multiplier so that fan_nominal_speed *
i8k_fan_mult always fits into a signed 32-bit integer and refuse to
initialize the driver if the value is too large.

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

Fixes: 20bdeebc88269 ("hwmon: (dell-smm) Introduce helper function for data init")
Signed-off-by: Denis Sergeev <denserg.edu@gmail.com>
Link: https://lore.kernel.org/r/20251209063706.49008-1-denserg.edu@gmail.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/dell-smm-hwmon.c

index a34753fc29733a9e00f1b580eb8bf059db4d4d1a..6040a894067438a283c173344823e9711c3e3a46 100644 (file)
@@ -76,6 +76,9 @@
 #define DELL_SMM_NO_TEMP       10
 #define DELL_SMM_NO_FANS       4
 
+/* limit fan multiplier to avoid overflow */
+#define DELL_SMM_MAX_FAN_MULT (INT_MAX / U16_MAX)
+
 struct smm_regs {
        unsigned int eax;
        unsigned int ebx;
@@ -1253,6 +1256,12 @@ static int dell_smm_init_data(struct device *dev, const struct dell_smm_ops *ops
        data->ops = ops;
        /* All options must not be 0 */
        data->i8k_fan_mult = fan_mult ? : I8K_FAN_MULT;
+       if (data->i8k_fan_mult > DELL_SMM_MAX_FAN_MULT) {
+               dev_err(dev,
+                       "fan multiplier %u is too large (max %u)\n",
+                       data->i8k_fan_mult, DELL_SMM_MAX_FAN_MULT);
+               return -EINVAL;
+       }
        data->i8k_fan_max = fan_max ? : I8K_FAN_HIGH;
        data->i8k_pwm_mult = DIV_ROUND_UP(255, data->i8k_fan_max);