From patchwork Mon Sep 20 18:09:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 12506155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D59F9C433EF for ; Mon, 20 Sep 2021 18:11:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCA4E61A03 for ; Mon, 20 Sep 2021 18:11:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376548AbhITSMw (ORCPT ); Mon, 20 Sep 2021 14:12:52 -0400 Received: from smtp-relay-canonical-1.canonical.com ([185.125.188.121]:35254 "EHLO smtp-relay-canonical-1.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359090AbhITSKv (ORCPT ); Mon, 20 Sep 2021 14:10:51 -0400 Received: from localhost (1.general.cking.uk.vpn [10.172.193.212]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-1.canonical.com (Postfix) with ESMTPSA id F0B5B3F328; Mon, 20 Sep 2021 18:09:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1632161362; bh=1MOw3pBn5yZn8i9TpCdyOmpabZHlCyzS2R0H6XOTRXI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version:Content-Type; b=cVCLcvTM2TVoMt16SXlVJ71+YWdYtMotLXo0nRN7RYm++zX6WyllppDB/mzX4YSvv iY/oW26nPG3lA2FiQMr+Rwj1GsQqw8EP+/aUWT6wFjRzVS9VRfkGCGN9/BJ373g/+n mp2/uv+wQ/l3kmXH+2bKwpkt5XhNVDawgPJDzOsiPiU8aOBvBFfokch693AfrFnCxa TfYwfLIMMncYel61/1CNJ9CvZwoOS5IYojZz/H+OGyO/Dc1HrHZjLTZRuL7rSRRroC nnIBD7Mn6zV+Zw+ocFh5Q9mKPLUdXisCkcYa2mKxbSgSLBOO2w6h4uQZ3TrOTbfugp MGyjCRNxGTQrw== From: Colin King To: Jean Delvare , Guenter Roeck , Vadim Pasternak , linux-hwmon@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] hwmon: (mlxreg-fan): Fix out of bounds read on array fan->pwm Date: Mon, 20 Sep 2021 19:09:21 +0100 Message-Id: <20210920180921.16246-1-colin.king@canonical.com> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Colin Ian King Array fan->pwm[] is MLXREG_FAN_MAX_PWM elements in size, however the for-loop has a off-by-one error causing index i to be out of range causing an out of bounds read on the array. Fix this by replacing the <= operator with < in the for-loop. Addresses-Coverity: ("Out-of-bounds read") Fixes: 35edbaab3bbf ("hwmon: (mlxreg-fan) Extend driver to support multiply cooling devices") Signed-off-by: Colin Ian King --- drivers/hwmon/mlxreg-fan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hwmon/mlxreg-fan.c b/drivers/hwmon/mlxreg-fan.c index 35228ed112d7..feab9ec6a6ca 100644 --- a/drivers/hwmon/mlxreg-fan.c +++ b/drivers/hwmon/mlxreg-fan.c @@ -554,7 +554,7 @@ static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan) { int i, j; - for (i = 0; i <= MLXREG_FAN_MAX_PWM; i++) { + for (i = 0; i < MLXREG_FAN_MAX_PWM; i++) { struct mlxreg_fan_pwm *pwm = &fan->pwm[i]; if (!pwm->connected)