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

ext4: use memtostr_pad() for s_volume_name

As with the other strings in struct ext4_super_block, s_volume_name is
not NUL terminated. The other strings were marked in commit 072ebb3bffe6
("ext4: add nonstring annotations to ext4.h"). Using strscpy() isn't
the right replacement for strncpy(); it should use memtostr_pad()
instead.

Reported-by: syzbot+50835f73143cc2905b9e@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/00000000000019f4c00619192c05@google.com/
Fixes: 744a56389f73 ("ext4: replace deprecated strncpy with alternatives")
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://patch.msgid.link/20240523225408.work.904-kees@kernel.org
Signed-off-by: Theodore Ts'o <tytso@mit.edu>

authored by

Kees Cook and committed by
Theodore Ts'o
be27cd64 7c73ddb7

+2 -2
+1 -1
fs/ext4/ext4.h
··· 1347 1347 /*60*/ __le32 s_feature_incompat; /* incompatible feature set */ 1348 1348 __le32 s_feature_ro_compat; /* readonly-compatible feature set */ 1349 1349 /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */ 1350 - /*78*/ char s_volume_name[EXT4_LABEL_MAX]; /* volume name */ 1350 + /*78*/ char s_volume_name[EXT4_LABEL_MAX] __nonstring; /* volume name */ 1351 1351 /*88*/ char s_last_mounted[64] __nonstring; /* directory where last mounted */ 1352 1352 /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */ 1353 1353 /*
+1 -1
fs/ext4/ioctl.c
··· 1151 1151 BUILD_BUG_ON(EXT4_LABEL_MAX >= FSLABEL_MAX); 1152 1152 1153 1153 lock_buffer(sbi->s_sbh); 1154 - strscpy_pad(label, sbi->s_es->s_volume_name); 1154 + memtostr_pad(label, sbi->s_es->s_volume_name); 1155 1155 unlock_buffer(sbi->s_sbh); 1156 1156 1157 1157 if (copy_to_user(user_label, label, sizeof(label)))