Skip to content

Commit

Permalink
KVM: x86: check bounds of APIC maps
Browse files Browse the repository at this point in the history
They can't be violated now, but play it safe for the future.

Signed-off-by: Radim Krčmář <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
rkrcmar authored and bonzini committed Dec 4, 2014
1 parent fa834e9 commit 25995e5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions arch/x86/kvm/lapic.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,16 @@ static void recalculate_apic_map(struct kvm *kvm)
kvm_for_each_vcpu(i, vcpu, kvm) {
struct kvm_lapic *apic = vcpu->arch.apic;
u16 cid, lid;
u32 ldr;

new->phys_map[kvm_apic_id(apic)] = apic;
u32 ldr, aid;

aid = kvm_apic_id(apic);
ldr = kvm_apic_get_reg(apic, APIC_LDR);
cid = apic_cluster_id(new, ldr);
lid = apic_logical_id(new, ldr);

if (lid)
if (aid < ARRAY_SIZE(new->phys_map))
new->phys_map[aid] = apic;
if (lid && cid < ARRAY_SIZE(new->logical_map))
new->logical_map[cid][ffs(lid) - 1] = apic;
}
out:
Expand Down

0 comments on commit 25995e5

Please sign in to comment.