Fix WARNING in __ext4_ioctl
PATCH v2 1/1 Fix WARNING in __ext4_ioctl
Specify the size of s_volume_name in strscpy_pad() to avoid buffer overflow.
strscpy_pad() by default takes the size of destination string as the size to be read from source string. However, as s_volume_name is only declared as an array of size EXT4_LABEL_MAX, we are reading 1 byte more than expected.
---strscpy_pad() by default takes the size of destination string as the size to be read from source string. However, as s_volume_name is only declared as an array of size EXT4_LABEL_MAX, we are reading 1 byte more than expected.
Specify the size of s_volume_name in strscpy_pad() to avoid buffer overflow.
---
Changes in v2:
- Add fixes label
- Move workaround into commit log
- Link to v1: https://lore.kernel.org/r/[email protected]
--- fs/ext4/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/ioctl.c +1 -1
@@ -1151,7 +1151,7 @@ static int ext4_ioctl_getlabel(struct ext4_sb_info *sbi, char __user *user_labelBUILD_BUG_ON (EXT4_LABEL_MAX >=FSLABEL_MAX );lock_buffer (sbi->s_sbh); -strscpy_pad (label, sbi->s_es->s_volume_name); +strscpy_pad (label, sbi->s_es->s_volume_name,EXT4_LABEL_MAX );unlock_buffer (sbi->s_sbh);if (copy_to_user (user_label, label,sizeof (label)))
---
base-commit: 55027e689933ba2e64f3d245fb1ff185b3e7fc81
change-id: 20240628-bug8-7f700a228c4a
Best regards,
Signature · 1 line
Pei Li <[email protected]>
Quoted 8 lines · Pei Li
Specify the size of
s_volume_nameinstrscpy_pad()to avoid buffer overflow.
strscpy_pad()by default takes the size of destination string as the size to be read from source string. However, ass_volume_nameis only declared as an array of sizeEXT4_LABEL_MAX, we are reading 1 byte more than expected.
Quoted 4 lines
Reported-by [email protected]Fixes 744a56389f73 ("ext4: replace deprecated strncpy with alternatives")Signed-off-by Pei Li <[email protected]>
Thanks for the fix, it looks good to me.
Quoted 37 lines
---
strscpy_pad()by default takes the size of destination string as the size to be read from source string. However, ass_volume_nameis only declared as an array of sizeEXT4_LABEL_MAX, we are reading 1 byte more than expected.Specify the size of
s_volume_nameinstrscpy_pad()to avoid buffer overflow.
---
Changes in v2:
- Add fixes label
- Move workaround into commit log
- Link to v1: https://lore.kernel.org/r/[email protected]--- fs/ext4/ioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ext4/ioctl.c +1
-2@@ -1151,7 +1151,7 @@ static int ext4_ioctl_getlabel(struct ext4_sb_info *sbi, char __user *user_labelBUILD_BUG_ON (EXT4_LABEL_MAX >=FSLABEL_MAX );lock_buffer (sbi->s_sbh); -strscpy_pad (label, sbi->s_es->s_volume_name); +strscpy_pad (label, sbi->s_es->s_volume_name,EXT4_LABEL_MAX );unlock_buffer (sbi->s_sbh);if (copy_to_user (user_label, label,sizeof (label))) ---base-commit:
55027e689933ba2e64f3d245fb1ff185b3e7fc81
change-id: 20240628-bug8-7f700a228c4aBest regards,
Theodore Ts'o
maintainerThanks for the patch; however, the correct fix submitted by Kees with this commit:
commit be27cd64461c45a6088a91a04eba5cd44e1767ef
Author: Kees Cook <[email protected]> Date: Thu May 23 15:54:12 2024 -0700
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.
- Ted