befs: Replace all non-returning strlcpy with strscpy
PATCH 1/1 befs: Replace all non-returning 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. 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
--- fs/befs/btree.c | 2 +- fs/befs/linuxvfs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/befs/btree.c +1 -1
@@ -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;
fs/befs/linuxvfs.c +1 -1
@@ -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;
Friendly ping.
Quoted 45 lines · Azeem Shaikh
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 removestrlcpy()completely, replacestrlcpy()here withstrscpy().
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/89Signed-off-by Azeem Shaikh <[email protected]>--- fs/befs/btree.c | 2 +- fs/befs/linuxvfs.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/befs/btree.c +1
-1@@ -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;fs/befs/linuxvfs.c +1
-1@@ -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;
Kees Cook
AppliedQuoted 9 lines · Azeem Shaikh
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 removestrlcpy()completely, replacestrlcpy()here withstrscpy().
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
Signature · 1 line
Kees Cook