Commit 1f72dd04 authored by Dan Carpenter's avatar Dan Carpenter Committed by Tzung-Bi Shih

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: bc3e4525 ("hwmon: add ChromeOS EC driver")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: default avatarGuenter Roeck <linux@roeck-us.net>
Acked-by: default avatarThomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/42331b70-bd3c-496c-8c79-3ec4faad40b8@moroto.mountainSigned-off-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
parent 04ca0a51
......@@ -212,7 +212,7 @@ static void cros_ec_hwmon_probe_temp_sensors(struct device *dev, struct cros_ec_
continue;
sensor_name_size = strnlen(resp.sensor_name, sizeof(resp.sensor_name));
priv->temp_sensor_names[i] = devm_kasprintf(dev, GFP_KERNEL, "%*s",
priv->temp_sensor_names[i] = devm_kasprintf(dev, GFP_KERNEL, "%.*s",
(int)sensor_name_size,
resp.sensor_name);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment