Skip to content

Commit a91fbda

Browse files
Coly Liaxboe
authored andcommitted
bcache: fix input overflow to cache set sysfs file io_error_halflife
Cache set sysfs entry io_error_halflife is used to set c->error_decay. c->error_decay is in type unsigned int, and it is converted by strtoul_or_return(), therefore overflow to c->error_decay is possible for a large input value. This patch fixes the overflow by using strtoul_safe_clamp() to convert input string to an unsigned long value in range [0, UINT_MAX], then divides by 88 and set it to c->error_decay. Signed-off-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b150084 commit a91fbda

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎drivers/md/bcache/sysfs.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -804,8 +804,17 @@ STORE(__bch_cache_set)
804804
sysfs_strtoul_clamp(io_error_limit, c->error_limit, 0, UINT_MAX);
805805

806806
/* See count_io_errors() for why 88 */
807-
if (attr == &sysfs_io_error_halflife)
808-
c->error_decay = strtoul_or_return(buf) / 88;
807+
if (attr == &sysfs_io_error_halflife) {
808+
unsigned long v = 0;
809+
ssize_t ret;
810+
811+
ret = strtoul_safe_clamp(buf, v, 0, UINT_MAX);
812+
if (!ret) {
813+
c->error_decay = v / 88;
814+
return size;
815+
}
816+
return ret;
817+
}
809818

810819
if (attr == &sysfs_io_disable) {
811820
v = strtoul_or_return(buf);

0 commit comments

Comments
 (0)