public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Roman Smirnov <r.smirnov@omp.ru>,
	Sergey Shtylyov <s.shtylyov@omp.ru>, Jens Axboe <axboe@kernel.dk>,
	Sasha Levin <sashal@kernel.org>,
	linux-block@vger.kernel.org
Subject: [PATCH AUTOSEL 6.6 08/11] block: prevent division by zero in blk_rq_stat_sum()
Date: Sun, 24 Mar 2024 13:06:38 -0400	[thread overview]
Message-ID: <20240324170645.546220-8-sashal@kernel.org> (raw)
In-Reply-To: <20240324170645.546220-1-sashal@kernel.org>

From: Roman Smirnov <r.smirnov@omp.ru>

[ 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: Roman Smirnov <r.smirnov@omp.ru>
Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Link: https://lore.kernel.org/r/20240305134509.23108-1-r.smirnov@omp.ru
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 block/blk-stat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/blk-stat.c b/block/blk-stat.c
index 7ff76ae6c76a9..e42c263e53fb9 100644
--- a/block/blk-stat.c
+++ b/block/blk-stat.c
@@ -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);
-- 
2.43.0


  parent reply	other threads:[~2024-03-24 17:07 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-24 17:06 [PATCH AUTOSEL 6.6 01/11] sysv: don't call sb_bread() with pointers_lock held Sasha Levin
2024-03-24 17:06 ` [PATCH AUTOSEL 6.6 02/11] rcu-tasks: Repair RCU Tasks Trace quiescence check Sasha Levin
2024-03-24 17:06 ` [PATCH AUTOSEL 6.6 03/11] rcu-tasks: Add data to eliminate RCU-tasks/do_exit() deadlocks Sasha Levin
2024-03-24 17:06 ` [PATCH AUTOSEL 6.6 04/11] rcu-tasks: Initialize " Sasha Levin
2024-03-24 17:06 ` [PATCH AUTOSEL 6.6 05/11] rcu-tasks: Maintain lists " Sasha Levin
2024-03-24 17:06 ` [PATCH AUTOSEL 6.6 06/11] rcu-tasks: Eliminate deadlocks involving do_exit() and RCU tasks Sasha Levin
2024-03-24 17:06 ` [PATCH AUTOSEL 6.6 07/11] rcu-tasks: Maintain real-time response in rcu_tasks_postscan() Sasha Levin
2024-03-24 17:06 ` Sasha Levin [this message]
2024-03-24 17:06 ` [PATCH AUTOSEL 6.6 09/11] fs: improve dump_mapping() robustness Sasha Levin
2024-03-24 17:06 ` [PATCH AUTOSEL 6.6 10/11] rcu/nocb: Fix WARN_ON_ONCE() in the rcu_nocb_bypass_lock() Sasha Levin
2024-03-24 17:06 ` [PATCH AUTOSEL 6.6 11/11] nvme: clear caller pointer on identify failure Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240324170645.546220-8-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=r.smirnov@omp.ru \
    --cc=s.shtylyov@omp.ru \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox