* [PATCH] hv: utils: replace deprecated strcpy with strscpy in kvp_register
@ 2026-04-28 17:11 Thorsten Blum
2026-04-29 22:15 ` Wei Liu
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-04-28 17:11 UTC (permalink / raw)
To: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Long Li
Cc: Thorsten Blum, linux-hyperv, linux-kernel
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>
---
Based on my other patch [1] which needs to be applied first.
[1] https://lore.kernel.org/lkml/20260414111008.307220-2-thorsten.blum@linux.dev/
---
drivers/hv/hv_kvp.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c
index 6180ebe040ff..336b278b2182 100644
--- a/drivers/hv/hv_kvp.c
+++ b/drivers/hv/hv_kvp.c
@@ -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);
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] hv: utils: replace deprecated strcpy with strscpy in kvp_register
2026-04-28 17:11 [PATCH] hv: utils: replace deprecated strcpy with strscpy in kvp_register Thorsten Blum
@ 2026-04-29 22:15 ` Wei Liu
0 siblings, 0 replies; 2+ messages in thread
From: Wei Liu @ 2026-04-29 22:15 UTC (permalink / raw)
To: Thorsten Blum
Cc: K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Long Li,
linux-hyperv, linux-kernel
On Tue, Apr 28, 2026 at 07:11:05PM +0200, Thorsten Blum wrote:
> 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>
Applied. Thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-04-29 22:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28 17:11 [PATCH] hv: utils: replace deprecated strcpy with strscpy in kvp_register Thorsten Blum
2026-04-29 22:15 ` Wei Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox