linux/drivers/virt/acrn
Justin Stitt 61af39e1e4 virt: acrn: replace deprecated strncpy with strscpy
strncpy() is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.

We can see that client->name should be NUL-terminated based on its usage
with a %s C-string format specifier.
|	client->thread = kthread_run(ioreq_task, client, "VM%u-%s",
|					client->vm->vmid, client->name);

NUL-padding is not required as client is already zero-allocated:
|	client = kzalloc(sizeof(*client), GFP_KERNEL);

Considering the above, a suitable replacement is `strscpy` [2] due to
the fact that it guarantees NUL-termination on the destination buffer
without unnecessarily NUL-padding.

Note that this patch relies on the _new_ 2-argument version of strscpy()
introduced in Commit e6584c3964 ("string: Allow 2-argument
strscpy()").

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2]
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/20240320-strncpy-drivers-virt-acrn-ioreq-c-v1-1-db6996770341@google.com
Signed-off-by: Kees Cook <keescook@chromium.org>
2024-04-24 16:44:29 -07:00
..
acrn_drv.h virt: acrn: Annotate struct vm_memory_region_batch with __counted_by 2023-10-08 22:46:04 -07:00
hsm.c x86/cpu: Encapsulate topology information in cpuinfo_x86 2023-10-10 14:38:17 +02:00
hypercall.h virt: acrn: Introduce interfaces for virtual device creating/destroying 2021-10-05 16:14:10 +02:00
ioeventfd.c eventfd: simplify eventfd_signal() 2023-11-28 14:08:38 +01:00
ioreq.c virt: acrn: replace deprecated strncpy with strscpy 2024-04-24 16:44:29 -07:00
irqfd.c virt: acrn: Remove unsued acrn_irqfds_mutex. 2022-03-18 13:49:49 +01:00
Kconfig virt: acrn: Introduce ioeventfd 2021-02-09 10:58:19 +01:00
Makefile virt: acrn: Introduce irqfd 2021-02-09 10:58:19 +01:00
mm.c virt: acrn: Annotate struct vm_memory_region_batch with __counted_by 2023-10-08 22:46:04 -07:00
vm.c virt: acrn: Do hcall_destroy_vm() before resource release 2021-07-27 16:48:45 +02:00