erofs: include the trailing NUL in FS_IOC_GETFSLABEL
PATCH 1/1 erofs: include the trailing NUL in FS_IOC_GETFSLABEL
erofs_ioctl_get_volume_label() passes strlen(sbi->volume_name) as the length to copy_to_user(), which copies the label string without the trailing NUL byte. Since FS_IOC_GETFSLABEL callers expect a NUL-terminated string in the FSLABEL_MAX-sized buffer and may not pre-zero the buffer, this can cause userspace to read past the label into uninitialised stack memory.
Fix this by using strlen() + 1 to include the NUL terminator, consistent with how ext4 and xfs implement FS_IOC_GETFSLABEL.
--- fs/erofs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/erofs/inode.c +1 -1
@@ -351,7 +351,7 @@ static int erofs_ioctl_get_volume_label(struct inode *inode, void __user *arg) ret =clear_user (arg,1 ); else ret =copy_to_user (arg, sbi->volume_name, -strlen (sbi->volume_name)); +strlen (sbi->volume_name) +1 );return ret ? -EFAULT :0 ; }
Signature · 1 line
2.43.0
Quoted 11 lines · Zhan Xusheng
erofs_ioctl_get_volume_label()passesstrlen(sbi->volume_name)as the length tocopy_to_user(), which copies the label string without the trailing NUL byte. SinceFS_IOC_GETFSLABELcallers expect a NUL-terminated string in the FSLABEL_MAX-sized buffer and may not pre-zero the buffer, this can cause userspace to read past the label into uninitialised stack memory.Fix this by using
strlen()+ 1 to include the NUL terminator, consistent with how ext4 and xfs implementFS_IOC_GETFSLABEL.Signed-off-by Zhan Xusheng <[email protected]>
Thanks,
Thanks,
Gao Xiang
Quoted 7 lines · Zhan Xusheng
erofs_ioctl_get_volume_label()passesstrlen(sbi->volume_name)as the length tocopy_to_user(), which copies the label string without the trailing NUL byte. SinceFS_IOC_GETFSLABELcallers expect a NUL-terminated string in the FSLABEL_MAX-sized buffer and may not pre-zero the buffer, this can cause userspace to read past the label into uninitialised stack memory.
Quoted 5 lines
Fix this by using
strlen()+ 1 to include the NUL terminator, consistent with how ext4 and xfs implementFS_IOC_GETFSLABEL.Signed-off-by Zhan Xusheng <[email protected]>
Thanks,