Skip to content

Commit c642256

Browse files
azeemshaikh38brauner
authored andcommitted
vfs: 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 [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] KSPP#89 Signed-off-by: Azeem Shaikh <azeemshaikh38@gmail.com> Reviewed-by: Kees Cook <keescook@chromium.org> Message-Id: <20230510221119.3508930-1-azeemshaikh38@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 38f1755 commit c642256

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

fs/char_dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ __register_chrdev_region(unsigned int major, unsigned int baseminor,
150150
cd->major = major;
151151
cd->baseminor = baseminor;
152152
cd->minorct = minorct;
153-
strlcpy(cd->name, name, sizeof(cd->name));
153+
strscpy(cd->name, name, sizeof(cd->name));
154154

155155
if (!prev) {
156156
cd->next = curr;

fs/super.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ struct super_block *sget_fc(struct fs_context *fc,
595595
fc->s_fs_info = NULL;
596596
s->s_type = fc->fs_type;
597597
s->s_iflags |= fc->s_iflags;
598-
strlcpy(s->s_id, s->s_type->name, sizeof(s->s_id));
598+
strscpy(s->s_id, s->s_type->name, sizeof(s->s_id));
599599
list_add_tail(&s->s_list, &super_blocks);
600600
hlist_add_head(&s->s_instances, &s->s_type->fs_supers);
601601
spin_unlock(&sb_lock);
@@ -674,7 +674,7 @@ struct super_block *sget(struct file_system_type *type,
674674
return ERR_PTR(err);
675675
}
676676
s->s_type = type;
677-
strlcpy(s->s_id, type->name, sizeof(s->s_id));
677+
strscpy(s->s_id, type->name, sizeof(s->s_id));
678678
list_add_tail(&s->s_list, &super_blocks);
679679
hlist_add_head(&s->s_instances, &type->fs_supers);
680680
spin_unlock(&sb_lock);

0 commit comments

Comments
 (0)