[PATCH] btrfs: validate scrub_speed_max sysfs string

David Disseldorp
2023-12-08T00:42:26Z

Fail the sysfs I/O on any trailing non-space characters.

Signed-off-by: David Disseldorp <ddiss@suse.de>
---
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;
}
--
2.35.3