mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy()
@ 2025-04-14 22:01 Yacov Simhony
  2025-04-14 22:41 ` Guenter Roeck
  0 siblings, 1 reply; 5+ messages in thread
From: Yacov Simhony @ 2025-04-14 22:01 UTC (permalink / raw)
  To: jdelvare, linux; +Cc: linux-hwmon, linux-kernel, Yacov Simhony

Use strscpy() instead of strcpy() to prevent potential buffer overflows
in acpi_device_name() and acpi_device_class(), which point to fixed-size
buffers.

This change improves safety and aligns with current kernel cleanup efforts.

Signed-off-by: Yacov Simhony <ysimhony@gmail.com>
---
 drivers/hwmon/acpi_power_meter.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 29ccdc2fb..a64497ddb 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -890,8 +890,12 @@ static int acpi_power_meter_add(struct acpi_device *device)
 	resource->sensors_valid = 0;
 	resource->acpi_dev = device;
 	mutex_init(&resource->lock);
-	strcpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
-	strcpy(acpi_device_class(device), ACPI_POWER_METER_CLASS);
+	strscpy(acpi_device_name(device), 
+		ACPI_POWER_METER_DEVICE_NAME,
+	        MAX_ACPI_DEVICE_NAME_LEN);
+	strscpy(acpi_device_class(device), 
+		ACPI_POWER_METER_CLASS,
+		MAX_ACPI_CLASS_NAME_LEN);
 	device->driver_data = resource;
 
 #if IS_REACHABLE(CONFIG_ACPI_IPMI)
-- 
2.47.0


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

* Re: [PATCH] hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy()
  2025-04-14 22:01 [PATCH] hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy() Yacov Simhony
@ 2025-04-14 22:41 ` Guenter Roeck
  0 siblings, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2025-04-14 22:41 UTC (permalink / raw)
  To: Yacov Simhony, jdelvare; +Cc: linux-hwmon, linux-kernel

On 4/14/25 15:01, Yacov Simhony wrote:
> Use strscpy() instead of strcpy() to prevent potential buffer overflows
> in acpi_device_name() and acpi_device_class(), which point to fixed-size
> buffers.
> 
> This change improves safety and aligns with current kernel cleanup efforts.

ACPI_POWER_METER_DEVICE_NAME and ACPI_POWER_METER_CLASS are constant strings.
There is no danger of buffer overflows. There is no safety improvement.

We should concentrate on fixing real problems, not imaginary ones.

Guenter


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

* Re: [PATCH] hwmon: (acpi_power_meter) Replace deprecated strcpy() with strscpy()
  2025-12-20 17:30 [PATCH] hwmon: (acpi_power_meter) Replace " Szymon Wilczek
  2025-12-23  1:31 ` lihuisong (C)
@ 2026-01-12 21:27 ` Guenter Roeck
  1 sibling, 0 replies; 5+ messages in thread
From: Guenter Roeck @ 2026-01-12 21:27 UTC (permalink / raw)
  To: Szymon Wilczek; +Cc: linux-hwmon, linux-kernel

