• Liran Alon's avatar
    KVM: VMX: Mark VMXArea with revision_id of physical CPU even when eVMCS enabled · 2307af1c
    Liran Alon authored
    When eVMCS is enabled, all VMCS allocated to be used by KVM are marked
    with revision_id of KVM_EVMCS_VERSION instead of revision_id reported
    by MSR_IA32_VMX_BASIC.
    
    However, even though not explictly documented by TLFS, VMXArea passed
    as VMXON argument should still be marked with revision_id reported by
    physical CPU.
    
    This issue was found by the following setup:
    * L0 = KVM which expose eVMCS to it's L1 guest.
    * L1 = KVM which consume eVMCS reported by L0.
    This setup caused the following to occur:
    1) L1 execute hardware_enable().
    2) hardware_enable() calls kvm_cpu_vmxon() to execute VMXON.
    3) L0 intercept L1 VMXON and execute handle_vmon() which notes
    vmxarea->revision_id != VMCS12_REVISION and therefore fails with
    nested_vmx_failInvalid() which sets RFLAGS.CF.
    4) L1 kvm_cpu_vmxon() don't check RFLAGS.CF for failure and therefore
    hardware_enable() continues as usual.
    5) L1 hardware_enable() then calls ept_sync_global() which executes
    INVEPT.
    6) L0 intercept INVEPT and execute handle_invept() which notes
    !vmx->nested.vmxon and thus raise a #UD to L1.
    7) Raised #UD caused L1 to panic.
    Reviewed-by: default avatarKrish Sadhukhan <krish.sadhukhan@oracle.com>
    Cc: stable@vger.kernel.org
    Fixes: 773e8a04Signed-off-by: default avatarLiran Alon <liran.alon@oracle.com>
    Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
    2307af1c
vmx.c 362 KB