Skip to content

Commit

Permalink
ceph: Use strscpy() instead of strcpy() in __get_snap_name()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Abdul Rahim authored and Ilya Dryomov committed Nov 18, 2024
1 parent e50f960 commit c152737
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion fs/ceph/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,13 @@ static int __get_snap_name(struct dentry *parent, char *name,
goto out;
if (ceph_snap(inode) == CEPH_SNAPDIR) {
if (ceph_snap(dir) == CEPH_NOSNAP) {
strcpy(name, fsc->mount_options->snapdir_name);
/*
* .get_name() from struct export_operations
* assumes that its 'name' parameter is pointing
* to a NAME_MAX+1 sized buffer
*/
strscpy(name, fsc->mount_options->snapdir_name,
NAME_MAX + 1);
err = 0;
}
goto out;
Expand Down

0 comments on commit c152737

Please sign in to comment.