Skip to content

Commit

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

Reported-by: [email protected]
Closes: https://lore.kernel.org/all/[email protected]/
Fixes: 744a563 ("ext4: replace deprecated strncpy with alternatives")
Signed-off-by: Kees Cook <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
kees authored and tytso committed Jul 5, 2024
1 parent 7c73ddb commit be27cd6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fs/ext4/ext4.h
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ struct ext4_super_block {
/*60*/ __le32 s_feature_incompat; /* incompatible feature set */
__le32 s_feature_ro_compat; /* readonly-compatible feature set */
/*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */
/*78*/ char s_volume_name[EXT4_LABEL_MAX]; /* volume name */
/*78*/ char s_volume_name[EXT4_LABEL_MAX] __nonstring; /* volume name */
/*88*/ char s_last_mounted[64] __nonstring; /* directory where last mounted */
/*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */
/*
Expand Down
2 changes: 1 addition & 1 deletion fs/ext4/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ static int ext4_ioctl_getlabel(struct ext4_sb_info *sbi, char __user *user_label
BUILD_BUG_ON(EXT4_LABEL_MAX >= FSLABEL_MAX);

lock_buffer(sbi->s_sbh);
strscpy_pad(label, sbi->s_es->s_volume_name);
memtostr_pad(label, sbi->s_es->s_volume_name);
unlock_buffer(sbi->s_sbh);

if (copy_to_user(user_label, label, sizeof(label)))
Expand Down

0 comments on commit be27cd6

Please sign in to comment.