From: Kees Cook <keescook@chromium.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Markus Mayer <mmayer@broadcom.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Florian Fainelli <florian.fainelli@broadcom.com>,
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
Date: Mon, 31 Jul 2023 16:16:58 -0700 [thread overview]
Message-ID: <202307311610.B1EB796684@keescook> (raw)
In-Reply-To: <ZMgiiEmBORZRaobc@work>
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
WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Markus Mayer <mmayer@broadcom.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Florian Fainelli <florian.fainelli@broadcom.com>,
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
Date: Mon, 31 Jul 2023 16:16:58 -0700 [thread overview]
Message-ID: <202307311610.B1EB796684@keescook> (raw)
In-Reply-To: <ZMgiiEmBORZRaobc@work>
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
next prev parent reply other threads:[~2023-07-31 23:17 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-31 21:07 [PATCH v2] cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug Gustavo A. R. Silva
2023-07-31 21:07 ` Gustavo A. R. Silva
2023-07-31 23:16 ` Kees Cook [this message]
2023-07-31 23:16 ` Kees Cook
2023-08-01 3:20 ` Gustavo A. R. Silva
2023-08-01 3:20 ` Gustavo A. R. Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202307311610.B1EB796684@keescook \
--to=keescook@chromium.org \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=florian.fainelli@broadcom.com \
--cc=gustavoars@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mmayer@broadcom.com \
--cc=rafael@kernel.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.