Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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(), and copy directly into '->rf_signature' instead
of using the start of the struct as the destination buffer.

Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strcpy [1]
Link: https://lkml.kernel.org/r/20251118185345.132411-3-thorsten.blum@linux.dev
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Reviewed-by: Joseph Qi <joseph.qi@linux.alibaba.com>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mark@fasheh.com>
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>

authored by

Thorsten Blum and committed by
Andrew Morton
13db54aa 4022ba20

+3 -2
+3 -2
fs/ocfs2/refcounttree.c
··· 34 34 #include <linux/pagevec.h> 35 35 #include <linux/swap.h> 36 36 #include <linux/security.h> 37 + #include <linux/string.h> 37 38 #include <linux/fsnotify.h> 38 39 #include <linux/quotaops.h> 39 40 #include <linux/namei.h> ··· 622 621 /* Initialize ocfs2_refcount_block. */ 623 622 rb = (struct ocfs2_refcount_block *)new_bh->b_data; 624 623 memset(rb, 0, inode->i_sb->s_blocksize); 625 - strcpy((void *)rb, OCFS2_REFCOUNT_BLOCK_SIGNATURE); 624 + strscpy(rb->rf_signature, OCFS2_REFCOUNT_BLOCK_SIGNATURE); 626 625 rb->rf_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot); 627 626 rb->rf_suballoc_loc = cpu_to_le64(suballoc_loc); 628 627 rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start); ··· 1563 1562 /* Initialize ocfs2_refcount_block. */ 1564 1563 new_rb = (struct ocfs2_refcount_block *)new_bh->b_data; 1565 1564 memset(new_rb, 0, sb->s_blocksize); 1566 - strcpy((void *)new_rb, OCFS2_REFCOUNT_BLOCK_SIGNATURE); 1565 + strscpy(new_rb->rf_signature, OCFS2_REFCOUNT_BLOCK_SIGNATURE); 1567 1566 new_rb->rf_suballoc_slot = cpu_to_le16(meta_ac->ac_alloc_slot); 1568 1567 new_rb->rf_suballoc_loc = cpu_to_le64(suballoc_loc); 1569 1568 new_rb->rf_suballoc_bit = cpu_to_le16(suballoc_bit_start);