Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp386158rdb; Mon, 22 Jan 2024 07:16:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqDPQ14SdbTcqaI7nijhCSPbLpzmAdaT60HKu/sxkM/l0FJsR61P81pdW43U5sWHyO7XQW X-Received: by 2002:a05:6808:1521:b0:3bd:bb53:418 with SMTP id u33-20020a056808152100b003bdbb530418mr1462614oiw.16.1705936586164; Mon, 22 Jan 2024 07:16:26 -0800 (PST) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 16-20020ac84e90000000b0042a0ddee631si5755481qtp.326.2024.01.22.07.16.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 07:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-33260-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=H3nm1vpR; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-33260-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-33260-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 3C11F1C2390F for ; Mon, 22 Jan 2024 15:15:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 674035579B; Mon, 22 Jan 2024 14:58:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H3nm1vpR" 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 8FB5955772; Mon, 22 Jan 2024 14:58:32 +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=1705935512; cv=none; b=Xn1TJyqQug26Rui05jiEx4kfIUs4ophM8o43vo0fjubTbFoAsJp8Hg2Hh2IN8MWSC29b3RAg8Z9cuF6bo9/e/ctTFke356p4N327aPBk15Haw5AeofQjgIWwB5KiI0KRTqxz+3oitu4nfhH4iRpmuxMdFXkkESelPTRV7hjTUdQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705935512; c=relaxed/simple; bh=jwP8RHOIWeRScoui3Um5Gmwxef1hevz9zqA4P4niiys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ak+gSC+v2NxVFa3CXoeZJ0SgBh+KG6n2+Tb0v8AaIdvSludO/nACCReqUCacbbd8rzq7ouk05yjO2wmh96Fpc7xVXgcyu/aHhrvcSKdNYT/GhXCDgeSo99NrF7lCaLrB9CQGaW1XJIsGToEqxKFhI3XCjCOtrGY4gE0kXdW+sXk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H3nm1vpR; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19754C43394; Mon, 22 Jan 2024 14:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705935512; bh=jwP8RHOIWeRScoui3Um5Gmwxef1hevz9zqA4P4niiys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H3nm1vpRw/SKB7CE7eBAOGP3FqUuFjREAUyTNjS0vHQvTXqN2P5D8gP38yfbb4loq qnbxKEbaiB4KWVa8SFd99bcZd7FNYrlhlmoB0T0xW5o7DBk8TofDM4MmQGMxeWGJsA N5Wywab4KWbinXTyscIdInKzfbIEZWNH8cBnyA35BU0Ud9xViNaMI8sK1DzlJthf95 Ru7RCfBhYTlPVP5qzHkMYIg6EXoBc1O5aV9946TKzzQ3qPbdGWAK3tiSVVTsI1a0rs edYJZNr4t9fK1olilE0ML7TinJXbugXGMh7/7xlu2PrMc6MRiHsyy+bZrEu1dTyrm/ jN0eqxiXnuejw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , Jim Cromie , Jean Delvare , Guenter Roeck , linux-hwmon@vger.kernel.org, "Gustavo A . R . Silva" , Sasha Levin Subject: [PATCH AUTOSEL 6.7 41/88] hwmon: (pc87360) Bounds check data->innr usage Date: Mon, 22 Jan 2024 09:51:14 -0500 Message-ID: <20240122145608.990137-41-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122145608.990137-1-sashal@kernel.org> References: <20240122145608.990137-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.7.1 Content-Transfer-Encoding: 8bit From: Kees Cook [ Upstream commit 4265eb062a7303e537ab3792ade31f424c3c5189 ] Without visibility into the initializers for data->innr, GCC suspects using it as an index could walk off the end of the various 14-element arrays in data. Perform an explicit clamp to the array size. Silences the following warning with GCC 12+: ./drivers/hwmon/pc87360.c: In function 'pc87360_update_device': ./drivers/hwmon/pc87360.c:341:49: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=] 341 | data->in_max[i] = pc87360_read_value(data, | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ 342 | LD_IN, i, | ~~~~~~~~~ 343 | PC87365_REG_IN_MAX); | ~~~~~~~~~~~~~~~~~~~ ./drivers/hwmon/pc87360.c:209:12: note: at offset 255 into destination object 'in_max' of size 14 209 | u8 in_max[14]; /* Register value */ | ^~~~~~ Cc: Jim Cromie Cc: Jean Delvare Cc: Guenter Roeck Cc: linux-hwmon@vger.kernel.org Signed-off-by: Kees Cook Reviewed-by: Gustavo A. R. Silva Link: https://lore.kernel.org/r/20231130200207.work.679-kees@kernel.org [groeck: Added comment into code clarifying context] Signed-off-by: Guenter Roeck Signed-off-by: Sasha Levin --- drivers/hwmon/pc87360.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/pc87360.c b/drivers/hwmon/pc87360.c index 926ea1fe133c..9e9681b2e8c5 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c @@ -323,7 +323,11 @@ static struct pc87360_data *pc87360_update_device(struct device *dev) } /* Voltages */ - for (i = 0; i < data->innr; i++) { + /* + * The min() below does not have any practical meaning and is + * only needed to silence a warning observed with gcc 12+. + */ + for (i = 0; i < min(data->innr, ARRAY_SIZE(data->in)); i++) { data->in_status[i] = pc87360_read_value(data, LD_IN, i, PC87365_REG_IN_STATUS); /* Clear bits */ -- 2.43.0