On Sat, Dec 20, 2025 at 06:30:41PM +0100, Szymon Wilczek wrote:
> strcpy() performs no bounds checking on the destination buffer, which
> could result in linear overflows beyond the end of the buffer. Although
> the source strings here are compile-time constants that fit within the
> destination buffers, using strscpy() is the preferred approach as it
> provides bounds checking and aligns with the kernel's deprecated API
> guidelines.
> 
> This change converts the remaining strcpy() calls to strscpy(), matching
> the pattern already used throughout other ACPI drivers in
> drivers/acpi/*.c.
> 
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
> Signed-off-by: Szymon Wilczek <szymonwilczek@gmx.com>
> Reviewed-by: lihuisong@huawei.com

Applied.

Thanks,
Guenter

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

* Re: [PATCH] hwmon: (acpi_power_meter) Replace deprecated strcpy() with strscpy()
  2025-12-20 17:30 [PATCH] hwmon: (acpi_power_meter) Replace " Szymon Wilczek
@ 2025-12-23  1:31 ` lihuisong (C)
  2026-01-12 21:27 ` Guenter Roeck
  1 sibling, 0 replies; 5+ messages in thread
From: lihuisong (C) @ 2025-12-23  1:31 UTC (permalink / raw)
  To: Szymon Wilczek, linux; +Cc: linux-hwmon, linux-kernel


在 2025/12/21 1:30, Szymon Wilczek 写道:
> strcpy() performs no bounds checking on the destination buffer, which
> could result in linear overflows beyond the end of the buffer. Although
> the source strings here are compile-time constants that fit within the
> destination buffers, using strscpy() is the preferred approach as it
> provides bounds checking and aligns with the kernel's deprecated API
> guidelines.
>
> This change converts the remaining strcpy() calls to strscpy(), matching
> the pattern already used throughout other ACPI drivers in
> drivers/acpi/*.c.
>
> Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
> Signed-off-by: Szymon Wilczek <szymonwilczek@gmx.com>
> ---
>   drivers/hwmon/acpi_power_meter.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
> index 29ccdc2fb7ff..cfb30c68bfc5 100644
> --- a/drivers/hwmon/acpi_power_meter.c
> +++ b/drivers/hwmon/acpi_power_meter.c
> @@ -890,8 +890,8 @@ static int acpi_power_meter_add(struct acpi_device *device)
>   	resource->sensors_valid = 0;
>   	resource->acpi_dev = device;
>   	mutex_init(&resource->lock);
> -	strcpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
> -	strcpy(acpi_device_class(device), ACPI_POWER_METER_CLASS);
> +	strscpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
> +	strscpy(acpi_device_class(device), ACPI_POWER_METER_CLASS);
>   	device->driver_data = resource;
>   
>   #if IS_REACHABLE(CONFIG_ACPI_IPMI)
LGTM,
Reviewed-by: lihuisong@huawei.com

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

* [PATCH] hwmon: (acpi_power_meter) Replace deprecated strcpy() with strscpy()
@ 2025-12-20 17:30 Szymon Wilczek
  2025-12-23  1:31 ` lihuisong (C)
  2026-01-12 21:27 ` Guenter Roeck
  0 siblings, 2 replies; 5+ messages in thread
From: Szymon Wilczek @ 2025-12-20 17:30 UTC (permalink / raw)
  To: linux; +Cc: linux-hwmon, linux-kernel, Szymon Wilczek

strcpy() performs no bounds checking on the destination buffer, which
could result in linear overflows beyond the end of the buffer. Although
the source strings here are compile-time constants that fit within the
destination buffers, using strscpy() is the preferred approach as it
provides bounds checking and aligns with the kernel's deprecated API
guidelines.

This change converts the remaining strcpy() calls to strscpy(), matching
the pattern already used throughout other ACPI drivers in
drivers/acpi/*.c.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy
Signed-off-by: Szymon Wilczek <szymonwilczek@gmx.com>
---
 drivers/hwmon/acpi_power_meter.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
index 29ccdc2fb7ff..cfb30c68bfc5 100644
--- a/drivers/hwmon/acpi_power_meter.c
+++ b/drivers/hwmon/acpi_power_meter.c
@@ -890,8 +890,8 @@ static int acpi_power_meter_add(struct acpi_device *device)
 	resource->sensors_valid = 0;
 	resource->acpi_dev = device;
 	mutex_init(&resource->lock);
-	strcpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
-	strcpy(acpi_device_class(device), ACPI_POWER_METER_CLASS);
+	strscpy(acpi_device_name(device), ACPI_POWER_METER_DEVICE_NAME);
+	strscpy(acpi_device_class(device), ACPI_POWER_METER_CLASS);
 	device->driver_data = resource;
 
 #if IS_REACHABLE(CONFIG_ACPI_IPMI)
-- 
2.52.0


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

end of thread, other threads:[~2026-01-12 21:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-14 22:01 [PATCH] hwmon: acpi_power_meter: replace deprecated strcpy() with strscpy() Yacov Simhony
2025-04-14 22:41 ` Guenter Roeck
2025-12-20 17:30 [PATCH] hwmon: (acpi_power_meter) Replace " Szymon Wilczek
2025-12-23  1:31 ` lihuisong (C)
2026-01-12 21:27 ` Guenter Roeck

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

all inboxes | Powered by JetHome®