From: Radu Rendec <rrendec@redhat.com>
To: Will Deacon <will@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org,
Rob Herring <robh@kernel.org>,
Sudeep Holla <sudeep.holla@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Borislav Petkov <bp@alien8.de>
Subject: Re: [PATCH] arm64: cacheinfo: Avoid out-of-bounds write to cacheinfo array
Date: Thu, 06 Feb 2025 10:22:33 -0500 [thread overview]
Message-ID: <2106533f69de3e9d699317fffb7cafb6eecce0c9.camel@redhat.com> (raw)
In-Reply-To: <20250206130213.GA3204@willie-the-truck>
On Thu, 2025-02-06 at 13:02 +0000, Will Deacon wrote:
> On Tue, Feb 04, 2025 at 10:55:53AM -0500, Radu Rendec wrote:
> > On Tue, 2025-02-04 at 12:39 +0000, Will Deacon wrote:
> > > On Thu, Jan 23, 2025 at 01:11:59PM -0500, Radu Rendec wrote:
> > > > diff --git a/arch/arm64/kernel/cacheinfo.c b/arch/arm64/kernel/cacheinfo.c
> > > > index d9c9218fa1fdd..77ffda7284754 100644
> > > > --- a/arch/arm64/kernel/cacheinfo.c
> > > > +++ b/arch/arm64/kernel/cacheinfo.c
> > > > @@ -101,16 +101,18 @@ int populate_cache_leaves(unsigned int cpu)
> > > > unsigned int level, idx;
> > > > enum cache_type type;
> > > > struct cpu_cacheinfo *this_cpu_ci = get_cpu_cacheinfo(cpu);
> > > > - struct cacheinfo *this_leaf = this_cpu_ci->info_list;
> > > > + struct cacheinfo *infos = this_cpu_ci->info_list;
> > > >
> > > > for (idx = 0, level = 1; level <= this_cpu_ci->num_levels &&
> > > > - idx < this_cpu_ci->num_leaves; idx++, level++) {
> > > > + idx < this_cpu_ci->num_leaves; level++) {
> > > > type = get_cache_type(level);
> > > > if (type == CACHE_TYPE_SEPARATE) {
> > > > - ci_leaf_init(this_leaf++, CACHE_TYPE_DATA, level);
> > > > - ci_leaf_init(this_leaf++, CACHE_TYPE_INST, level);
> > > > + if (idx + 2 > this_cpu_ci->num_leaves)
> > > > + break;
> > >
> > > Why are you checking 'idx + 2' rather than 'idx + 1'?
> >
> > I don't like "magic constants", and I thought "idx + 2" would be more
> > suggestive since 2 elements were added.
> >
> > The check is correct though. For example, if this_cpu_ci->num_leaves = 3
> > (the array size is 3) and idx = 2, then 2 + 2 > 3 is true, so you can't
> > add two more elements. On the other hand, if idx = 1, then 1 + 2 > 3 is
> > false, so you can add the two elements (at indices 1 and 2).
> >
> > If there's a strong preference for "idx + 1", I can change it. But then
> > of course ">" will need to change to ">=" as well.
>
> Might just be me, but I'd personally find that clearer given that we're
> assigning to infos[idx] and infos[idx + 1].
Fair enough. I don't feel strongly about it, and since nobody else has
chimed in, I will make the change and post v2.
--
Thanks,
Radu
prev parent reply other threads:[~2025-02-06 15:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-23 18:11 [PATCH] arm64: cacheinfo: Avoid out-of-bounds write to cacheinfo array Radu Rendec
2025-02-04 12:39 ` Will Deacon
2025-02-04 15:55 ` Radu Rendec
2025-02-06 13:02 ` Will Deacon
2025-02-06 15:22 ` Radu Rendec [this message]
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=2106533f69de3e9d699317fffb7cafb6eecce0c9.camel@redhat.com \
--to=rrendec@redhat.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=robh@kernel.org \
--cc=sudeep.holla@arm.com \
--cc=will@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox