Commit 6a22e017 authored by Azeem Shaikh's avatar Azeem Shaikh Committed by Dinh Nguyen

nios2: 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/89Reviewed-by: default avatarKees Cook <keescook@chromium.org>
Signed-off-by: default avatarAzeem Shaikh <azeemshaikh38@gmail.com>
Signed-off-by: default avatarDinh Nguyen <dinguyen@kernel.org>
parent 6ebe94ba
...@@ -47,7 +47,7 @@ void __init setup_cpuinfo(void) ...@@ -47,7 +47,7 @@ void __init setup_cpuinfo(void)
str = of_get_property(cpu, "altr,implementation", &len); str = of_get_property(cpu, "altr,implementation", &len);
if (str) if (str)
strlcpy(cpuinfo.cpu_impl, str, sizeof(cpuinfo.cpu_impl)); strscpy(cpuinfo.cpu_impl, str, sizeof(cpuinfo.cpu_impl));
else else
strcpy(cpuinfo.cpu_impl, "<unknown>"); strcpy(cpuinfo.cpu_impl, "<unknown>");
......
...@@ -121,7 +121,7 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6, ...@@ -121,7 +121,7 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
dtb_passed = r6; dtb_passed = r6;
if (r7) if (r7)
strlcpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE); strscpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
} }
#endif #endif
...@@ -129,10 +129,10 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6, ...@@ -129,10 +129,10 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
#ifndef CONFIG_CMDLINE_FORCE #ifndef CONFIG_CMDLINE_FORCE
if (cmdline_passed[0]) if (cmdline_passed[0])
strlcpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE); strscpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
#ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB #ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
else else
strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
#endif #endif
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment