Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a55dab4 authored by Roman Smirnov's avatar Roman Smirnov Committed by Greg Kroah-Hartman
Browse files

block: prevent division by zero in blk_rq_stat_sum()



[ Upstream commit 93f52fbeaf4b676b21acfe42a5152620e6770d02 ]

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: default avatarRoman Smirnov <r.smirnov@omp.ru>
Reviewed-by: default avatarSergey Shtylyov <s.shtylyov@omp.ru>
Link: https://lore.kernel.org/r/20240305134509.23108-1-r.smirnov@omp.ru


Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 56199ebb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ void blk_rq_stat_init(struct blk_rq_stat *stat)
/* src is a per-cpu stat, mean isn't initialized */
void blk_rq_stat_sum(struct blk_rq_stat *dst, struct blk_rq_stat *src)
{
	if (!src->nr_samples)
	if (dst->nr_samples + src->nr_samples <= dst->nr_samples)
		return;

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