Re: [PATCH] btrfs: validate scrub_speed_max sysfs string

Qu Wenruo
2023-12-11T03:18:26Z

On 2023/12/8 11:11, David Disseldorp wrote:
> Fail the sysfs I/O on any trailing non-space characters.
>
> Signed-off-by: David Disseldorp <ddiss@suse.de>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Although I have an unrelated idea.

Since memparse() provides the @endptr, can we rewind the @endptr, so
that we can check if the last valid charactor is suffix 'e'.
Then reject it from btrfs size.

I really don't think we need exabytes suffix for our scrub speed limit
usage.

Thanks,
Qu

> ---
> fs/btrfs/sysfs.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
> index e6b51fb3ddc1e..4c4642ef7c5f0 100644
> --- a/fs/btrfs/sysfs.c
> +++ b/fs/btrfs/sysfs.c
> @@ -1783,6 +1783,9 @@ static ssize_t btrfs_devinfo_scrub_speed_max_store(struct kobject *kobj,
> unsigned long long limit;
>
> limit = memparse(buf, &endptr);
> + endptr = skip_spaces(endptr);
> + if (*endptr != 0)
> + return -EINVAL;
> WRITE_ONCE(device->scrub_speed_max, limit);
> return len;
> }