Skip to contentSkip to conversation

hwmon: (mlxreg-fan): Fix out of bounds read on array fan->pwm

PATCH Applied Colin King 2 participants 2 messages Sep 20, 2021 – Sep 24, 2021

Subsystems (2)
lore
Share & tools
lore

Colin King

author
#0 lore raw

PATCH 1/1 hwmon: (mlxreg-fan): Fix out of bounds read on array fan->pwm

From: Colin Ian King <[email protected]>

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")

Fixes 35edbaab3bbf ("hwmon: (mlxreg-fan) Extend driver to support multiply cooling devices")
---
 drivers/hwmon/mlxreg-fan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/mlxreg-fan.c +1 -1
index 35228ed112d7..feab9ec6a6ca 100644
@@ -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)
Signature · 1 line
2.32.0
maintainer Applied
#1 lore raw
Quoted 10 lines · Colin King

From: Colin Ian King <[email protected]>

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")

Fixes 35edbaab3bbf ("hwmon: (mlxreg-fan) Extend driver to support multiply cooling devices")

Applied.

Thanks,
Guenter

Quoted 17 lines
---
 drivers/hwmon/mlxreg-fan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/mlxreg-fan.c +1 -1
index 35228ed112d7..feab9ec6a6ca 100644
@@ -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)