From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 8D644C433EF for ; Fri, 24 Sep 2021 01:06:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65D3460F41 for ; Fri, 24 Sep 2021 01:06:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243676AbhIXBHj (ORCPT ); Thu, 23 Sep 2021 21:07:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240863AbhIXBHj (ORCPT ); Thu, 23 Sep 2021 21:07:39 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EBD3C061574; Thu, 23 Sep 2021 18:06:07 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id u22so12298194oie.5; Thu, 23 Sep 2021 18:06:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ArpQncnpQmSaNPsbvlT3rEkygRJSB+QsZ3dkPtwwBe0=; b=l+T916tq9xQJB1u3pK0jVjmfnXOhPhvuzGNUTDtKTHwjA6ySKT+1StK1eCjmhvFtOe LWDA8cuobfhzOuoBi7FKPc4+76w9poAX0MhV4Fueq9s77sZgGVk5Bpoc5wRxxj8PGiZC RwVeHludygeeX8h1X5UPloDg5Rzmus7SInQQLTz/fQtiGdTvf3SNxGL74jVW6zwXzVCQ XmzYKsTX8aStPGN1/OS7IuGysIQNTowl9bhKOb1MGgY4NX8ZkSZyDzc8uzH0HHUfSBCc ab4V/CFjkiPkvpCuwu7zY3ti2MkILVX45jXce4c5JEL7SS2W2aKCWD3rKUZuyEjZMYKs AavQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=ArpQncnpQmSaNPsbvlT3rEkygRJSB+QsZ3dkPtwwBe0=; b=uuxTvGvE3BAER1O7y6xwG2ZG9jzv+hcQtI33Qp7NTVVMQSVRVSMejZ/PQWqFNjDLvo uFKPlFeoJaS8UvKTKW30q7yrHeXEinD9oEFIRwokdRg2QCUKmbaDoDsOfk0Go8DQhLl5 9wtOzHVUAKJOmAAxTgTBOhkmrS7pI98f8Z2Je4tD3sO+8NbGXvyJ8mdNWG8Eekmisn4P MwU6otq255OIe2YKYfSmaYUas9JdpAdxprVJKb68tzb085rT7JZOMTUJtr264PjSlMpj mBhxyEPJwrJhta8MArKAIT5TC4cHxSqdk4ZEV47Vo3jz11RVFMDbWEJVXrk2zjS3/EqA Oi2Q== X-Gm-Message-State: AOAM531R7xt6xeL7Debo+G+aem4n7jdEEseXqtmOiMGrJ1LSim3AUJy7 6aULWBQhyLfQNR4XRSq2g5A= X-Google-Smtp-Source: ABdhPJzGDid0sKGbfIBrtk3UGtAEmAdTGjUMbRnzidj0RpdRfT61NKAidIg//pXt0Je0+1zTi84QVg== X-Received: by 2002:aca:645:: with SMTP id 66mr6054976oig.145.1632445566502; Thu, 23 Sep 2021 18:06:06 -0700 (PDT) Received: from server.roeck-us.net ([2600:1700:e321:62f0:329c:23ff:fee3:9d7c]) by smtp.gmail.com with ESMTPSA id 37sm667324oti.7.2021.09.23.18.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Sep 2021 18:06:05 -0700 (PDT) Sender: Guenter Roeck Date: Thu, 23 Sep 2021 18:06:04 -0700 From: Guenter Roeck To: Colin King Cc: Jean Delvare , Vadim Pasternak , linux-hwmon@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] hwmon: (mlxreg-fan): Fix out of bounds read on array fan->pwm Message-ID: <20210924010604.GA3029410@roeck-us.net> References: <20210920180921.16246-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210920180921.16246-1-colin.king@canonical.com> Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org On Mon, Sep 20, 2021 at 07:09:21PM +0100, Colin King wrote: > 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 Applied. Thanks, Guenter > --- > 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)