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

sparc64: Replace all non-returning strlcpy with strscpy

strlcpy() reads the entire source buffer first.
This read may exceed the destination size limit.
This is both inefficient and can lead to linear read
overflows if a source string is not NUL-terminated [1].
In an effort to remove strlcpy() completely [2], replace
strlcpy() here with strscpy().
No return values were used, so direct replacement is safe.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
[2] https://github.com/KSPP/linux/issues/89

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230530163001.985256-1-azeemshaikh38@gmail.com

authored by

Azeem Shaikh and committed by
Kees Cook
bb07972f f0e212de

+4 -4
+1 -1
arch/sparc/kernel/ioport.c
··· 191 191 tack += sizeof (struct resource); 192 192 } 193 193 194 - strlcpy(tack, name, XNMLN+1); 194 + strscpy(tack, name, XNMLN+1); 195 195 res->name = tack; 196 196 197 197 va = _sparc_ioremap(res, busno, phys, size);
+1 -1
arch/sparc/kernel/setup_32.c
··· 302 302 303 303 /* Initialize PROM console and command line. */ 304 304 *cmdline_p = prom_getbootargs(); 305 - strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE); 305 + strscpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE); 306 306 parse_early_param(); 307 307 308 308 boot_flags_init(*cmdline_p);
+1 -1
arch/sparc/kernel/setup_64.c
··· 636 636 { 637 637 /* Initialize PROM console and command line. */ 638 638 *cmdline_p = prom_getbootargs(); 639 - strlcpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE); 639 + strscpy(boot_command_line, *cmdline_p, COMMAND_LINE_SIZE); 640 640 parse_early_param(); 641 641 642 642 boot_flags_init(*cmdline_p);
+1 -1
arch/sparc/prom/bootstr_32.c
··· 52 52 * V3 PROM cannot supply as with more than 128 bytes 53 53 * of an argument. But a smart bootstrap loader can. 54 54 */ 55 - strlcpy(barg_buf, *romvec->pv_v2bootargs.bootargs, sizeof(barg_buf)); 55 + strscpy(barg_buf, *romvec->pv_v2bootargs.bootargs, sizeof(barg_buf)); 56 56 break; 57 57 default: 58 58 break;