Skip to content

Commit 6a22e01

Browse files
azeemshaikh38Dinh Nguyen
authored andcommitted
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] KSPP#89 Reviewed-by: Kees Cook <[email protected]> Signed-off-by: Azeem Shaikh <[email protected]> Signed-off-by: Dinh Nguyen <[email protected]>
1 parent 6ebe94b commit 6a22e01

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

arch/nios2/kernel/cpuinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void __init setup_cpuinfo(void)
4747

4848
str = of_get_property(cpu, "altr,implementation", &len);
4949
if (str)
50-
strlcpy(cpuinfo.cpu_impl, str, sizeof(cpuinfo.cpu_impl));
50+
strscpy(cpuinfo.cpu_impl, str, sizeof(cpuinfo.cpu_impl));
5151
else
5252
strcpy(cpuinfo.cpu_impl, "<unknown>");
5353

arch/nios2/kernel/setup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,18 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
121121
dtb_passed = r6;
122122

123123
if (r7)
124-
strlcpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
124+
strscpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
125125
}
126126
#endif
127127

128128
early_init_devtree((void *)dtb_passed);
129129

130130
#ifndef CONFIG_CMDLINE_FORCE
131131
if (cmdline_passed[0])
132-
strlcpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
132+
strscpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
133133
#ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
134134
else
135-
strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
135+
strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
136136
#endif
137137
#endif
138138

0 commit comments

Comments
 (0)