Skip to contentSkip to conversation

hwmon: (cros_ec) Prevent read overflow in probe()

PATCH Applied Dan Carpenter 4 participants 5 messages Jun 6, 2024 – Jun 7, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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 bc3e45258096 ("hwmon: add ChromeOS EC driver")
---
 drivers/hwmon/cros_ec_hwmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/cros_ec_hwmon.c +1 -1
index 41f268fa8260..b3ba7247e06b 100644
@@ -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);
 	}
Signature · 1 line
2.43.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dan Carpenter

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")
Quoted 17 lines
---
  drivers/hwmon/cros_ec_hwmon.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/cros_ec_hwmon.c +1 -1
index 41f268fa8260..b3ba7247e06b 100644
@@ -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);
  	}
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter

Thanks!

Quoted 8 lines · Dan Carpenter

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

devm_kstrndup() would have been nice.

Thomas

#3 lore raw
In reply to Dan Carpenter
This patch was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-kernelci) by Tzung-Bi Shih <[email protected]>:

Quoted 10 lines · On Thu, 6 Jun 2024 16:12:11 +0300 you wrote:

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

[...]

Here is the summary with links:
- hwmon: (cros_ec) Prevent read overflow in probe()

    https://git.kernel.org/chrome-platform/c/1f72dd046270

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#4 lore raw
In reply to Dan Carpenter
This patch was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Hello:

This patch was applied to chrome-platform/linux.git (for-next) by Tzung-Bi Shih <[email protected]>:

Quoted 10 lines · On Thu, 6 Jun 2024 16:12:11 +0300 you wrote:

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

[...]

Here is the summary with links:
- hwmon: (cros_ec) Prevent read overflow in probe()

    https://git.kernel.org/chrome-platform/c/1f72dd046270

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html