Skip to content

Commit

Permalink
hwmon: (mlxreg-fan) Fix out of bounds read on array fan->pwm
Browse files Browse the repository at this point in the history
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: 35edbaa ("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>
  • Loading branch information
Colin Ian King authored and groeck committed Oct 12, 2021
1 parent 3fbbfc2 commit 000cc5b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/hwmon/mlxreg-fan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 000cc5b

Please sign in to comment.