Skip to contentSkip to conversation

nios2: Replace all non-returning strlcpy with strscpy

PATCH Applied Azeem Shaikh 4 participants 6 messages May 30, 2023 – Jun 21, 2023 NIOS2 architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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/89

---
 arch/nios2/kernel/cpuinfo.c |    2 +-
 arch/nios2/kernel/setup.c   |    6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
arch/nios2/kernel/cpuinfo.c +1 -1
index 203870c4b86d..338849c430a5 100644
@@ -47,7 +47,7 @@ void __init setup_cpuinfo(void)
 
 	str = of_get_property(cpu, "altr,implementation", &len);
 	if (str)
-		strlcpy(cpuinfo.cpu_impl, str, sizeof(cpuinfo.cpu_impl));
+		strscpy(cpuinfo.cpu_impl, str, sizeof(cpuinfo.cpu_impl));
 	else
 		strcpy(cpuinfo.cpu_impl, "<unknown>");
 
arch/nios2/kernel/setup.c +3 -3
index 40bc8fb75e0b..8582ed965844 100644
@@ -121,7 +121,7 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
 		dtb_passed = r6;
 
 		if (r7)
-			strlcpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
+			strscpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
 	}
 #endif
 
@@ -129,10 +129,10 @@ asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
 
 #ifndef CONFIG_CMDLINE_FORCE
 	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
 	else
-		strlcpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
+		strscpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
 #endif
 #endif
 
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Azeem Shaikh

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.

Quoted 4 lines

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

Signature · 1 line
Kees Cook
maintainer Applied
#2 lore raw
Quoted 9 lines · Kees Cook
Quoted 8 lines · Azeem Shaikh

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.

Quoted 7 lines
Quoted 4 lines

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

Applied!

Thanks,
Dinh

#3 lore raw
Quoted 15 lines · Dinh Nguyen
Quoted 12 lines · Kees Cook
Quoted 11 lines · Azeem Shaikh

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

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Applied!

Thanks for taking this patch! I just wanted to double-check, though; I haven't seen it show up in -next yet. Is this still queued?

Thanks!

-Kees

Signature · 1 line
Kees Cook
maintainer
#4 lore raw
Quoted 21 lines · Kees Cook
Quoted 20 lines · Dinh Nguyen
Quoted 16 lines · Kees Cook
Quoted 8 lines · Azeem Shaikh

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.

Quoted 4 lines

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

Quoted 6 lines
Quoted 1 line

Applied!

Thanks for taking this patch! I just wanted to double-check, though; I haven't seen it show up in -next yet. Is this still queued?

Thanks!

I've queued it for v6.5. Do you need it in v6.4?

Dinh

#5 lore raw
Quoted 24 lines · Dinh Nguyen
Quoted 21 lines · Kees Cook
Quoted 20 lines · Dinh Nguyen
Quoted 16 lines · Kees Cook
Quoted 8 lines · Azeem Shaikh

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.

Quoted 4 lines

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

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Applied!

Thanks for taking this patch! I just wanted to double-check, though; I haven't seen it show up in -next yet. Is this still queued?

Thanks!

I've queued it for v6.5. Do you need it in v6.4?

6.5 is fine, yeah. I just wanted to make sure it didn't get lost. :) (I didn't see it in sfr's linux-next merges tree.)

Thanks!

-Kees

Signature · 1 line
Kees Cook