btrfs: sysfs: validate scrub_speed_max value
authorDavid Disseldorp <ddiss@suse.de>
Fri, 8 Dec 2023 00:41:56 +0000 (11:41 +1100)
committerDavid Sterba <dsterba@suse.com>
Fri, 15 Dec 2023 22:01:04 +0000 (23:01 +0100)
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 <ddiss@suse.de>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/sysfs.c

index e6b51fb3ddc1eb6ffd29f14bf36748d9a6b47c53..84c05246ffd8ad4b23b622c1ef3d4087307d6c02 100644 (file)
@@ -1783,6 +1783,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;
 }