befs: Replace all non-returning strlcpy with strscpy
authorAzeem Shaikh <azeemshaikh38@gmail.com>
Tue, 9 May 2023 01:41:36 +0000 (01:41 +0000)
committerKees Cook <keescook@chromium.org>
Tue, 30 May 2023 23:42:00 +0000 (16:42 -0700)
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>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20230509014136.2095900-1-azeemshaikh38@gmail.com
fs/befs/btree.c
fs/befs/linuxvfs.c

index 1b7e0f7..53b36aa 100644 (file)
@@ -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;
 
index 32749fc..eee9237 100644 (file)
@@ -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;