mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] befs: Replace all non-returning strlcpy with strscpy
@ 2023-05-09  1:41 Azeem Shaikh
  2023-05-22 16:17 ` Azeem Shaikh
  2023-05-23 15:38 ` Kees Cook
  0 siblings, 2 replies; 3+ messages in thread
From: Azeem Shaikh @ 2023-05-09  1:41 UTC (permalink / raw)
  To: keescook, Luis de Bethencourt, Salah Triki; +Cc: Azeem Shaikh, linux-kernel

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.
In an effort to remove strlcpy() completely, 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/befs/btree.c    |    2 +-
 fs/befs/linuxvfs.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/befs/btree.c b/fs/befs/btree.c
index 1b7e0f7128d6..53b36aa29978 100644
--- a/fs/befs/btree.c
+++ b/fs/befs/btree.c
@@ -500,7 +500,7 @@ befs_btree_read(struct super_block *sb, const befs_data_stream *ds,
 		goto error_alloc;
 	}
 
-	strlcpy(keybuf, keystart, keylen + 1);
+	strscpy(keybuf, keystart, keylen + 1);
 	*value = fs64_to_cpu(sb, valarray[cur_key]);
 	*keysize = keylen;
 
diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
index 32749fcee090..eee9237386e2 100644
--- a/fs/befs/linuxvfs.c
+++ b/fs/befs/linuxvfs.c
@@ -374,7 +374,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
 	if (S_ISLNK(inode->i_mode) && !(befs_ino->i_flags & BEFS_LONG_SYMLINK)){
 		inode->i_size = 0;
 		inode->i_blocks = befs_sb->block_size / VFS_BLOCK_SIZE;
-		strlcpy(befs_ino->i_data.symlink, raw_inode->data.symlink,
+		strscpy(befs_ino->i_data.symlink, raw_inode->data.symlink,
 			BEFS_SYMLINK_LEN);
 	} else {
 		int num_blks;


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

* Re: [PATCH] befs: Replace all non-returning strlcpy with strscpy
  2023-05-09  1:41 [PATCH] befs: Replace all non-returning strlcpy with strscpy Azeem Shaikh
@ 2023-05-22 16:17 ` Azeem Shaikh
  2023-05-23 15:38 ` Kees Cook
  1 sibling, 0 replies; 3+ messages in thread
From: Azeem Shaikh @ 2023-05-22 16:17 UTC (permalink / raw)
  To: keescook, Luis de Bethencourt, Salah Triki; +Cc: linux-kernel

Friendly ping.

On Mon, May 8, 2023 at 9:41 PM Azeem Shaikh <azeemshaikh38@gmail.com> 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.
> In an effort to remove strlcpy() completely, 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/befs/btree.c    |    2 +-
>  fs/befs/linuxvfs.c |    2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/befs/btree.c b/fs/befs/btree.c
> index 1b7e0f7128d6..53b36aa29978 100644
> --- a/fs/befs/btree.c
> +++ b/fs/befs/btree.c
> @@ -500,7 +500,7 @@ befs_btree_read(struct super_block *sb, const befs_data_stream *ds,
>                 goto error_alloc;
>         }
>
> -       strlcpy(keybuf, keystart, keylen + 1);
> +       strscpy(keybuf, keystart, keylen + 1);
>         *value = fs64_to_cpu(sb, valarray[cur_key]);
>         *keysize = keylen;
>
> diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
> index 32749fcee090..eee9237386e2 100644
> --- a/fs/befs/linuxvfs.c
> +++ b/fs/befs/linuxvfs.c
> @@ -374,7 +374,7 @@ static struct inode *befs_iget(struct super_block *sb, unsigned long ino)
>         if (S_ISLNK(inode->i_mode) && !(befs_ino->i_flags & BEFS_LONG_SYMLINK)){
>                 inode->i_size = 0;
>                 inode->i_blocks = befs_sb->block_size / VFS_BLOCK_SIZE;
> -               strlcpy(befs_ino->i_data.symlink, raw_inode->data.symlink,
> +               strscpy(befs_ino->i_data.symlink, raw_inode->data.symlink,
>                         BEFS_SYMLINK_LEN);
>         } else {
>                 int num_blks;
>

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

* Re: [PATCH] befs: Replace all non-returning strlcpy with strscpy
  2023-05-09  1:41 [PATCH] befs: Replace all non-returning strlcpy with strscpy Azeem Shaikh
  2023-05-22 16:17 ` Azeem Shaikh
@ 2023-05-23 15:38 ` Kees Cook
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-05-23 15:38 UTC (permalink / raw)
  To: azeemshaikh38, salah.triki, Kees Cook, luisbg; +Cc: linux-kernel

On Tue, 9 May 2023 01:41:36 +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.
> In an effort to remove strlcpy() completely, replace
> strlcpy() here with strscpy().
> No return values were used, so direct replacement is safe.
> 
> [...]

Applied to for-next/hardening, thanks!

[1/1] befs: Replace all non-returning strlcpy with strscpy
      https://git.kernel.org/kees/c/35ba10a47326

-- 
Kees Cook


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

end of thread, other threads:[~2023-05-23 15:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-09  1:41 [PATCH] befs: Replace all non-returning strlcpy with strscpy Azeem Shaikh
2023-05-22 16:17 ` Azeem Shaikh
2023-05-23 15:38 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®