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

ocfs2: replace deprecated strcpy in ocfs2_create_xattr_block

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 '->xb_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-2-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
4022ba20 ff713698

+1 -1
+1 -1
fs/ocfs2/xattr.c
··· 2908 2908 /* Initialize ocfs2_xattr_block */ 2909 2909 xblk = (struct ocfs2_xattr_block *)new_bh->b_data; 2910 2910 memset(xblk, 0, inode->i_sb->s_blocksize); 2911 - strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE); 2911 + strscpy(xblk->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE); 2912 2912 xblk->xb_suballoc_slot = cpu_to_le16(ctxt->meta_ac->ac_alloc_slot); 2913 2913 xblk->xb_suballoc_loc = cpu_to_le64(suballoc_loc); 2914 2914 xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start);