From: Sean Christopherson <seanjc@google.com>
To: Jim Mattson <jmattson@google.com>
Cc: David Woodhouse <dwmw2@infradead.org>,
Thijs Raymakers <thijs@raymakers.nl>,
kvm@vger.kernel.org, Anel Orazgaliyeva <anelkz@amazon.de>,
stable <stable@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v3] KVM: x86: use array_index_nospec with indices that come from guest
Date: Thu, 5 Mar 2026 14:29:11 -0800 [thread overview]
Message-ID: <aaoDtzpY-2y-c-66@google.com> (raw)
In-Reply-To: <CALMp9eTSb3YrLRxnSbYQmAsK1SKA3Job6z2VjUWcKpPOGbWvRw@mail.gmail.com>
On Thu, Mar 05, 2026, Jim Mattson wrote:
> On Thu, Mar 5, 2026 at 12:31 PM David Woodhouse <dwmw2@infradead.org> wrote:
> >
> > On Mon, 2025-08-04 at 08:44 +0200, Thijs Raymakers wrote:
> > > min and dest_id are guest-controlled indices. Using array_index_nospec()
> > > after the bounds checks clamps these values to mitigate speculative execution
> > > side-channels.
> > >
> >
> > (commit c87bd4dd43a6)
> >
> > Is this sufficient in the __pv_send_ipi() case?
> >
> > > --- a/arch/x86/kvm/lapic.c
> > > +++ b/arch/x86/kvm/lapic.c
> > > @@ -852,6 +852,8 @@ static int __pv_send_ipi(unsigned long *ipi_bitmap, struct kvm_apic_map *map,
> > > if (min > map->max_apic_id)
> > > return 0;
> > >
> > > + min = array_index_nospec(min, map->max_apic_id + 1);
> > > +
> > > for_each_set_bit(i, ipi_bitmap,
> > > min((u32)BITS_PER_LONG, (map->max_apic_id - min + 1))) {
> > > if (map->phys_map[min + i]) {
> > vcpu = map->phys_map[min + i]->vcpu;
> > count += kvm_apic_set_irq(vcpu, irq, NULL);
> > }
> > }
> >
> > Do we need to protect [min + i] in the loop, rather than just [min]?
> >
> > The end condition for the for_each_set_bit() loop does mean that it
> > won't actually execute past max_apic_id but is that sufficient to
> > protect against *speculative* execution?
> >
> > I have a variant of this which uses array_index_nospec(min+i, ...)
> > *inside* the loop.
>
> Heh. Me too!
LOL, OMG, get off your high horses you two and someone send a damn patch!
next prev parent reply other threads:[~2026-03-05 22:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-04 6:44 [PATCH v3] KVM: x86: use array_index_nospec with indices that come from guest Thijs Raymakers
2025-08-12 10:37 ` David Woodhouse
2025-08-12 19:48 ` Jim Mattson
2025-08-19 23:11 ` Sean Christopherson
2026-03-05 20:30 ` David Woodhouse
2026-03-05 22:22 ` Jim Mattson
2026-03-05 22:29 ` Sean Christopherson [this message]
2026-03-05 22:42 ` David Woodhouse
2026-03-06 1:54 ` Sean Christopherson
2026-03-06 8:05 ` David Woodhouse
2026-03-06 12:02 ` Thijs Raymakers
2026-03-06 10:45 ` Paolo Bonzini
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=aaoDtzpY-2y-c-66@google.com \
--to=seanjc@google.com \
--cc=anelkz@amazon.de \
--cc=dwmw2@infradead.org \
--cc=gregkh@linuxfoundation.org \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=stable@kernel.org \
--cc=thijs@raymakers.nl \
/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