[lvc-project] [PATCH v2 2/2] ext4: check if mount_opts is NUL-terminated in ext4_ioctl_set_tune_sb()

Baokun Li libaokun1 at huawei.com
Sat Nov 8 07:05:45 MSK 2025


On 2025-11-02 00:04, Fedor Pchelkin wrote:
> params.mount_opts may come as potentially non-NUL-term string.  Userspace
> is expected to pass a NUL-term string.  Add an extra check to ensure this
> holds true.  Note that further code utilizes strscpy_pad() so this is just
> for proper informing the user of incorrect data being provided.
>
> Found by Linux Verification Center (linuxtesting.org).
>
> Signed-off-by: Fedor Pchelkin <pchelkin at ispras.ru>

Looks good to me.

Reviewed-by: Baokun Li <libaokun1 at huawei.com>

> ---
>
> v2: check length of mount_opts in superblock tuning ioctl (Jan Kara)
>
>     Can't plainly return error at strscpy_pad() call site in
>     ext4_sb_setparams(), that's a void ext4_update_sb_callback.
>
> v1: https://lore.kernel.org/lkml/20251028130949.599847-1-pchelkin@ispras.ru/T/#u
>
>  fs/ext4/ioctl.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index a93a7baae990..3dec26c939fd 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -1394,6 +1394,10 @@ static int ext4_ioctl_set_tune_sb(struct file *filp,
>  	if (copy_from_user(&params, in, sizeof(params)))
>  		return -EFAULT;
>  
> +	if (strnlen(params.mount_opts, sizeof(params.mount_opts)) ==
> +	    sizeof(params.mount_opts))
> +		return -E2BIG;
> +
>  	if ((params.set_flags & ~TUNE_OPS_SUPPORTED) != 0)
>  		return -EOPNOTSUPP;
>  





More information about the lvc-project mailing list