]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: x86: Avoid theoretical NULL pointer dereference in kvm_irq_delivery_to_apic_fast()
authorVitaly Kuznetsov <vkuznets@redhat.com>
Wed, 10 Aug 2022 20:25:52 +0000 (23:25 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 25 Aug 2022 09:18:16 +0000 (11:18 +0200)
commit f36ff1cd62f49ca0f72c805fd3cf552c5818d5ce upstream

When kvm_irq_delivery_to_apic_fast() is called with APIC_DEST_SELF
shorthand, 'src' must not be NULL. Crash the VM with KVM_BUG_ON()
instead of crashing the host.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Message-Id: <20220325132140.25650-3-vkuznets@redhat.com>
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Stefan Ghinea <stefan.ghinea@windriver.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/x86/kvm/lapic.c

index 3696b4de9d99de97cc5ed80a1630a887b06e1f03..23480d8e4ef17fa80353ba2e275e2eaf6cf2a4ae 100644 (file)
@@ -955,6 +955,10 @@ bool kvm_irq_delivery_to_apic_fast(struct kvm *kvm, struct kvm_lapic *src,
        *r = -1;
 
        if (irq->shorthand == APIC_DEST_SELF) {
+               if (KVM_BUG_ON(!src, kvm)) {
+                       *r = 0;
+                       return true;
+               }
                *r = kvm_apic_set_irq(src->vcpu, irq, dest_map);
                return true;
        }