diff options
author | Justin Stitt <justinstitt@google.com> | 2023-09-26 06:59:15 +0000 |
---|---|---|
committer | Kees Cook <keescook@chromium.org> | 2023-10-24 14:10:53 -0700 |
commit | 9cca73d7b4bfec75b2fcef751015f31691afa792 (patch) | |
tree | 2e0641bb71e0c56cd74b87c4f448257dfc77698e | |
parent | fed2ef7abaebe5e0207cd52ae52721ea3da3b5ba (diff) | |
download | linux-9cca73d7b4bfec75b2fcef751015f31691afa792.tar.gz linux-9cca73d7b4bfec75b2fcef751015f31691afa792.tar.bz2 linux-9cca73d7b4bfec75b2fcef751015f31691afa792.zip |
hwmon: (acpi_power_meter) replace open-coded kmemdup_nul
`strncpy` is deprecated for use on NUL-terminated destination strings [1].
Let's refactor this kcalloc() + strncpy() into a kmemdup_nul() which has
more obvious behavior and is less error prone.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://github.com/KSPP/linux/issues/90
Cc: linux-hardening@vger.kernel.org
Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230926-strncpy-drivers-hwmon-acpi_power_meter-c-v5-1-3fc31a9daf99@google.com
Signed-off-by: Kees Cook <keescook@chromium.org>
-rw-r--r-- | drivers/hwmon/acpi_power_meter.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c index fa28d447f0df..8db740214ffd 100644 --- a/drivers/hwmon/acpi_power_meter.c +++ b/drivers/hwmon/acpi_power_meter.c @@ -796,14 +796,13 @@ static int read_capabilities(struct acpi_power_meter_resource *resource) goto error; } - *str = kcalloc(element->string.length + 1, sizeof(u8), - GFP_KERNEL); + *str = kmemdup_nul(element->string.pointer, element->string.length, + GFP_KERNEL); if (!*str) { res = -ENOMEM; goto error; } - strncpy(*str, element->string.pointer, element->string.length); str++; } |