LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>,
Maxim Levitsky <mlevitsk@redhat.com>,
kvm@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
Nitesh Narayan Lal <nitesh@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 4/4] KVM: x86: Fix stack-out-of-bounds memory access from ioapic_write_indirect()
Date: Thu, 26 Aug 2021 14:13:56 -0400 [thread overview]
Message-ID: <20210826181356.xhsie7kkqoeukeju@habkost.net> (raw)
In-Reply-To: <YSfW62JxXXBI1/UE@google.com>
On Thu, Aug 26, 2021 at 06:01:15PM +0000, Sean Christopherson wrote:
> On Thu, Aug 26, 2021, Eduardo Habkost wrote:
> > > @@ -918,7 +918,7 @@ static bool kvm_apic_is_broadcast_dest(struct kvm *kvm, struct kvm_lapic **src,
> > > static inline bool kvm_apic_map_get_dest_lapic(struct kvm *kvm,
> > > struct kvm_lapic **src, struct kvm_lapic_irq *irq,
> > > struct kvm_apic_map *map, struct kvm_lapic ***dst,
> > > - unsigned long *bitmap)
> > > + unsigned long *bitmap64)
> >
> > You can communicate the expected bitmap size to the compiler
> > without typedefs if using DECLARE_BITMAP inside the function
> > parameter list is acceptable coding style (is it?).
> >
> > For example, the following would have allowed the compiler to
> > catch the bug you are fixing:
> >
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> > diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
> > index d7c25d0c1354..e8c64747121a 100644
> > --- a/arch/x86/kvm/lapic.h
> > +++ b/arch/x86/kvm/lapic.h
> > @@ -236,7 +236,7 @@ bool kvm_apic_pending_eoi(struct kvm_vcpu *vcpu, int vector);
> > void kvm_wait_lapic_expire(struct kvm_vcpu *vcpu);
> >
> > void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq,
> > - unsigned long *vcpu_bitmap);
> > + DECLARE_BITMAP(vcpu_bitmap, KVM_MAX_VCPUS));
> >
> > bool kvm_intr_is_single_vcpu_fast(struct kvm *kvm, struct kvm_lapic_irq *irq,
> > struct kvm_vcpu **dest_vcpu);
> > diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
> > index 76fb00921203..1df113894cba 100644
> > --- a/arch/x86/kvm/lapic.c
> > +++ b/arch/x86/kvm/lapic.c
> > @@ -1166,7 +1166,7 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode,
> > * each available vcpu to identify the same.
> > */
> > void kvm_bitmap_or_dest_vcpus(struct kvm *kvm, struct kvm_lapic_irq *irq,
> > - unsigned long *vcpu_bitmap)
> > + DECLARE_BITMAP(vcpu_bitmap, KVM_MAX_VCPUS))
> > {
> > struct kvm_lapic **dest_vcpu = NULL;
> > struct kvm_lapic *src = NULL;
>
> Sadly, that would not have actually caught the bug. In C++, an array param does
> indeed have a fixed size, but in C an array param is nothing more than syntatic
> sugar that is demoted to a plain ol' pointer. E.g. gcc-10 and clang-11 both
> happily compile with "DECLARE_BITMAP(vcpu_bitmap, 0)" and the original single
> "unsigned long vcpu_bitmap". Maybe there are gcc extensions to enforce array
> sizes? But if there are, they are not (yet) enabled for kernel builds.
The compiler wouldn't have caught it today only because Linux is
compiled with `-Wno-stringop-overflow`. I have some hope that
eventually the warning will be enabled, as indicated on the
commit message if commit 5a76021c2eff ("gcc-10: disable
'stringop-overflow' warning for now").
Even if the warning isn't enabled, the bitmap size declaration
would be a hint for humans reading the code.
--
Eduardo
next prev parent reply other threads:[~2021-08-26 18:14 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-23 14:30 [PATCH v2 0/4] KVM: Various fixes and improvements around kicking vCPUs Vitaly Kuznetsov
2021-08-23 14:30 ` [PATCH v2 1/4] KVM: Clean up benign vcpu->cpu data races when " Vitaly Kuznetsov
2021-08-23 14:30 ` [PATCH v2 2/4] KVM: Guard cpusmask NULL check with CONFIG_CPUMASK_OFFSTACK Vitaly Kuznetsov
2021-08-23 14:30 ` [PATCH v2 3/4] KVM: Optimize kvm_make_vcpus_request_mask() a bit Vitaly Kuznetsov
2021-08-23 14:30 ` [PATCH v2 4/4] KVM: x86: Fix stack-out-of-bounds memory access from ioapic_write_indirect() Vitaly Kuznetsov
2021-08-23 18:58 ` Eduardo Habkost
2021-08-24 7:13 ` Vitaly Kuznetsov
2021-08-24 14:23 ` Eduardo Habkost
2021-08-24 14:42 ` Vitaly Kuznetsov
2021-08-24 16:07 ` Maxim Levitsky
2021-08-24 17:40 ` Sean Christopherson
2021-08-25 8:26 ` Vitaly Kuznetsov
2021-08-25 8:21 ` Vitaly Kuznetsov
2021-08-25 9:11 ` Maxim Levitsky
2021-08-25 9:43 ` Vitaly Kuznetsov
2021-08-25 10:41 ` Maxim Levitsky
2021-08-25 13:19 ` Eduardo Habkost
2021-08-26 12:40 ` Vitaly Kuznetsov
2021-08-26 14:52 ` Eduardo Habkost
2021-08-26 18:01 ` Sean Christopherson
2021-08-26 18:13 ` Eduardo Habkost [this message]
2021-08-26 19:27 ` Eduardo Habkost
2021-08-30 19:47 ` Nitesh Lal
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=20210826181356.xhsie7kkqoeukeju@habkost.net \
--to=ehabkost@redhat.com \
--cc=dgilbert@redhat.com \
--cc=jmattson@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mlevitsk@redhat.com \
--cc=nitesh@redhat.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/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;
as well as URLs for NNTP newsgroup(s).