bcache: fix input overflow to cache set io_error_limit
authorColy Li <colyli@suse.de>
Sat, 9 Feb 2019 04:53:09 +0000 (12:53 +0800)
committerJens Axboe <axboe@kernel.dk>
Sat, 9 Feb 2019 14:18:32 +0000 (07:18 -0700)
commitb15008403b59955c9fa0c8b55cadd6dae991a4e9
tree1283e2fdc1b648c3206581a4b8a19278a91181dd
parent453745fbbebecf7e459785db7e29e11563908525
bcache: fix input overflow to cache set io_error_limit

c->error_limit is in type unsigned int, it is set via cache set sysfs
file io_error_limit. Inside the bcache code, input string is converted
by strtoul_or_return() and set the converted value to c->error_limit.

Because the converted value is unsigned long, and c->error_limit is
unsigned int, if the input is large enought, overflow will happen to
c->error_limit.

This patch uses sysfs_strtoul_clamp() to convert input string, and set
the range in [0, UINT_MAX] to avoid the potential overflow.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/sysfs.c