Skip to content

Commit d86fea4

Browse files
tobluxakpm00
authored andcommitted
ocfs2: replace deprecated strcpy with strscpy
strcpy() has been deprecated [1] because it performs no bounds checking on the destination buffer, which can lead to buffer overflows. Replace it with the safer strscpy(). No functional changes. Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1] Link: https://lkml.kernel.org/r/20251126114419.92539-1-thorsten.blum@linux.dev Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev> Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com> Cc: Mark Fasheh <mark@fasheh.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Junxiao Bi <junxiao.bi@oracle.com> Cc: Changwei Ge <gechangwei@live.cn> Cc: Jun Piao <piaojun@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent 4ac577a commit d86fea4

6 files changed

Lines changed: 16 additions & 11 deletions

File tree

fs/ocfs2/alloc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/fs.h>
1111
#include <linux/types.h>
1212
#include <linux/slab.h>
13+
#include <linux/string.h>
1314
#include <linux/highmem.h>
1415
#include <linux/swap.h>
1516
#include <linux/quotaops.h>
@@ -1037,7 +1038,7 @@ static int ocfs2_create_new_meta_bhs(handle_t *handle,
10371038
memset(bhs[i]->b_data, 0, osb->sb->s_blocksize);
10381039
eb = (struct ocfs2_extent_block *) bhs[i]->b_data;
10391040
/* Ok, setup the minimal stuff here. */
1040-
strcpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE);
1041+
strscpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE);
10411042
eb->h_blkno = cpu_to_le64(first_blkno);
10421043
eb->h_fs_generation = cpu_to_le32(osb->fs_generation);
10431044
eb->h_suballoc_slot =
@@ -6746,7 +6747,7 @@ static int ocfs2_reuse_blk_from_dealloc(handle_t *handle,
67466747
/* We can't guarantee that buffer head is still cached, so
67476748
* polutlate the extent block again.
67486749
*/
6749-
strcpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE);
6750+
strscpy(eb->h_signature, OCFS2_EXTENT_BLOCK_SIGNATURE);
67506751
eb->h_blkno = cpu_to_le64(bf->free_blk);
67516752
eb->h_fs_generation = cpu_to_le32(osb->fs_generation);
67526753
eb->h_suballoc_slot = cpu_to_le16(real_slot);

