Skip to contentSkip to conversation

parisc: Replace strlcpy() with strscpy()

PATCH Applied Kees Cook 2 participants 2 messages Nov 16, 2023 – Nov 17, 2023 PA-RISC architecture

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 parisc: Replace 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]. Additionally, it returns the size of the source string, not the resulting size of the destination string. In an effort to remove strlcpy() completely[2], replace strlcpy() here with strscpy().

---
 arch/parisc/kernel/processor.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/processor.c +1 -1
index 29e2750f86a4..e95a977ba5f3 100644
@@ -383,7 +383,7 @@ show_cpuinfo (struct seq_file *m, void *v)
 	char cpu_name[60], *p;
 
 	/* strip PA path from CPU name to not confuse lscpu */
-	strlcpy(cpu_name, per_cpu(cpu_data, 0).dev->name, sizeof(cpu_name));
+	strscpy(cpu_name, per_cpu(cpu_data, 0).dev->name, sizeof(cpu_name));
 	p = strrchr(cpu_name, '[');
 	if (p)
 		*(--p) = 0;
Signature · 1 line
2.34.1
maintainer Applied
#1 lore raw
Quoted 7 lines · Kees Cook

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]. Additionally, it returns the size of the source string, not the resulting size of the destination string. In an effort to remove strlcpy() completely[2], replace strlcpy() here with strscpy().

Quoted 7 lines

applied.

Thanks!
Helge

Quoted 17 lines
---
  arch/parisc/kernel/processor.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/processor.c +1 -1
index 29e2750f86a4..e95a977ba5f3 100644
@@ -383,7 +383,7 @@ show_cpuinfo (struct seq_file *m, void *v)
  	char cpu_name[60], *p;
 
  	/* strip PA path from CPU name to not confuse lscpu */
-	strlcpy(cpu_name, per_cpu(cpu_data, 0).dev->name, sizeof(cpu_name));
+	strscpy(cpu_name, per_cpu(cpu_data, 0).dev->name, sizeof(cpu_name));
  	p = strrchr(cpu_name, '[');
  	if (p)
  		*(--p) = 0;