Skip to content

Commit 93f52fb

Browse files
RSmirnov512axboe
authored andcommitted
block: prevent division by zero in blk_rq_stat_sum()
The expression dst->nr_samples + src->nr_samples may have zero value on overflow. It is necessary to add a check to avoid division by zero. Found by Linux Verification Center (linuxtesting.org) with Svace. Signed-off-by: Roman Smirnov <[email protected]> Reviewed-by: Sergey Shtylyov <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent e6dfe74 commit 93f52fb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

block/blk-stat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void blk_rq_stat_init(struct blk_rq_stat *stat)
2727
/* src is a per-cpu stat, mean isn't initialized */
2828
void blk_rq_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
2929
{
30-
if (!src->nr_samples)
30+
if (dst->nr_samples + src->nr_samples <= dst->nr_samples)
3131
return;
3232

3333
dst->min = min(dst->min, src->min);

0 commit comments

Comments
 (0)