Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ibmvmc: 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.

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

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/20230927-strncpy-drivers-misc-ibmvmc-c-v1-1-29f56cd3a269@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Justin Stitt and committed by
Greg Kroah-Hartman
2801badd bd4da04c

+1 -3
+1 -3
drivers/misc/ibmvmc.c
··· 1249 1249 return -EIO; 1250 1250 } 1251 1251 1252 - /* Make sure buffer is NULL terminated before trying to print it */ 1253 - memset(print_buffer, 0, HMC_ID_LEN + 1); 1254 - strncpy(print_buffer, hmc->hmc_id, HMC_ID_LEN); 1252 + strscpy(print_buffer, hmc->hmc_id, sizeof(print_buffer)); 1255 1253 pr_info("ibmvmc: sethmcid: Set HMC ID: \"%s\"\n", print_buffer); 1256 1254 1257 1255 memcpy(buffer->real_addr_local, hmc->hmc_id, HMC_ID_LEN);