From: Radim Krcmar <rkrcmar@redhat.com>
To: Liran Alon <liran.alon@oracle.com>
Cc: Dan Carpenter <dan.carpenter@oracle.com>,
Wanpeng Li <kernellwp@gmail.com>,
LKML <linux-kernel@vger.kernel.org>, kvm <kvm@vger.kernel.org>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH] KVM: LAPIC: Fix pv ipis out-of-bounds access
Date: Wed, 29 Aug 2018 15:55:40 +0200 [thread overview]
Message-ID: <20180829135539.GA15829@flask> (raw)
In-Reply-To: <485CA660-9423-45B7-848F-49E3D13D5CBD@oracle.com>
2018-08-29 13:43+0300, Liran Alon:
> Why is “min” defined as “int” instead of “unsigned int”?
> It represents the lowest APIC ID in bitmap so it can’t be negative…
Right,
I think the code would look better as something like (untested):
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 0cefba28c864..24fc84eb97d2 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -548,7 +548,7 @@ int kvm_apic_set_irq(struct kvm_vcpu *vcpu, struct kvm_lapic_irq *irq,
}
int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
- unsigned long ipi_bitmap_high, int min,
+ unsigned long ipi_bitmap_high, u32 min,
unsigned long icr, int op_64_bit)
{
int i;
@@ -557,6 +557,7 @@ int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
struct kvm_lapic_irq irq = {0};
int cluster_size = op_64_bit ? 64 : 32;
int count = 0;
+ unsigned long ipi_bitmap[2] = {ipi_bitmap_low, ipi_bitmap_high};
irq.vector = icr & APIC_VECTOR_MASK;
irq.delivery_mode = icr & APIC_MODE_MASK;
@@ -571,16 +572,14 @@ int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low,
rcu_read_lock();
map = rcu_dereference(kvm->arch.apic_map);
- /* Bits above cluster_size are masked in the caller. */
- for_each_set_bit(i, &ipi_bitmap_low, BITS_PER_LONG) {
- vcpu = map->phys_map[min + i]->vcpu;
- count += kvm_apic_set_irq(vcpu, &irq, NULL);
- }
+ if (min <= map->max_apic_id) {
+ size_t ipi_bitmap_size = MIN(sizeof(ipi_bitmap) * 8,
+ map->max_apic_id - min + 1);
- min += cluster_size;
- for_each_set_bit(i, &ipi_bitmap_high, BITS_PER_LONG) {
- vcpu = map->phys_map[min + i]->vcpu;
- count += kvm_apic_set_irq(vcpu, &irq, NULL);
+ for_each_set_bit(i, ipi_bitmap, ipi_bitmap_size) {
+ vcpu = map->phys_map[min + i]->vcpu;
+ count += kvm_apic_set_irq(vcpu, &irq, NULL);
+ }
}
rcu_read_unlock();
next prev parent reply other threads:[~2018-08-29 13:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-29 5:52 [PATCH] KVM: LAPIC: Fix pv ipis out-of-bounds access Wanpeng Li
2018-08-29 9:05 ` Liran Alon
2018-08-29 10:12 ` Dan Carpenter
2018-08-29 10:18 ` Dan Carpenter
2018-08-29 10:23 ` Wanpeng Li
2018-08-29 10:29 ` Dan Carpenter
2018-08-29 10:42 ` Wanpeng Li
2018-08-29 10:54 ` Dan Carpenter
2018-08-29 10:43 ` Liran Alon
2018-08-29 13:55 ` Radim Krcmar [this message]
2018-08-29 14:36 ` Radim Krcmar
2018-08-29 15:42 ` Radim Krcmar
2018-08-30 2:15 ` Wanpeng Li
-- strict thread matches above, loose matches on Subject: below --
2018-08-29 5:51 Wanpeng Li
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=20180829135539.GA15829@flask \
--to=rkrcmar@redhat.com \
--cc=dan.carpenter@oracle.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liran.alon@oracle.com \
--cc=pbonzini@redhat.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