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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 45A25C04E69 for ; Tue, 1 Aug 2023 03:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:From:References:Cc:To:Subject: MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ed7m+uWxOt6rZ8YvuP3Y0Es2s0N/2t/1efyzxbB3QC0=; b=vo3GMzSK0gcg4v T1E32UVnsO52z9sog5uR+nm23OM4lD9ksIRdtK132KMXeyNboBmr/1kFRtcPr36xdqKsei/gY99G/ /ThzZVqv7oODgj5rN+EgXulJTd7X75YzI4GxkqK7ZFje8dKnhAmct1ybmX+ySEJHlp/3UPPfpVGv0 7GP6Zs9x8x5gWYHRu/7zaIYhqkVHcs6xa+65WvXEMBANX8B7km66nmJjB7OWDnyPuQMx5J9UG0tao 9c2f0m2CEG7alOE0eqWRvN8M7Xp4+LbdQwp/pLqwCsPcgA4ujd39Mt2na852DolDj0oWJFgYlvr4T nNnL3r5RXU9+z0I6kSAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQfvW-000GUE-23; Tue, 01 Aug 2023 03:20:02 +0000 Received: from omta034.useast.a.cloudfilter.net ([44.202.169.33]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQfvQ-000GRX-1u for linux-arm-kernel@lists.infradead.org; Tue, 01 Aug 2023 03:20:01 +0000 Received: from eig-obgw-6009a.ext.cloudfilter.net ([10.0.30.184]) by cmsmtp with ESMTP id QRZBqfIgAez0CQfutq1IHP; Tue, 01 Aug 2023 03:19:23 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id Qfv1qZcwvvsSTQfv1qgKhh; Tue, 01 Aug 2023 03:19:32 +0000 X-Authority-Analysis: v=2.4 cv=C8P6dCD+ c=1 sm=1 tr=0 ts=64c879c4 a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=WzbPXH4gqzPVN0x6HrNMNA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=ws7JD89P4LkA:10 a=wYkD_t78qR0A:10 a=VwQbUJbxAAAA:8 a=IsyNV7-RnDjwaFrxwpMA:9 a=QEXdDO2ut3YA:10 a=AjGcO6oz07-iQ99wixmX:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=q8xDoc0e3lwDSHDguSa5+mR825k++nOURzgRi1L1QjM=; b=w0vRXLpPlYdxEw939A2MVixiqw osSgoVZQAZPQEm7lqCh5b0Tyh6FNxMmL0lx10kA0X/tRQkrzVaUQ51vWgqvLep0h+6yE14lc36Pa4 p6oaFQCebqtJc5egOX6KOxqWRZgnWQQf8tghftegCMdYYnft19+qi4hM0gFtD17aEMb6owVSdPdYy ilJWqff/aqNeXpdTzlX+AicmuLRUL+aTLci81Swb92upaukSQuY/sWwXRyUeARI1tipgDa1xI0Ux6 iHfk0fAhUgxt590w/aC7CJP4O6x+kh5XaA89JYH7pMUsYuSFMuK+Qi9HmkoxtSWGVKllrSB09qw1U bBkTnRbQ==; Received: from 187-162-21-192.static.axtel.net ([187.162.21.192]:60426 helo=[192.168.15.8]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1qQfv0-000Kd9-1K; Mon, 31 Jul 2023 22:19:31 -0500 Message-ID: <8d83bd2e-9e66-c5fc-e351-1d57f710296c@embeddedor.com> Date: Mon, 31 Jul 2023 21:20:17 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Subject: Re: [PATCH v2] cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug Content-Language: en-US To: Kees Cook , "Gustavo A. R. Silva" Cc: Markus Mayer , Broadcom internal kernel review list , "Rafael J. Wysocki" , Viresh Kumar , Florian Fainelli , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org References: <202307311610.B1EB796684@keescook> From: "Gustavo A. R. Silva" In-Reply-To: <202307311610.B1EB796684@keescook> 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 - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.162.21.192 X-Source-L: No X-Exim-ID: 1qQfv0-000Kd9-1K X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 187-162-21-192.static.axtel.net ([192.168.15.8]) [187.162.21.192]:60426 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 3 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfCba3LI9q0e2C5R9pqBw+xO2SIFzsuy9dgoOFGBT1tmQ/gl9516kHaXybFLLgIwrxifACOoJyvp7PJ8ol+ItVcnnpWV8345WQhpfjPF3nsk6HI/KEhA9 5UUDomr0he2pm3LODeUFJ0HVLMfiMAvgnNtCAkyzq4tdTBHVPrnab0MAYFOcdcMDVUHVbn2XF3ESIKYSoh8RX24Kt58utAwcZ1/jApNOoYThuMCRFKfvJu6n X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_201956_720121_3DD919BA X-CRM114-Status: GOOD ( 14.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 7/31/23 17:16, Kees Cook wrote: > On Mon, Jul 31, 2023 at 03:07:20PM -0600, Gustavo A. R. Silva wrote: >> Update the iteration conditions in the for() loop to avoid writing in >> array `table` beyond its allocated size at: >> >> drivers/cpufreq/brcmstb-avs-cpufreq.c: >> 449 table[i].frequency = CPUFREQ_TABLE_END; >> >> This fixes the following -Warray-bounds warning seen after building >> ARM with multi_v7_defconfig (GCC 13): >> In function 'brcm_avs_get_freq_table', >> inlined from 'brcm_avs_cpufreq_init' at drivers/cpufreq/brcmstb-avs-cpufreq.c:623:15: >> drivers/cpufreq/brcmstb-avs-cpufreq.c:449:28: warning: array subscript 5 is outside array bounds of 'void[60]' [-Warray-bounds=] >> 449 | table[i].frequency = CPUFREQ_TABLE_END; > > #define AVS_PSTATE_P0 0x0 > #define AVS_PSTATE_P1 0x1 > #define AVS_PSTATE_P2 0x2 > #define AVS_PSTATE_P3 0x3 > #define AVS_PSTATE_P4 0x4 > #define AVS_PSTATE_MAX AVS_PSTATE_P4 > > table = devm_kcalloc(dev, AVS_PSTATE_MAX + 1, sizeof(*table), > GFP_KERNEL); > ... > for (i = AVS_PSTATE_P0; i <= AVS_PSTATE_MAX; i++) { > ... > } > table[i].frequency = CPUFREQ_TABLE_END; > > I see "AVS_PSTATE_MAX + 1" being used for the allocation, and so the > loop is likely correctly doing P0 through P4. If there is supposed to be > a terminating element in the table, I think the correct fix would be to > allocate an additional element, not stop the loop from processing P4. Yeah; I think you're right. And it seems that this function header makes it clear, too: drivers/cpufreq/brcmstb-avs-cpufreq.c: 421 /* 422 * We determine which frequencies are supported by cycling through all P-states 423 * and reading back what frequency we are running at for each P-state. 424 */ 425 static struct cpufreq_frequency_table * 426 brcm_avs_get_freq_table(struct device *dev, struct private_data *priv) I just sent v3: https://lore.kernel.org/linux-hardening/ZMh45KH2iPIpNktr@work/ Let's see what the maintainers say. Thanks for the feedback! -- Gustavo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel