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 EEC97C001DF for ; Mon, 31 Jul 2023 23:17:33 +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-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=U3Qlbl/9E4f9IpvPrQ/SM+ydPhTuuN5ZNMBI6j6BR9o=; b=mDS4ZJEKOELaXX B2ZGuWzuOgSn6/OfE65MLGTrV1EgC04UD9ehUOlX5plAIhUYm8bNgWrCGDXQ3i6T5cbLgaWDjkUMY g72/S9KvjJ3F37Lp6Zzam1bOwBDX5GPMARIy90vSFk400X44nH+42eTmaN8sHbrTkVswNQkgUD9s2 ZR2xxtPbgil0NRt4X/3xX/4MSgi63z+I7ohgccmQG9Ta3IsExfVBEGRnIMialWc+XiAnfgVVel+z+ vb2++xC+8Vdd0uKkImYcdhzf2w97l2xUiXd5QzimgJWRVeqec83LYarzoDfDXf9/IgThMHQ04V6UK knPdKkrTRAMCQuUnXWDQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qQc8Q-00HYVG-26; Mon, 31 Jul 2023 23:17:06 +0000 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qQc8N-00HYUl-04 for linux-arm-kernel@lists.infradead.org; Mon, 31 Jul 2023 23:17:04 +0000 Received: by mail-oi1-x229.google.com with SMTP id 5614622812f47-3a7293bb9daso1180335b6e.1 for ; Mon, 31 Jul 2023 16:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1690845419; x=1691450219; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=F8ua9oJZuaplLKApOoOkZO4imSzRRPEkrxgh9MzX6eQ=; b=MRoUyK3tDM70iZUtX070fFz+firyj2lfTJ1XnXANIO+ivnv8m8bTICXQgqrH8gx49f 526lqY3qDTC6OXQpTVm6V9nlEyOnznV/7rw5cWJCQdvnqQtJnECaLtFS2qKcrZrj3pRZ K2wPcUMxIn2jEisqWgZuO7jL+1dK69RjZY2jU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690845419; x=1691450219; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=F8ua9oJZuaplLKApOoOkZO4imSzRRPEkrxgh9MzX6eQ=; b=EtgF8k878/eStHMlmzDQGziUSZGbbq4kOoAes7qkUZjU80pY21Ructs6LkIDWfH2vN uXBl+KUTEeMTzzoAJHypBu9i8Y25gySMdUNCVBlrDboghYUcReqs8rRgI/0xEfpwziCq 6NQE5BKrgHft2RK4AYgRNzRc0t7Pc786bwoEszL+eKxMQo9bfmN9es1l5qO1UfSsyvlf fh4tQdbJ5c2wpJQkgrbiArQos+DHhmF1UPUwwjnurfFUxp8Af4oOyQA/h26UjAeOpyXE QgETODFtzzzDeHUbrwlbodlxXbgsxmnlbzR3AnWqbjMIUSFjsMkZnbFK6ctuCmo82Wr2 bV4g== X-Gm-Message-State: ABy/qLaQG9Ou3G2f3tY7uFQ54UU82+LMZNZR0djYvmb06Y4KpFgTkzDq h34OMx6U5+GsKpuQq4DZjzoSCQ== X-Google-Smtp-Source: APBJJlHW6hb0A5gM3w1lWC0L6AnstuIDB765N0cHvSxfZb4GZ25ntHbzjG+bjp5400aNwHH7nIm3BQ== X-Received: by 2002:a54:4390:0:b0:3a7:2d21:2916 with SMTP id u16-20020a544390000000b003a72d212916mr4865294oiv.9.1690845419333; Mon, 31 Jul 2023 16:16:59 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id c29-20020a63725d000000b005348af1b84csm8663037pgn.74.2023.07.31.16.16.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 16:16:58 -0700 (PDT) Date: Mon, 31 Jul 2023 16:16:58 -0700 From: Kees Cook To: "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 Subject: Re: [PATCH v2] cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug Message-ID: <202307311610.B1EB796684@keescook> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230731_161703_511726_91C61390 X-CRM114-Status: GOOD ( 16.67 ) 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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. > [...] > - for (i = AVS_PSTATE_P0; i <= AVS_PSTATE_MAX; i++) { > + for (i = AVS_PSTATE_P0; i < AVS_PSTATE_MAX; i++) { > ret = brcm_avs_set_pstate(priv, i); > if (ret) > return ERR_PTR(ret); -Kees -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel