All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: Avoid NULL dereference in kvm_apic_accept_pic_intr()
@ 2012-02-07  6:32 Michael Ellerman
  2012-02-07 19:38 ` Marcelo Tosatti
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Ellerman @ 2012-02-07  6:32 UTC (permalink / raw)
  To: kvm; +Cc: avi, mtosatti

A test case which does the following:

 ioctl(vmfd, KVM_CREATE_VCPU, 0);
 ioctl(vmfd, KVM_CREATE_IRQCHIP);
 ioctl(cpufd, KVM_RUN);

Can oops in kvm_apic_accept_pic_intr() because vcpu->arch.apic == NULL.

Because irqchip_in_kernel() is false when we create the vcpu we leave
vcpu->arch.apic uninitialised (in kvm_arch_vcpu_init()). Then when we run,
irqchip_in_kernel() is true, but we didn't do the correct initialisation.

The root of the problem seems to be that there is an assumption that
KVM_CREATE_IRQCHIP will be called before any VCPUs are created. The
documentation says "sets up future vcpus to have a local APIC".

So the simplest fix seems to be to enforce that ordering in the code.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/x86/kvm/x86.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 14d6cad..27dd380 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3110,6 +3110,9 @@ long kvm_arch_vm_ioctl(struct file *filp,
 		r = -EEXIST;
 		if (kvm->arch.vpic)
 			goto create_irqchip_unlock;
+		r = -EINVAL;
+		if (atomic_read(&kvm->online_vcpus))
+			goto create_irqchip_unlock;
 		r = -ENOMEM;
 		vpic = kvm_create_pic(kvm);
 		if (vpic) {
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-03-04 10:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-07  6:32 [PATCH] KVM: x86: Avoid NULL dereference in kvm_apic_accept_pic_intr() Michael Ellerman
2012-02-07 19:38 ` Marcelo Tosatti
2012-02-08 10:41   ` Michael Ellerman
2012-02-08 12:13     ` Michael Ellerman
2012-03-04  9:51       ` Avi Kivity
2012-03-04 10:14         ` Avi Kivity

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.