From: David Disseldorp Date: Fri, 8 Dec 2023 00:41:56 +0000 (+1100) Subject: btrfs: sysfs: validate scrub_speed_max value X-Git-Tag: v6.6.17~748 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5e570e600b24e72222056a6968548211bb9636ca;p=platform%2Fkernel%2Flinux-starfive.git btrfs: sysfs: validate scrub_speed_max value commit 2b0122aaa800b021e36027d7f29e206f87c761d6 upstream. The value set as scrub_speed_max accepts size with suffixes (k/m/g/t/p/e) but we should still validate it for trailing characters, similar to what we do with chunk_size_store. CC: stable@vger.kernel.org # 5.15+ Signed-off-by: David Disseldorp Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c index b1d1ac2..c919872 100644 --- a/fs/btrfs/sysfs.c +++ b/fs/btrfs/sysfs.c @@ -1760,6 +1760,10 @@ static ssize_t btrfs_devinfo_scrub_speed_max_store(struct kobject *kobj, unsigned long long limit; limit = memparse(buf, &endptr); + /* There could be trailing '\n', also catch any typos after the value. */ + endptr = skip_spaces(endptr); + if (*endptr != 0) + return -EINVAL; WRITE_ONCE(device->scrub_speed_max, limit); return len; }