Re: [syzbot] WARNING in static_key_slow_try_dec (2)

From: Tetsuo Handa
Date: Sun Oct 10 2021 - 01:34:32 EST


Hello.

Commit 4547700a4d190ac4 ("KVM: x86: Consolidate APIC base RESET initialization code")
changed the location to set MSR_IA32_APICBASE_ENABLE flag. And syzbot is reporting
underflow bug due to too late initialization of vcpu->arch.apic_base member. We need to
make sure that vcpu->arch.apic_base is initialized before kvm_free_lapic() is called.

kvm_vm_ioctl() {
kvm_vm_ioctl_create_vcpu() {
kvm_arch_vcpu_create() {
if (something_went_wrong)
goto fail_free_lapic;
/* vcpu->arch.apic_base is initialized when something_went_wrong is false. */
kvm_vcpu_reset() {
kvm_lapic_reset(struct kvm_vcpu *vcpu, bool init_event) {
vcpu->arch.apic_base = APIC_DEFAULT_PHYS_BASE | MSR_IA32_APICBASE_ENABLE;
}
}
return 0;
fail_free_lapic:
kvm_free_lapic() {
/* vcpu->arch.apic_base is not yet initialized when something_went_wrong is true. */
if (!(vcpu->arch.apic_base & MSR_IA32_APICBASE_ENABLE))
static_branch_slow_dec_deferred(&apic_hw_disabled); // <= underflow bug.
}
return r;
}
}
}