KVM: x86: disallow KVM_{SET,GET}_LAPIC without allocated in-kernel lapic
authorMarcelo Tosatti <mtosatti@redhat.com>
Thu, 29 Oct 2009 15:44:16 +0000 (13:44 -0200)
committerAvi Kivity <avi@redhat.com>
Thu, 3 Dec 2009 07:32:23 +0000 (09:32 +0200)
Otherwise kvm might attempt to dereference a NULL pointer.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
arch/x86/kvm/x86.c

index 97f6f95..cd6fe0a 100644 (file)
@@ -1893,6 +1893,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
 
        switch (ioctl) {
        case KVM_GET_LAPIC: {
+               r = -EINVAL;
+               if (!vcpu->arch.apic)
+                       goto out;
                lapic = kzalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL);
 
                r = -ENOMEM;
@@ -1908,6 +1911,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
                break;
        }
        case KVM_SET_LAPIC: {
+               r = -EINVAL;
+               if (!vcpu->arch.apic)
+                       goto out;
                lapic = kmalloc(sizeof(struct kvm_lapic_state), GFP_KERNEL);
                r = -ENOMEM;
                if (!lapic)