]> www.infradead.org Git - users/hch/configfs.git/commitdiff
hwmon: (cros_ec) Prevent read overflow in probe()
authorDan Carpenter <dan.carpenter@linaro.org>
Thu, 6 Jun 2024 13:12:11 +0000 (16:12 +0300)
committerTzung-Bi Shih <tzungbi@kernel.org>
Fri, 7 Jun 2024 09:57:44 +0000 (09:57 +0000)
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: bc3e45258096 ("hwmon: add ChromeOS EC driver")
Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
Reviewed-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/42331b70-bd3c-496c-8c79-3ec4faad40b8@moroto.mountain
Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org>
drivers/hwmon/cros_ec_hwmon.c

index 41f268fa826098e905b08d67e247f51945d2e4b5..b3ba7247e06b2b16018cef6bf6330f1b6cf23cf4 100644 (file)
@@ -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);
        }