Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2525lqz; Fri, 29 Mar 2024 06:56:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU/AoTICVUr9QicmtyaiBjl3aN/QCgj6acMg6fXnsV9PdwxJpUK7XQQPdCFb4AYeK//nQ6mHHJMDm1I6XCw5rtsu/eqrfGrB6dRQBam8Q== X-Google-Smtp-Source: AGHT+IH1mcgYTxBWGSYmmSbMvBAOy4h+dxM+3qNfjpYm7V1EYZBFq9FptSDBgHCfqog+/rxv4S+u X-Received: by 2002:a17:903:6cb:b0:1e0:a2cf:62e8 with SMTP id kj11-20020a17090306cb00b001e0a2cf62e8mr6011373plb.10.1711720585827; Fri, 29 Mar 2024 06:56:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711720585; cv=pass; d=google.com; s=arc-20160816; b=sDMbkduw7/dOjShKm8gbwwJIFLGD5xuncW7deDbZ4gWZ4LJlHPW7HSoMEBZtmFgJlt S9KUpsm5CYFZkq8UnbXsYjWgoAgEHYlTBhuwwkPBzWfDtGBCXImj6ik/f620CzXpBsLW QICB7mmtXy5tzBlzYiY1+GvZMrrtQ/Vf96RyIzOTI3EVMqpZR60BZIwydU9BzAiL8nhn GxobidhUj/Q9Vb608W1I0bhh7pm1ksGBl9sf4NGx7VF4NwDv1+pt9RHPAVR9pa/6VfRo C0q9tKQB8J4+NIHLbWg+LCEOnO/Mv2GK9Lu1B5LdaDp8+Tvm9XB/lG3V/ST+zVq11JUD J0gQ== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GUNOF5qSFMZJOVCnu0HdbZQqpMv1Zv5/pnGt+3HWhw0=; fh=yxpzEavC5cr/2fXaBkEnEeKOGnaieg5PRFrevjWmepM=; b=TI8N4OhlguDHb/jMJe0JrtKYcpeBUEiSJ60+uM+akMw4sv6aQn/Ku133cXM5wUAHeD khw0jed+0BNFMlk2M+PxTixmO6QwwJ635idzlTYrv0QU4t4wlL6k0IqmydBUgyLVm6de 4vNxsKZLqzILWpu7+cilPNdjfLbmFtj5CJ2e6lB9jahBq3eK4oOVMtK027S2bgV0K+0+ b4rQ1RZXwYrqP38kqvYZJHhmwH0k70ZYuDOdPCAcv85n5VMpZAVYntIGXlWkl/K3s8lT ZZRj5mQm/fxhm7H/dqol0Og8z2l8J0kDBs/FyvhZdc9ltTD0WF6xpP6L6kQtVpj15cKT 1AqA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T59y7KB1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124795-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id n10-20020a170902f60a00b001e2368e8b9asi1004505plg.504.2024.03.29.06.56.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 06:56:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124795-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T59y7KB1; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124795-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124795-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 0827B284887 for ; Fri, 29 Mar 2024 13:53:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A6DD148840; Fri, 29 Mar 2024 12:42:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="T59y7KB1" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FBE114883F; Fri, 29 Mar 2024 12:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716150; cv=none; b=AeQN3AVjrht6k9dPHw+cNxxRU1Q2YhKO8GUFv4dgG72fmQV2EXsAdBuWGkmkG1cP+lpC96u+uwmtPmXEhbKEFGikeUZnL9KyU/CmKDfTge/SfAGv62PSRxTnRuC0rsi1NwarwHxSQTraoRGCWINjNdwZS/cC4x+quOea9P/PqTc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716150; c=relaxed/simple; bh=0pqNxaLcbkQ7KCRmakADyDfAYk41/fLh/4lRyyT542Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mpjKDcv+oV2pwnWNPu1cDdFi5zxDG86FF72NF48rRSP1CqG+JKp/SpoOKbAya6XWDCdxZOLO5AgYzNo0OiSsL/rm3xktgkKnkqsfZ3RCHdhSQdbMLR6LehqM3K4prk2yvqx8TnRALazDluWniuaoS16W1TLELaoSsWQ5dt8Z/kk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=T59y7KB1; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31E21C43390; Fri, 29 Mar 2024 12:42:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716150; bh=0pqNxaLcbkQ7KCRmakADyDfAYk41/fLh/4lRyyT542Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T59y7KB1uYxG+ABIogCK8Kne1cNVYI0DDJu/wyOqXnz/UPS6egWPRMkf1TSEltdCr hY/ZkqfOJws5YUA2BYfBSUHRsygQo1eSYMQTKL+Cln+1rswRTTpyOtiLjw8e/gWTs5 N2tPi+FdKpCS2IvSPjDUYzbH0cejLXe39jjbviX8Kq2rBaoeSCkwLNi97XJdGNLJti yH1fVKRdDwMd5BBTa37nzrHQDhMoE8KaKnuS3EP4QczAjIZu9O9GiAjBXQMwV6QnRF StfdcGX+Rx73LnJDK9azrt5B8uAL9fddMb5yBJkPRYDCsBoetqU6HQr5ZSINx57X/e HQcCpKqdnSHkA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Roman Smirnov , Sergey Shtylyov , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 6.8 84/98] block: prevent division by zero in blk_rq_stat_sum() Date: Fri, 29 Mar 2024 08:37:55 -0400 Message-ID: <20240329123919.3087149-84-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329123919.3087149-1-sashal@kernel.org> References: <20240329123919.3087149-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.2 Content-Transfer-Encoding: 8bit From: Roman Smirnov [ 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 Reviewed-by: Sergey Shtylyov Link: https://lore.kernel.org/r/20240305134509.23108-1-r.smirnov@omp.ru Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- 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