ceph: Use strscpy() instead of strcpy()
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH v2 1/1 ceph: Use strscpy() instead of strcpy()
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
---
Changes since v1:
- Added third parameter in strscpy()
- Added comment to explain where the limit NAME_MAX+1 is comming from as suggested by Christophe JAILLET <[email protected]>
Link to v1: https://lore.kernel.org/lkml/[email protected]/
The function __get_snap_name() is assigned to .get_name() from struct export_operations, when ceph_snap(inode) != CEPH_NOSNAP. struct export_operations is comming from include/linux/exportfs.h, and according to [1], the operation get_name assumes that the variable name is pointing to a buffer of size NAME_MAX+1
fs/ceph/export.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/ceph/export.c +5 -1
@@ -452,7 +452,11 @@ 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;
Signature · 1 line
2.43.0
Ilya Dryomov
maintainerQuoted 47 lines · Abdul Rahim
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
Signed-off-by Abdul Rahim <[email protected]>---
Changes since v1:
- Added third parameter instrscpy()
- Added comment to explain where the limitNAME_MAX+1is comming from as suggested by Christophe JAILLET <[email protected]>Link to v1: https://lore.kernel.org/lkml/[email protected]/
The function
__get_snap_name()is assigned to .get_name() from structexport_operations, whenceph_snap(inode) != CEPH_NOSNAP.struct export_operationsis comming frominclude/linux/exportfs.h, and according to [1], the operationget_nameassumes that the variablenameis pointing to a buffer of size NAME_MAX+1fs/ceph/export.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)fs/ceph/export.c +5
-2@@ -452,7 +452,11 @@ 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; --
Quoted 2 lines
2.43.0
Applied with minor formatting tweaks.
Thanks,
Ilya