Skip to content

Commit b150084

Browse files
Coly Liaxboe
authored andcommitted
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>
1 parent 453745f commit b150084

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

‎drivers/md/bcache/sysfs.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,8 +801,7 @@ STORE(__bch_cache_set)
801801
c->on_error = v;
802802
}
803803

804-
if (attr == &sysfs_io_error_limit)
805-
c->error_limit = strtoul_or_return(buf);
804+
sysfs_strtoul_clamp(io_error_limit, c->error_limit, 0, UINT_MAX);
806805

807806
/* See count_io_errors() for why 88 */
808807
if (attr == &sysfs_io_error_halflife)

0 commit comments

Comments
 (0)