linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] procfs: Replace all non-returning strlcpy with strscpy
@ 2023-05-10 21:24 Azeem Shaikh
  2023-05-11 16:25 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Azeem Shaikh @ 2023-05-10 21:24 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-hardening, Azeem Shaikh, linux-fsdevel, Andrew Morton,
	Lorenzo Stoakes, Baoquan He, David Hildenbrand, Liu Shixin,
	Kefeng Wang

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

Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>
---
 fs/proc/kcore.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 25b44b303b35..5d0cf59c4926 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -419,7 +419,7 @@ static ssize_t read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter)
 		char *notes;
 		size_t i = 0;
 
-		strlcpy(prpsinfo.pr_psargs, saved_command_line,
+		strscpy(prpsinfo.pr_psargs, saved_command_line,
 			sizeof(prpsinfo.pr_psargs));
 
 		notes = kzalloc(notes_len, GFP_KERNEL);


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] procfs: Replace all non-returning strlcpy with strscpy
  2023-05-10 21:24 [PATCH] procfs: Replace all non-returning strlcpy with strscpy Azeem Shaikh
@ 2023-05-11 16:25 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2023-05-11 16:25 UTC (permalink / raw)
  To: Azeem Shaikh
  Cc: linux-kernel, linux-hardening, linux-fsdevel, Andrew Morton,
	Lorenzo Stoakes, Baoquan He, David Hildenbrand, Liu Shixin,
	Kefeng Wang

On Wed, May 10, 2023 at 09:24:57PM +0000, Azeem Shaikh 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].
> 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
> 
> Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-11 16:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-10 21:24 [PATCH] procfs: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-11 16:25 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).