Skip to content

Commit 25be318

Browse files
Alexei Safingroeck
authored andcommitted
hwmon: (asus-ec-sensors) check sensor index in read_string()
Prevent a potential invalid memory access when the requested sensor is not found. find_ec_sensor_index() may return a negative value (e.g. -ENOENT), but its result was used without checking, which could lead to undefined behavior when passed to get_sensor_info(). Add a proper check to return -EINVAL if sensor_index is negative. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: d0ddfd2 ("hwmon: (asus-ec-sensors) add driver for ASUS EC") Signed-off-by: Alexei Safin <[email protected]> Link: https://lore.kernel.org/r/[email protected] [groeck: Return error code returned from find_ec_sensor_index] Signed-off-by: Guenter Roeck <[email protected]>
1 parent a60d965 commit 25be318

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

drivers/hwmon/asus-ec-sensors.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,10 @@ static int asus_ec_hwmon_read_string(struct device *dev,
955955
{
956956
struct ec_sensors_data *state = dev_get_drvdata(dev);
957957
int sensor_index = find_ec_sensor_index(state, type, channel);
958+
959+
if (sensor_index < 0)
960+
return sensor_index;
961+
958962
*str = get_sensor_info(state, sensor_index)->label;
959963

960964
return 0;

0 commit comments

Comments
 (0)