* [PATCH] parisc: Replace strlcpy() with strscpy()
@ 2023-11-16 19:13 Kees Cook
2023-11-17 14:48 ` Helge Deller
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2023-11-16 19:13 UTC (permalink / raw)
To: James E.J. Bottomley
Cc: Kees Cook, Helge Deller, Azeem Shaikh, linux-parisc, linux-kernel,
linux-hardening
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 [1]
Link: https://github.com/KSPP/linux/issues/89 [2]
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>
---
arch/parisc/kernel/processor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/parisc/kernel/processor.c b/arch/parisc/kernel/processor.c
index 29e2750f86a4..e95a977ba5f3 100644
--- a/arch/parisc/kernel/processor.c
+++ b/arch/parisc/kernel/processor.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] parisc: Replace strlcpy() with strscpy()
2023-11-16 19:13 [PATCH] parisc: Replace strlcpy() with strscpy() Kees Cook
@ 2023-11-17 14:48 ` Helge Deller
0 siblings, 0 replies; 2+ messages in thread
From: Helge Deller @ 2023-11-17 14:48 UTC (permalink / raw)
To: Kees Cook, James E.J. Bottomley
Cc: Azeem Shaikh, linux-parisc, linux-kernel, linux-hardening
On 11/16/23 20:13, Kees Cook wrote:
> 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 [1]
> Link: https://github.com/KSPP/linux/issues/89 [2]
> 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>
applied.
Thanks!
Helge
> ---
> arch/parisc/kernel/processor.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/parisc/kernel/processor.c b/arch/parisc/kernel/processor.c
> index 29e2750f86a4..e95a977ba5f3 100644
> --- a/arch/parisc/kernel/processor.c
> +++ b/arch/parisc/kernel/processor.c
> @@ -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;
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-11-17 14:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-16 19:13 [PATCH] parisc: Replace strlcpy() with strscpy() Kees Cook
2023-11-17 14:48 ` Helge Deller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox