Skip to content

Commit 1f72dd0

Browse files
Dan CarpenterTzung-Bi Shih
authored andcommitted
hwmon: (cros_ec) Prevent read overflow in probe()
The "resp.sensor_name" comes from cros_ec_cmd() and it hasn't necessarily been NUL terminated. We had not intended to read past "sensor_name_size" bytes, however, there is a width vs precision bug in the format string. The format needs to be precision '%.*s' instead of width '%*s'. Precision prevents an out of bounds read, but width is a no-op. Fixes: bc3e452 ("hwmon: add ChromeOS EC driver") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Acked-by: Thomas Weißschuh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent 04ca0a5 commit 1f72dd0

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/hwmon/cros_ec_hwmon.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static void cros_ec_hwmon_probe_temp_sensors(struct device *dev, struct cros_ec_
212212
continue;
213213

214214
sensor_name_size = strnlen(resp.sensor_name, sizeof(resp.sensor_name));
215-
priv->temp_sensor_names[i] = devm_kasprintf(dev, GFP_KERNEL, "%*s",
215+
priv->temp_sensor_names[i] = devm_kasprintf(dev, GFP_KERNEL, "%.*s",
216216
(int)sensor_name_size,
217217
resp.sensor_name);
218218
}

0 commit comments

Comments
 (0)