]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
hv: utils: replace deprecated strcpy with strscpy in kvp_register
authorThorsten Blum <thorsten.blum@linux.dev>
Tue, 28 Apr 2026 17:11:05 +0000 (19:11 +0200)
committerWei Liu <wei.liu@kernel.org>
Wed, 29 Apr 2026 22:15:31 +0000 (22:15 +0000)
strcpy() has been deprecated [1] because it performs no bounds checking
on the destination buffer, which can lead to buffer overflows. While the
current code works correctly, replace strcpy() with the safer strscpy()
to follow secure coding best practices. Use ->body.kvp_register.version
directly as the destination buffer and remove the local variable.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Signed-off-by: Wei Liu <wei.liu@kernel.org>
drivers/hv/hv_kvp.c

index 6180ebe040ff498d1a849edf570881b6c59bb06d..336b278b2182aa0908d61eb8716c9c62eb84afba 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/connector.h>
 #include <linux/workqueue.h>
 #include <linux/hyperv.h>
+#include <linux/string.h>
 #include <hyperv/hvhdk.h>
 
 #include "hyperv_vmbus.h"
@@ -130,18 +131,15 @@ static void kvp_register_done(void)
 static int
 kvp_register(int reg_value)
 {
-
        struct hv_kvp_msg *kvp_msg;
-       char *version;
        int ret;
 
        kvp_msg = kzalloc_obj(*kvp_msg);
        if (!kvp_msg)
                return -ENOMEM;
 
-       version = kvp_msg->body.kvp_register.version;
        kvp_msg->kvp_hdr.operation = reg_value;
-       strcpy(version, HV_DRV_VERSION);
+       strscpy(kvp_msg->body.kvp_register.version, HV_DRV_VERSION);
 
        ret = hvutil_transport_send(hvt, kvp_msg, sizeof(*kvp_msg),
                                    kvp_register_done);