From: Coly Li Date: Sat, 9 Feb 2019 04:53:01 +0000 (+0800) Subject: bcache: fix input overflow to sequential_cutoff X-Git-Tag: v5.15~6749^2~87 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c27a3953e92eb0b22dbb03d599f543a05f9574e;p=platform%2Fkernel%2Flinux-starfive.git bcache: fix input overflow to sequential_cutoff People may set sequential_cutoff of a cached device via sysfs file, but current code does not check input value overflow. E.g. if value 4294967295 (UINT_MAX) is written to file sequential_cutoff, its value is 4GB, but if 4294967296 (UINT_MAX + 1) is written into, its value will be 0. This is an unexpected behavior. This patch replaces d_strtoi_h() by sysfs_strtoul_clamp() to convert input string to unsigned integer value, and limit its range in [0, UINT_MAX]. Then the input overflow can be fixed. Signed-off-by: Coly Li Signed-off-by: Jens Axboe --- diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index bedd3e6..96b6489 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -314,7 +314,9 @@ STORE(__cached_dev) dc->io_disable = v ? 1 : 0; } - d_strtoi_h(sequential_cutoff); + sysfs_strtoul_clamp(sequential_cutoff, + dc->sequential_cutoff, + 0, UINT_MAX); d_strtoi_h(readahead); if (attr == &sysfs_clear_stats)