Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp404915lqs; Tue, 5 Mar 2024 05:46:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVXwxD8PdFEkeWSeFMDNmwwp+tPYbjNB9mm1X11613LdOSoESZD0jKNVH7vQVRgg/q0+BzuU/dpH8bu2vYCL3yJxoksHbGZXyFbk4aiKg== X-Google-Smtp-Source: AGHT+IEKcK2ASs5S4UUBWEArboNd1ILIMFP1cJMSU7I1afWhl5Gn6R6W8NUO29a4RfHxYDQpvsQq X-Received: by 2002:a05:6a20:1442:b0:1a1:4848:98a6 with SMTP id a2-20020a056a20144200b001a1484898a6mr1764117pzi.4.1709646362926; Tue, 05 Mar 2024 05:46:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709646362; cv=pass; d=google.com; s=arc-20160816; b=eqhMirXIOL/Wa+XfhjbFsjJEBo6PykT/q0hHmk1uNYcy9F3sQXi5YIKYNju9B3xyDm j57oSVBjlNUROeBu5djuIOIf90LPEJESq0enbbPa1pnTWLacTMuL+pkiJfI5bGfpqfmt 3DFnmi/1+yQSCRldYKKiAAzSPVF4VNNdDgiNt7pYXio5A85OZF0XNrn2+iTlSqI4LXzE EPcSl5WgjI2d1+3js2JRSy7DUkH2xbNUZXgb3oiy5T1pczvmkU0BXe/64esM3wyik9vD /4gP6bKSEwUqXndlecJlAeSRd5TUgU0rGRL8V8tldu3rlGPQB5FI08OwW4klxzWNVlz0 k1+A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=9oZUfjxo410YF3/0MFnaYOisjgce682NMZo+vyKYKt8=; fh=bvB+qO2krfum8pLdzMZn5UYSiCgCH2HQWMSy9D6/+l8=; b=IpJGZSpxKDPzQUWW7zOJBp6HK5xXPcRHNgT2dNjbN0YvbVZ95YIGaUyyj36KbQLo0p KdQZlzn1GeaJIL3Xxf8DtAHnuC1iBYrvOa/+f3yB5e2p/V4ZfWA3pnDnsoNMqahOBsbH 1gWggqCte1zpO/ZZo5XnRNVI/OImMJOtWwKuvIVNTxiu1duR43AfJOcLLXmIFvnmWAgx LMwOVkbzf7hV4KMfktnz9pct8NWSMPmNmo5Et7IGCyVC8mzdr3HSnRejLNWQtKD/Bggu G/soW4vHjY0rLOJjUGn8bl9kJPJHDloKIt3x1b3Wv90EJyONvBx+A5NfNf6rTpaqiM9x +Hyw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-kernel+bounces-92463-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92463-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bq13-20020a056a02044d00b005cfb2c44526si11000491pgb.862.2024.03.05.05.46.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 05:46:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-92463-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-kernel+bounces-92463-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92463-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 986442835FF for ; Tue, 5 Mar 2024 13:46:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FCAB86126; Tue, 5 Mar 2024 13:45:55 +0000 (UTC) Received: from mx01.omp.ru (mx01.omp.ru [90.154.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C98B55915D; Tue, 5 Mar 2024 13:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.154.21.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709646355; cv=none; b=cQFhZ3j5OuaM27w3K6BA8YQaN+pTcz8przQ/JtmXi0CcXZqEKCxXzkn502BlDKOxfkrlCj46nmsaKXyJmL6CnlPD44SQgPKslvtmeGukpeqGIBVACc9Bu0ZB8mSzLwsDNPW/XkZ9BiJchmD2r0SMt3LYm0CDcjr0WLFJDsqakI0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709646355; c=relaxed/simple; bh=xfh49nxcNCMeozUYuhHg+aE7kDfXE3vNBO+UGPTu1fc=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=KdB+z7dEEdzrLEnI7QdSFZPQfmdLULFC8Bcqnaz7hpwei3K0BbMzX32X8+ZJU9ZF5Uhr4bvnlwozFPnsDTMTWOvRdQcBqt4q+vzH636huCLajpsI+HJ9HPLMamvloRTawAc+zVp3IhRKEkCbEY5ubJySPigkIglQk4dLC22ghGM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru; spf=pass smtp.mailfrom=omp.ru; arc=none smtp.client-ip=90.154.21.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=omp.ru Received: from localhost.localdomain (78.37.41.175) by msexch01.omp.ru (10.188.4.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1258.12; Tue, 5 Mar 2024 16:45:41 +0300 From: Roman Smirnov To: Jens Axboe CC: Roman Smirnov , Sergey Shtylyov , Karina Yankevich , , , Subject: [PATCH] block: prevent division by zero in blk_rq_stat_sum() Date: Tue, 5 Mar 2024 16:45:09 +0300 Message-ID: <20240305134509.23108-1-r.smirnov@omp.ru> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: msexch01.omp.ru (10.188.4.12) To msexch01.omp.ru (10.188.4.12) X-KSE-ServerInfo: msexch01.omp.ru, 9 X-KSE-AntiSpam-Interceptor-Info: scan successful X-KSE-AntiSpam-Version: 6.1.0, Database issued on: 03/05/2024 13:15:25 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 59 X-KSE-AntiSpam-Info: Lua profiles 183964 [Mar 05 2024] X-KSE-AntiSpam-Info: Version: 6.1.0.3 X-KSE-AntiSpam-Info: Envelope from: r.smirnov@omp.ru X-KSE-AntiSpam-Info: LuaCore: 8 0.3.8 4a99897b35b48c45ee5c877607d26a2d9f419920 X-KSE-AntiSpam-Info: {rep_avail} X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: {relay has no DNS name} X-KSE-AntiSpam-Info: {SMTP from is not routable} X-KSE-AntiSpam-Info: {Found in DNSBL: 78.37.41.175 in (user) dbl.spamhaus.org} X-KSE-AntiSpam-Info: omp.ru:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;127.0.0.199:7.1.2 X-KSE-AntiSpam-Info: ApMailHostAddress: 78.37.41.175 X-KSE-AntiSpam-Info: {DNS response errors} X-KSE-AntiSpam-Info: Rate: 59 X-KSE-AntiSpam-Info: Status: not_detected X-KSE-AntiSpam-Info: Method: none X-KSE-AntiSpam-Info: Auth:dmarc=temperror header.from=omp.ru;spf=temperror smtp.mailfrom=omp.ru;dkim=none X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Heuristic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 03/05/2024 13:20:00 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 3/5/2024 11:10:00 AM X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit 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 Reviewed-by: Sergey Shtylyov --- 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 7ff76ae6c76a..e42c263e53fb 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.34.1