Skip to content

Commit d6250d4

Browse files
Zhan Xushenghsiangkao
authored andcommitted
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. Signed-off-by: Zhan Xusheng <zhanxusheng@xiaomi.com> Fixes: 1cf12c7 ("erofs: Add support for FS_IOC_GETFSLABEL") Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com> Reviewed-by: Chunhai Guo <guochunhai@vivo.com> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent 5de6951 commit d6250d4

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

fs/erofs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static int erofs_ioctl_get_volume_label(struct inode *inode, void __user *arg)
351351
ret = clear_user(arg, 1);
352352
else
353353
ret = copy_to_user(arg, sbi->volume_name,
354-
strlen(sbi->volume_name));
354+
strlen(sbi->volume_name) + 1);
355355
return ret ? -EFAULT : 0;
356356
}
357357

0 commit comments

Comments
 (0)