Skip to content

Commit c152737

Browse files
Abdul Rahimidryomov
authored andcommitted
ceph: Use strscpy() instead of strcpy() in __get_snap_name()
strcpy() performs no bounds checking on the destination buffer. This could result in linear overflows beyond the end of the buffer, leading to all kinds of misbehaviors [1]. This fixes checkpatch warning: WARNING: Prefer strscpy over strcpy [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [ idryomov: formatting ] Signed-off-by: Abdul Rahim <abdul.rahim@myyahoo.com> Reviewed-by: Ilya Dryomov <idryomov@gmail.com> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent e50f960 commit c152737

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fs/ceph/export.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,13 @@ static int __get_snap_name(struct dentry *parent, char *name,
452452
goto out;
453453
if (ceph_snap(inode) == CEPH_SNAPDIR) {
454454
if (ceph_snap(dir) == CEPH_NOSNAP) {
455-
strcpy(name, fsc->mount_options->snapdir_name);
455+
/*
456+
* .get_name() from struct export_operations
457+
* assumes that its 'name' parameter is pointing
458+
* to a NAME_MAX+1 sized buffer
459+
*/
460+
strscpy(name, fsc->mount_options->snapdir_name,
461+
NAME_MAX + 1);
456462
err = 0;
457463
}
458464
goto out;

0 commit comments

Comments
 (0)