From patchwork Fri Jun 2 08:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniil Dulov X-Patchwork-Id: 690074 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12580C7EE24 for ; Fri, 2 Jun 2023 09:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235106AbjFBJMs (ORCPT ); Fri, 2 Jun 2023 05:12:48 -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 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) Precedence: bulk List-ID: X-Mailing-List: linux-pm@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 +