]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
hwmon: (mlxreg-fan) Fix out of bounds read on array fan->pwm
authorColin Ian King <colin.king@canonical.com>
Mon, 20 Sep 2021 18:09:21 +0000 (19:09 +0100)
committerGuenter Roeck <linux@roeck-us.net>
Tue, 12 Oct 2021 14:22:38 +0000 (07:22 -0700)
Array fan->pwm[] is MLXREG_FAN_MAX_PWM elements in size, however the
for-loop has a off-by-one error causing index i to be out of range
causing an out of bounds read on the array. Fix this by replacing
the <= operator with < in the for-loop.

Addresses-Coverity: ("Out-of-bounds read")
Reported-by: Vadim Pasternak <vadimp@nvidia.com>
Fixes: 35edbaab3bbf ("hwmon: (mlxreg-fan) Extend driver to support multiply cooling devices")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Link: https://lore.kernel.org/r/20210920180921.16246-1-colin.king@canonical.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/mlxreg-fan.c

index 35228ed112d77e1e6fbfad99c67eb2b58b72a415..feab9ec6a6cae099e9d61c351ae4477898770bc9 100644 (file)
@@ -554,7 +554,7 @@ static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan)
 {
        int i, j;
 
-       for (i = 0; i <= MLXREG_FAN_MAX_PWM; i++) {
+       for (i = 0; i < MLXREG_FAN_MAX_PWM; i++) {
                struct mlxreg_fan_pwm *pwm = &fan->pwm[i];
 
                if (!pwm->connected)