Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1945265rwd; Fri, 2 Jun 2023 02:27:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4xKerfP4RTGzacD+YtNbAPphk3Mosa3jhieaYysENF/JAqRJRCc6BHMRu0KxypnSdD31Ef X-Received: by 2002:a92:4b08:0:b0:335:fc8:9b4 with SMTP id m8-20020a924b08000000b003350fc809b4mr8124303ilg.19.1685698041383; Fri, 02 Jun 2023 02:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685698041; cv=none; d=google.com; s=arc-20160816; b=yTh2ewGTH7BDjc6GV4NGsanErh0Wptb38UehQzcKgp/S9FSEPT7mDEhwsEnfSlnc0j 77EEANKaBGfg8ZoYm+wcT0ekwGqKqG0IEvUZB0tiA6bDqma0jQtdVh5qs/K/CWDoMyHI QOpXZYVATvSI+/N0N9rVNycUI8nFTjFjisUdVbyHBEMwDBtHiy5yIjiROE2O/ttJEv4p 4F3gt6vEEbDmKISyi10Fj04wvic5P4OD3fwGt7RfnaGi7/tlWJwbfyzs4tBcojoyA62j mGGGlT2PDwWdenXCDDYRp3Ci2zELXmIcTvP2YlEGqiJlMs2gDPvf0weQt80Xmt606B5O XQVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=0EW4q+l4tJr6iOg12Tei5XHVBbkzj3F/wFek7YoioTM=; b=iH8j3Yl0z7Rv2WeLVfXktVEt92XsE1gDnDEToPFLhvCak8Ymui6F8qCyMt6aVBywJa c9OE523uSdlNKLB3O401RDOS5tGCA6ZcbC1hEHJNnyAGF39iZRcnuF+rMwjf4L3ZUaKI Hw9FHXhaIOHqwKhPoXsdXTTxhL9+CDf6KLYaoyfhWj79pIW2dDOMmXfWhLok5lnHwA98 k9epvsQC7hWCjYf7tOiix7nK4RlVhVP0bTKrOKilzxclB21/4DVm+LRTtce8FJ4lriYH 0VCosAxNbyvfTKtb9cui1TTZua6VCOKH+2WoGNaaihK8UMr7j4Y5RdTQo3SBR8kkKdP9 if8A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aladdin.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q16-20020a631f50000000b0051b48085aaasi644840pgm.858.2023.06.02.02.27.07; Fri, 02 Jun 2023 02:27:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aladdin.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234834AbjFBJMt (ORCPT + 99 others); Fri, 2 Jun 2023 05:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234833AbjFBJMW (ORCPT ); Fri, 2 Jun 2023 05:12:22 -0400 X-Greylist: delayed 903 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 02 Jun 2023 02:10:57 PDT Received: from mail-out.aladdin-rd.ru (mail-out.aladdin-rd.ru [91.199.251.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15F50E5F; Fri, 2 Jun 2023 02:10:57 -0700 (PDT) From: Daniil Dulov To: Zhang Rui CC: Daniil Dulov , Daniel Lezcano , Amit Kucheria , "Rafael J. Wysocki" , Srinivas Pandruvada , Greg Kroah-Hartman , Chen Yu , Sasha Levin , Arjan van de Ven , Jacob Pan , , , Subject: [PATCH] thermal: intel_powerclamp: Check for a possible array out of bounds access. Date: Fri, 2 Jun 2023 01:55:46 -0700 Message-ID: <20230602085546.376086-1-d.dulov@aladdin.ru> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.0.20.125] X-ClientProxiedBy: EXCH-2016-02.aladdin.ru (192.168.1.102) To EXCH-2016-01.aladdin.ru (192.168.1.101) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ratio may be equal to MAX_TARGET_RATIO - 1 that will result in out of bound access. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: d6d71ee4a14a ("PM: Introduce Intel PowerClamp Driver") Signed-off-by: Daniil Dulov --- drivers/thermal/intel/intel_powerclamp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/intel/intel_powerclamp.c b/drivers/thermal/intel/intel_powerclamp.c index fb04470d7d4b..9deaf2b8ccf6 100644 --- a/drivers/thermal/intel/intel_powerclamp.c +++ b/drivers/thermal/intel/intel_powerclamp.c @@ -277,7 +277,8 @@ static unsigned int get_compensation(int ratio) comp = (cal_data[ratio].steady_comp + cal_data[ratio - 1].steady_comp + cal_data[ratio - 2].steady_comp) / 3; - } else if (cal_data[ratio].confidence >= CONFIDENCE_OK && + } else if (ratio < MAX_TARGET_RATIO - 1 && + cal_data[ratio].confidence >= CONFIDENCE_OK && cal_data[ratio - 1].confidence >= CONFIDENCE_OK && cal_data[ratio + 1].confidence >= CONFIDENCE_OK) { comp = (cal_data[ratio].steady_comp + -- 2.25.1