From patchwork Wed Dec 13 22:45:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 10111047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E8B94602B3 for ; Wed, 13 Dec 2017 23:09:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA94329603 for ; Wed, 13 Dec 2017 23:09:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEC792962B; Wed, 13 Dec 2017 23:09:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A12BE29603 for ; Wed, 13 Dec 2017 23:09:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751029AbdLMXJG (ORCPT ); Wed, 13 Dec 2017 18:09:06 -0500 Received: from gateway32.websitewelcome.com ([192.185.145.119]:25587 "EHLO gateway32.websitewelcome.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750785AbdLMXJF (ORCPT ); Wed, 13 Dec 2017 18:09:05 -0500 X-Greylist: delayed 1400 seconds by postgrey-1.27 at vger.kernel.org; Wed, 13 Dec 2017 18:09:05 EST Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway32.websitewelcome.com (Postfix) with ESMTP id 27C0DBEE2E2 for ; Wed, 13 Dec 2017 16:45:45 -0600 (CST) Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with SMTP id PFmbe5X6VODN4PFmbe9Bwp; Wed, 13 Dec 2017 16:45:45 -0600 Received: from [189.175.3.118] (port=45836 helo=embeddedor) by gator4166.hostgator.com with esmtpa (Exim 4.89) (envelope-from ) id 1ePFmZ-000fqj-W3; Wed, 13 Dec 2017 16:45:44 -0600 Date: Wed, 13 Dec 2017 16:45:41 -0600 From: "Gustavo A. R. Silva" To: "Rafael J. Wysocki" , Len Brown , George Cherian Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" Subject: [PATCH] ACPI / CPPC: Fix negative array index read in cppc_set_perf Message-ID: <20171213224541.GA31477@embeddedor.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 189.175.3.118 X-Source-L: No X-Exim-ID: 1ePFmZ-000fqj-W3 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: (embeddedor) [189.175.3.118]:45836 X-Source-Auth: garsilva@embeddedor.com X-Email-Count: 4 X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If pcc_ss_id is less than 0, there is a negative array index read before verifying pcc_ss_id is not a negative value. Fix this by removing the code that triggers this issue. Notice that this code is already properly placed after the check on pcc_ss_id at line 1182: pcc_ss_data = pcc_data[pcc_ss_id]; Addresses-Coverity-ID: 1426090 ("Negative array index read") Fixes: 1ecbd7170d65 ("ACPI / CPPC: Fix KASAN global out of bounds warning") Signed-off-by: Gustavo A. R. Silva Reviewed-by: George Cherian --- drivers/acpi/cppc_acpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 30e84cc..06ea474 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1171,7 +1171,7 @@ int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) struct cpc_desc *cpc_desc = per_cpu(cpc_desc_ptr, cpu); struct cpc_register_resource *desired_reg; int pcc_ss_id = per_cpu(cpu_pcc_subspace_idx, cpu); - struct cppc_pcc_data *pcc_ss_data = pcc_data[pcc_ss_id]; + struct cppc_pcc_data *pcc_ss_data; int ret = 0; if (!cpc_desc || pcc_ss_id < 0) {