Skip to content

Commit a073d7e

Browse files
Wanpeng Libonzini
Wanpeng Li
authored andcommitted
KVM: hyperv: Fix Direct Synthetic timers assert an interrupt w/o lapic_in_kernel
Reported by syzkaller: kasan: GPF could be caused by NULL-ptr deref or user memory access general protection fault: 0000 [#1] PREEMPT SMP KASAN RIP: 0010:__apic_accept_irq+0x46/0x740 arch/x86/kvm/lapic.c:1029 Call Trace: kvm_apic_set_irq+0xb4/0x140 arch/x86/kvm/lapic.c:558 stimer_notify_direct arch/x86/kvm/hyperv.c:648 [inline] stimer_expiration arch/x86/kvm/hyperv.c:659 [inline] kvm_hv_process_stimers+0x594/0x1650 arch/x86/kvm/hyperv.c:686 vcpu_enter_guest+0x2b2a/0x54b0 arch/x86/kvm/x86.c:7896 vcpu_run+0x393/0xd40 arch/x86/kvm/x86.c:8152 kvm_arch_vcpu_ioctl_run+0x636/0x900 arch/x86/kvm/x86.c:8360 kvm_vcpu_ioctl+0x6cf/0xaf0 arch/x86/kvm/../../../virt/kvm/kvm_main.c:2765 The testcase programs HV_X64_MSR_STIMERn_CONFIG/HV_X64_MSR_STIMERn_COUNT, in addition, there is no lapic in the kernel, the counters value are small enough in order that kvm_hv_process_stimers() inject this already-expired timer interrupt into the guest through lapic in the kernel which triggers the NULL deferencing. This patch fixes it by don't advertise direct mode synthetic timers and discarding the inject when lapic is not in kernel. syzkaller source: https://syzkaller.appspot.com/x/repro.c?x=1752fe0a600000 Reported-by: [email protected] Cc: Paolo Bonzini <[email protected]> Cc: Radim Krčmář <[email protected]> Signed-off-by: Wanpeng Li <[email protected]> Reviewed-by: Vitaly Kuznetsov <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 319109a commit a073d7e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

arch/x86/kvm/hyperv.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,9 @@ static int stimer_notify_direct(struct kvm_vcpu_hv_stimer *stimer)
645645
.vector = stimer->config.apic_vector
646646
};
647647

648-
return !kvm_apic_set_irq(vcpu, &irq, NULL);
648+
if (lapic_in_kernel(vcpu))
649+
return !kvm_apic_set_irq(vcpu, &irq, NULL);
650+
return 0;
649651
}
650652

651653
static void stimer_expiration(struct kvm_vcpu_hv_stimer *stimer)
@@ -1852,7 +1854,13 @@ int kvm_vcpu_ioctl_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid,
18521854

18531855
ent->edx |= HV_FEATURE_FREQUENCY_MSRS_AVAILABLE;
18541856
ent->edx |= HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE;
1855-
ent->edx |= HV_STIMER_DIRECT_MODE_AVAILABLE;
1857+
1858+
/*
1859+
* Direct Synthetic timers only make sense with in-kernel
1860+
* LAPIC
1861+
*/
1862+
if (lapic_in_kernel(vcpu))
1863+
ent->edx |= HV_STIMER_DIRECT_MODE_AVAILABLE;
18561864

18571865
break;
18581866

0 commit comments

Comments
 (0)