fs/ocfs2/cluster/nodemanager.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <linux/slab.h>
7+
#include <linux/string.h>
78
#include <linux/kernel.h>
89
#include <linux/module.h>
910
#include <linux/configfs.h>
@@ -590,7 +591,7 @@ static struct config_item *o2nm_node_group_make_item(struct config_group *group,
590591
if (node == NULL)
591592
return ERR_PTR(-ENOMEM);
592593

593-
strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */
594+
strscpy(node->nd_name, name); /* use item.ci_namebuf instead? */
594595
config_item_init_type_name(&node->nd_item, name, &o2nm_node_type);
595596
spin_lock_init(&node->nd_lock);
596597

fs/ocfs2/dir.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ static void ocfs2_init_dir_trailer(struct inode *inode,
136136
struct ocfs2_dir_block_trailer *trailer;
137137

138138
trailer = ocfs2_trailer_from_bh(bh, inode->i_sb);
139-
strcpy(trailer->db_signature, OCFS2_DIR_TRAILER_SIGNATURE);
139+
strscpy(trailer->db_signature, OCFS2_DIR_TRAILER_SIGNATURE);
140140
trailer->db_compat_rec_len =
141141
cpu_to_le16(sizeof(struct ocfs2_dir_block_trailer));
142142
trailer->db_parent_dinode = cpu_to_le64(OCFS2_I(inode)->ip_blkno);
@@ -2213,14 +2213,14 @@ static struct ocfs2_dir_entry *ocfs2_fill_initial_dirents(struct inode *inode,
22132213
de->name_len = 1;
22142214
de->rec_len =
22152215
cpu_to_le16(OCFS2_DIR_REC_LEN(de->name_len));
2216-
strcpy(de->name, ".");
2216+
strscpy(de->name, ".");
22172217
ocfs2_set_de_type(de, S_IFDIR);
22182218

22192219
de = (struct ocfs2_dir_entry *) ((char *)de + le16_to_cpu(de->rec_len));
22202220
de->inode = cpu_to_le64(OCFS2_I(parent)->ip_blkno);
22212221
de->rec_len = cpu_to_le16(size - OCFS2_DIR_REC_LEN(1));
22222222
de->name_len = 2;
2223-
strcpy(de->name, "..");
2223+
strscpy(de->name, "..");
22242224
ocfs2_set_de_type(de, S_IFDIR);
22252225

22262226
return de;
@@ -2378,7 +2378,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,
23782378

23792379
dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data;
23802380
memset(dx_root, 0, osb->sb->s_blocksize);
2381-
strcpy(dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE);
2381+
strscpy(dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE);
23822382
dx_root->dr_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot);
23832383
dx_root->dr_suballoc_loc = cpu_to_le64(suballoc_loc);
23842384
dx_root->dr_suballoc_bit = cpu_to_le16(dr_suballoc_bit);
@@ -2454,7 +2454,7 @@ static int ocfs2_dx_dir_format_cluster(struct ocfs2_super *osb,
24542454
dx_leaf = (struct ocfs2_dx_leaf *) bh->b_data;
24552455

24562456
memset(dx_leaf, 0, osb->sb->s_blocksize);
2457-
strcpy(dx_leaf->dl_signature, OCFS2_DX_LEAF_SIGNATURE);
2457+
strscpy(dx_leaf->dl_signature, OCFS2_DX_LEAF_SIGNATURE);
24582458
dx_leaf->dl_fs_generation = cpu_to_le32(osb->fs_generation);
24592459
dx_leaf->dl_blkno = cpu_to_le64(bh->b_blocknr);
24602460
dx_leaf->dl_list.de_count =

fs/ocfs2/namei.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/fs.h>
2424
#include <linux/types.h>
2525
#include <linux/slab.h>
26+
#include <linux/string.h>
2627
#include <linux/highmem.h>
2728
#include <linux/quotaops.h>
2829
#include <linux/iversion.h>
@@ -568,7 +569,7 @@ static int __ocfs2_mknod_locked(struct inode *dir,
568569
ocfs2_set_links_count(fe, inode->i_nlink);
569570

570571
fe->i_last_eb_blk = 0;
571-
strcpy(fe->i_signature, OCFS2_INODE_SIGNATURE);
572+
strscpy(fe->i_signature, OCFS2_INODE_SIGNATURE);
572573
fe->i_flags |= cpu_to_le32(OCFS2_VALID_FL);
573574
ktime_get_coarse_real_ts64(&ts);
574575
fe->i_atime = fe->i_ctime = fe->i_mtime =

fs/ocfs2/stackglue.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <linux/list.h>
1212
#include <linux/spinlock.h>
13+
#include <linux/string.h>
1314
#include <linux/module.h>
1415
#include <linux/slab.h>
1516
#include <linux/kmod.h>
@@ -670,7 +671,7 @@ static int __init ocfs2_stack_glue_init(void)
670671
{
671672
int ret;
672673

673-
strcpy(cluster_stack_name, OCFS2_STACK_PLUGIN_O2CB);
674+
strscpy(cluster_stack_name, OCFS2_STACK_PLUGIN_O2CB);
674675

675676
ocfs2_table_header = register_sysctl("fs/ocfs2/nm", ocfs2_nm_table);
676677
if (!ocfs2_table_header) {

fs/ocfs2/suballoc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/fs.h>
1212
#include <linux/types.h>
1313
#include <linux/slab.h>
14+
#include <linux/string.h>
1415
#include <linux/highmem.h>
1516

1617
#include <cluster/masklog.h>
@@ -372,7 +373,7 @@ static int ocfs2_block_group_fill(handle_t *handle,
372373
}
373374

374375
memset(bg, 0, sb->s_blocksize);
375-
strcpy(bg->bg_signature, OCFS2_GROUP_DESC_SIGNATURE);
376+
strscpy(bg->bg_signature, OCFS2_GROUP_DESC_SIGNATURE);
376377
bg->bg_generation = cpu_to_le32(osb->fs_generation);
377378
bg->bg_size = cpu_to_le16(ocfs2_group_bitmap_size(sb, 1,
378379
osb->s_feature_incompat));

0 commit comments

Comments
 (0)