public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: (cros_ec) Prevent read overflow in probe()
@ 2024-06-06 13:12 Dan Carpenter
  2024-06-06 14:05 ` Guenter Roeck
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dan Carpenter @ 2024-06-06 13:12 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Thomas Weißschuh, Jean Delvare, Guenter Roeck, Benson Leung,
	Tzung-Bi Shih, chrome-platform, linux-hwmon, linux-kernel,
	kernel-janitors

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>
---
 drivers/hwmon/cros_ec_hwmon.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c
index 41f268fa8260..b3ba7247e06b 100644
--- a/drivers/hwmon/cros_ec_hwmon.c
+++ b/drivers/hwmon/cros_ec_hwmon.c
@@ -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);
 	}
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] hwmon: (cros_ec) Prevent read overflow in probe()
  2024-06-06 13:12 [PATCH] hwmon: (cros_ec) Prevent read overflow in probe() Dan Carpenter
@ 2024-06-06 14:05 ` Guenter Roeck
  2024-06-06 14:30 ` Thomas Weißschuh
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2024-06-06 14:05 UTC (permalink / raw)
  To: Dan Carpenter, Thomas Weißschuh
  Cc: Thomas Weißschuh, Jean Delvare, Benson Leung, Tzung-Bi Shih,
	chrome-platform, linux-hwmon, linux-kernel, kernel-janitors

On 6/6/24 06:12, Dan Carpenter 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")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>   drivers/hwmon/cros_ec_hwmon.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/hwmon/cros_ec_hwmon.c b/drivers/hwmon/cros_ec_hwmon.c
> index 41f268fa8260..b3ba7247e06b 100644
> --- a/drivers/hwmon/cros_ec_hwmon.c
> +++ b/drivers/hwmon/cros_ec_hwmon.c
> @@ -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);
>   	}


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] hwmon: (cros_ec) Prevent read overflow in probe()
  2024-06-06 13:12 [PATCH] hwmon: (cros_ec) Prevent read overflow in probe() Dan Carpenter
  2024-06-06 14:05 ` Guenter Roeck
@ 2024-06-06 14:30 ` Thomas Weißschuh
  2024-06-07 10:10 ` patchwork-bot+chrome-platform
  2024-06-07 10:10 ` patchwork-bot+chrome-platform
  3 siblings, 0 replies; 5+ messages in thread
From: Thomas Weißschuh @ 2024-06-06 14:30 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Jean Delvare, Guenter Roeck, Benson Leung, Tzung-Bi Shih,
	chrome-platform, linux-hwmon, linux-kernel, kernel-janitors

Thanks!

On 2024-06-06 16:12:11+0000, Dan Carpenter 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")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>

Acked-by: Thomas Weißschuh <linux@weissschuh.net>

devm_kstrndup() would have been nice.


Thomas

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] hwmon: (cros_ec) Prevent read overflow in probe()
  2024-06-06 13:12 [PATCH] hwmon: (cros_ec) Prevent read overflow in probe() Dan Carpenter
                   ` (2 preceding siblings ...)
  2024-06-07 10:10 ` patchwork-bot+chrome-platform
@ 2024-06-07 10:10 ` patchwork-bot+chrome-platform
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+chrome-platform @ 2024-06-07 10:10 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: linux, thomas, jdelvare, linux, bleung, tzungbi, chrome-platform,
	linux-hwmon, linux-kernel, kernel-janitors

Hello:

This patch was applied to chrome-platform/linux.git (for-kernelci)
by Tzung-Bi Shih <tzungbi@kernel.org>:

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")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] hwmon: (cros_ec) Prevent read overflow in probe()
  2024-06-06 13:12 [PATCH] hwmon: (cros_ec) Prevent read overflow in probe() Dan Carpenter
  2024-06-06 14:05 ` Guenter Roeck
  2024-06-06 14:30 ` Thomas Weißschuh
@ 2024-06-07 10:10 ` patchwork-bot+chrome-platform
  2024-06-07 10:10 ` patchwork-bot+chrome-platform
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+chrome-platform @ 2024-06-07 10:10 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: linux, thomas, jdelvare, linux, bleung, tzungbi, chrome-platform,
	linux-hwmon, linux-kernel, kernel-janitors

Hello:

This patch was applied to chrome-platform/linux.git (for-next)
by Tzung-Bi Shih <tzungbi@kernel.org>:

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")
> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org>
> 
> [...]

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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-06-07 10:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-06 13:12 [PATCH] hwmon: (cros_ec) Prevent read overflow in probe() Dan Carpenter
2024-06-06 14:05 ` Guenter Roeck
2024-06-06 14:30 ` Thomas Weißschuh
2024-06-07 10:10 ` patchwork-bot+chrome-platform
2024-06-07 10:10 ` patchwork-bot+chrome-platform

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox