parisc: Replace strlcpy() with strscpy()
authorKees Cook <keescook@chromium.org>
Thu, 16 Nov 2023 19:13:40 +0000 (11:13 -0800)
committerHelge Deller <deller@gmx.de>
Sat, 18 Nov 2023 17:59:28 +0000 (18:59 +0100)
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().

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy
Link: https://github.com/KSPP/linux/issues/89
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Azeem Shaikh <azeemshaikh38@gmail.com>
Cc: linux-parisc@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Helge Deller <deller@gmx.de>
arch/parisc/kernel/processor.c

index 29e2750f86a410f58da62d30ccc4e25f2e901908..e95a977ba5f376eb813d4c7806d205a92f539880 100644 (file)
@@ -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;