Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp23894lqz; Fri, 29 Mar 2024 07:28:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXG2Evc2/DNEuqdx2uEHpl3FO2JBIqKfMTX3drmSdFEwh+JpyaT0jDcG9F/1V2OBG5a2tTZBhOo51I4Wer24DOunMyMk9e5vneSeXKjSQ== X-Google-Smtp-Source: AGHT+IFvQ2/HhZrR8+Zaag2fw0SBO46pVFww/wCAMSL/UJ/vO5YNvBhHtCBe2VjsQwbk7xR7YG3h X-Received: by 2002:a05:6a20:bc94:b0:1a3:673b:62b8 with SMTP id fx20-20020a056a20bc9400b001a3673b62b8mr1877066pzb.35.1711722527947; Fri, 29 Mar 2024 07:28:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711722527; cv=pass; d=google.com; s=arc-20160816; b=ofHc2OpRqPgo6rXnUIfV7vJYrnfi+ENDIgnsXzIGTew8HCSQlPuFVioGspGZKwfR8m RI9Q16nFYDllQ8IgCd+mztvXLfQ160pKvl9XkqLdPzxLJENb7JowabHk366lxaCX6mcT kavSjkn2N3/SOGzdL7qsBPn5KItsL/vAGy8uwgfGZ6qP9guRaI6bZcGrN6HebLMyuBe+ 0bcMypKqR7aQX81gMkyGjxhD4miqSBpKy7lNZqK4/BkBzv77bqvLozrWAv5EUDO65sPG 5jFQzLWD618t1pSbjHLcDb3ozuvu01TYAoqeXCy/J1dikw48WtNP1LYP9ksSYwnv/RmJ jccg== 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=a3WspWzowyLKXaY8vcYjAZEPBkJVbWHXiyI2xC4Fj1E=; fh=yxpzEavC5cr/2fXaBkEnEeKOGnaieg5PRFrevjWmepM=; b=uoH8zRgecdz9FkqkCLLer0ZEmLrgxWwFa7TNukf6afk5dC1g8dnFLedXTOcIMWmyaU Pv9YKj5ZX0evRd6twUBirPcu9PJ6zk79SwUY5LHsXJNUA7++RxpItSlhLF57PNIng3uN Px7F5gSDUwU7CO/58+fcUCUDrIkesAaBvUGmM8pIg877Do7eWcyXSapH1VeSQzzruE9w onk4wX6y6MybQ/ovPTkzXmAVsU0nAzlotcYWbogy5podCYsF5c+E2urwu5zfHbSql5ju bnORzfYwbCaaDEF8+ZLNk4koloRW0FnPm8FLa6elnJn5ucoi1Fe3SWPtaWjObFvrT8di RGoQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QSyjNtUk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124927-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124927-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id lm8-20020a170903298800b001e0afbfd57bsi3793023plb.128.2024.03.29.07.28.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 07:28:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-124927-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QSyjNtUk; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-124927-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-124927-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 C8E902866C0 for ; Fri, 29 Mar 2024 14:28:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F50D16C43C; Fri, 29 Mar 2024 12:47:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="QSyjNtUk" 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 6AE471A33BF; Fri, 29 Mar 2024 12:47:21 +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=1711716441; cv=none; b=W2s/X1ZdqvKXQ0ZV/UJElCHyY9u8FZ4KyrP3ssNOgLfHJBRhUepTfhURy7N0c31B490nCVisleu/JvCi6N+YoQOHu6s68jtHtxzh7BOwxHnuwmebXCNMEkYJX47RBQFC1A5OmQzdqvvAYI/jEgrdx5hHzmO6lvNo+VQAjOxrldU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711716441; c=relaxed/simple; bh=Yx4z1c+Bu5s+V0sWrTPLA22MMO08Ob0bgjwlHnhaN5k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nRnieWKjGmv805vYHA69xDH8P90effrPKomgElb6ex8/8jsddFdX87PYKmAy+hKS02/TCJk2aWxMEtF/yvobbDDL2GFNoBjrONs2NKR2BhGQbkcqCG/t294k9wKdSTXag0pi6951cB6Tga81dntJf5SuQeukZCRfkYk/AyUs6P0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QSyjNtUk; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A39FC43330; Fri, 29 Mar 2024 12:47:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711716441; bh=Yx4z1c+Bu5s+V0sWrTPLA22MMO08Ob0bgjwlHnhaN5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QSyjNtUkO5NPXkWufLgjgmhXxI5TEQ3T4jKj8KlamkU5RB2GlJCiudK5IfbzvaoMi 66xUuOkL1DS52e8PtCSTKtlqF75sxoLSlvf2tNyH2NHECGJbRn/BBUD0ER/cdjbfYn EEYAcPY6FlbaTPY6q0hm5BZFdfW+XwaANRZtz7k/1D4aQuH+4vBPJm4/nHm/v/tthV qdXg8+TfNhim1rTWj3oPKVIHnowzU+e7umbBjvHQj4n6aUkV3zwR5HJNdfPlvFtpNU NAexU79Bmo1Sug8LM9pyCl5wpfwN4Qwtj1Co/lID6gl3Mhp6BbYtBtIqvNzQN4rALD uoSZRD5I2EclQ== 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.1 43/52] block: prevent division by zero in blk_rq_stat_sum() Date: Fri, 29 Mar 2024 08:45:37 -0400 Message-ID: <20240329124605.3091273-43-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329124605.3091273-1-sashal@kernel.org> References: <20240329124605.3091273-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.1.83 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 da9407b7d4abf..41be89ecaf20e 100644 --- a/block/blk-stat.c +++ b/block/blk-stat.c @@ -28,7 +28,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