[PATCH v5 0/6] KVM: nVMX: Synthesize SHUTDOWN on RSM with bad state
Sean Christopherson <[email protected]>
| Newsgroups | org.kernel.vger.kvm,org.kernel.vger.linux-kernel |
|---|---|
| Message-ID | <[email protected]> |
Synthesize SHUTDOWN if invalid guest state is detected a RSM, i.e. if SMRAM is clobbered by L1 (or host userspace) while handling an SMI that occurred while L2 was active. This fixes yet another case of syzkaller tripping KVM's sanity check that KVM doesn't cancel a pending nested VM-Enter. v5: - Fix goofs in patch 1. [Sashiko] - Print out correct target L1 vs. L2. [Sashiko] v4: - https://lore.kernel.org/all/[email protected] - Synthesize SHUTDOWN instead of trying to suppress the KVM_BUG_ON(). - Add a selftest. v3: - https://lore.kernel.org/all/[email protected] - Retain KVM_NESTED_RUN_PENDING_UNTRUSTED until after sync_vmcs02_to_vmcs12(), to avoid saving VMCS12 fields that are valid only after L2 has actually run. - Clear the untrusted pending state before restoring L1 state to avoid leaking nested_run_pending into L1 and blocking event injection. - Clarify the VMX pending-run BUG comment and update the changelog. - Tested with the syzkaller repro on the fixed kernel, no WARNING/KVM_BUG in the repro log v2: - https://lore.kernel.org/all/[email protected] - Mark nested state restored by RSM from SMRAM as KVM_NESTED_RUN_PENDING_UNTRUSTED. - Keep the BUG check in __vmx_handle_exit(), but make it apply only to KVM_NESTED_RUN_PENDING. v1: https://lore.kernel.org/all/[email protected] Hao Zhang (1): KVM: selftests: Extend the invalid nVMX guest state test to cover RSM Sean Christopherson (5): KVM: x86: Extract VMX's unhandleable emulation check to common x86 KVM: nVMX: Synthesize SHUTDOWN on RSM if L2 requires emulation KVM: x86: Rework kvm_x86_ops.vcpu_pre_run() into .vcpu_needs_initialization() KVM: selftests: Use port 0x80 in invalid nVMX guest state test KVM: selftests: Refactor invalid nVMX state test to prepare for RSM testcase arch/x86/include/asm/kvm-x86-ops.h | 3 +- arch/x86/include/asm/kvm_host.h | 4 +- arch/x86/kvm/smm.c | 4 + arch/x86/kvm/svm/sev.c | 5 + arch/x86/kvm/svm/svm.c | 12 +- arch/x86/kvm/svm/svm.h | 1 + arch/x86/kvm/vmx/main.c | 21 +++- arch/x86/kvm/vmx/tdx.c | 9 +- arch/x86/kvm/vmx/vmx.c | 12 +- arch/x86/kvm/vmx/x86_ops.h | 4 +- arch/x86/kvm/x86.c | 10 +- .../kvm/x86/vmx_invalid_nested_guest_state.c | 118 ++++++++++++++---- 12 files changed, 143 insertions(+), 60 deletions(-) base-commit: 3c7d7f908d574277a845423ec32250a8d8df44c8 -- 2.55.0.508.g3f0d502094-goog