From mboxrd@z Thu Jan 1 00:00:00 1970 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 E68E3151CCD; Mon, 22 Jan 2024 15:18:51 +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=1705936732; cv=none; b=qUdFAFgWi/cmjPnh6HlCkI0xHDnQ5H3xOM25xR5p0OGIR3H8omnWOVJt1XMFtGzqoE2qnev7wfAUpcmDlpJUvpHDmhTvHXtC35a5BqqRJxoeTSD1/XJDJFuG1xYaLSNhmzMkuv4Ufpq22RThCdGsm14lw8SNZgyt0XgkcLVvlm4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705936732; c=relaxed/simple; bh=+k2vygah2BYoMsEnvJ8o9+EBu3ToXpgQXFXwdYknDb0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X2mHddkwyUqa8r5baKcjECmfD4lFybdCdLIfezzUjkzXw+yXmnmfvSbf+K2TSZ953Th0Q3eQSnIQPOCF1RfU41fPzady7LKCrZwsaMSL3oOuKLD3oLPmQvcNQLwAKjbnPP0DUukzzn8RyLdyQt5Y9Hkh60wj69ifvwe+0hgz/Ek= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mKfhZgTy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mKfhZgTy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D901C433F1; Mon, 22 Jan 2024 15:18:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705936731; bh=+k2vygah2BYoMsEnvJ8o9+EBu3ToXpgQXFXwdYknDb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mKfhZgTyqMshqj0eHxeAGLQ+tVQcEfEdiNMJhUq3AnodlE4ldf5AqsnTZ5B5QoIrh 1bA5JxY/Nx1YfyyHCXryEv18Fw+JpsB2GEEITsx/seARVxh6y+L8vM8DgafW8rfvJ2 sO9+L/GfFs/XpWl/Wj0ij51AtGhc4IuxECY11eE6lSVXO8RR+VwQvEhDwW/O8yJRfE 7kff15RW4yAJpQ3M85WdMZNyokC1/Sag+aY92Kdlr1dlVzcy3QS/qfwSiGOpMabp7a pQxcG77ueiiLalbSP6tHqLq1CFcuH7nrsk2FXKmAN35hCATrk9YfETjsYTHNjPRVZn c6Lpy8ULaZ4Qg== 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 4.19 13/23] hwmon: (pc87360) Bounds check data->innr usage Date: Mon, 22 Jan 2024 10:17:53 -0500 Message-ID: <20240122151823.997644-13-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240122151823.997644-1-sashal@kernel.org> References: <20240122151823.997644-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 4.19.305 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 7e3697727537..d2b3137dccd4 100644 --- a/drivers/hwmon/pc87360.c +++ b/drivers/hwmon/pc87360.c @@ -1637,7 +1637,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