[PATCH v2 0/8] KVM: x86/hyperv: Fix racy usage of vcpu->arch.hyperv

From: Sean Christopherson

Date: Fri Jun 12 2026 - 19:06:33 EST


Fix a bug found by syzkaller (on a Google-internal kernel) where KVM consumes
a vCPU's HyperV structure before it's fully initialized, by concurrently
triggering PV TLB flushes (queues flushes into a vCPU's FIFO without holding
the vCPU's mutex) on a vCPU that is in the process of activating HyperV.

Harden against similar bugs by asserting the vcpu->mutex is held when using
the "normal" to_hv_vcpu(), same as we did for get_vmcs12() and
get_shadow_vmcs12() (also in response to cross-task races). To avoid false
positives when creating a vCPU, initialize vcpu_idx to -1, and treat the vCPU
as unreachable (other than the caller, obviously) if its index is -1.

v2:
- Init vcpu->vcpu_idx to -1, use that as a canary to detect the vCPU is
unreachable, and allow accessing Hyper-V state if the vCPU is otherwise
unreachable. [syzbot]

v1: https://lore.kernel.org/all/20260423140833.439512-1-seanjc@xxxxxxxxxx

Sean Christopherson (8):
KVM: x86/hyperv: Get target FIFO in hv_tlb_flush_enqueue(), not caller
KVM: x86/hyperv: Check for NULL vCPU Hyper-V object in
kvm_hv_get_tlb_flush_fifo()
KVM: x86/hyperv: Ensure vCPU's Hyper-V object is initialized on
cross-vCPU accesses
KVM: Initialize a vCPU's index to '-1' while it's being created
KVM: Move nVMX's lockdep logic for vcpu->mutex to a common helper
KVM: x86: Treat a vCPU as unreachable if its index is invalid
KVM: x86/hyperv: Assert vCPU's mutex is held in to_hv_vcpu()
KVM: x86/hyperv: Use {READ,WRITE}_ONCE for cross-task synic->active
accesses

arch/x86/kvm/hyperv.c | 64 +++++++++++++++++++++------------------
arch/x86/kvm/hyperv.h | 25 +++++++++++++--
arch/x86/kvm/vmx/nested.h | 6 ++--
include/linux/kvm_host.h | 7 +++++
virt/kvm/kvm_main.c | 2 ++
5 files changed, 67 insertions(+), 37 deletions(-)


base-commit: c1f7303302927f9cbf4efedf70f0512cde168c65
--
2.54.0.1136.gdb2ca164c4-goog