Skip to content

Commit

Permalink
bcache: fix input overflow to cache set sysfs file io_error_halflife
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Coly Li authored and axboe committed Feb 9, 2019
1 parent b150084 commit a91fbda
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions drivers/md/bcache/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,17 @@ STORE(__bch_cache_set)
sysfs_strtoul_clamp(io_error_limit, c->error_limit, 0, UINT_MAX);

/* See count_io_errors() for why 88 */
if (attr == &sysfs_io_error_halflife)
c->error_decay = strtoul_or_return(buf) / 88;
if (attr == &sysfs_io_error_halflife) {
unsigned long v = 0;
ssize_t ret;

ret = strtoul_safe_clamp(buf, v, 0, UINT_MAX);
if (!ret) {
c->error_decay = v / 88;
return size;
}
return ret;
}

if (attr == &sysfs_io_disable) {
v = strtoul_or_return(buf);
Expand Down

0 comments on commit a91fbda

Please sign in to comment.