]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: VMX: Flush shadow VMCS on emergency reboot
authorChao Gao <chao.gao@intel.com>
Mon, 24 Mar 2025 14:08:48 +0000 (22:08 +0800)
committerSean Christopherson <seanjc@google.com>
Mon, 28 Apr 2025 17:57:56 +0000 (10:57 -0700)
Ensure the shadow VMCS cache is evicted during an emergency reboot to
prevent potential memory corruption if the cache is evicted after reboot.

This issue was identified through code inspection, as __loaded_vmcs_clear()
flushes both the normal VMCS and the shadow VMCS.

Avoid checking the "launched" state during an emergency reboot, unlike the
behavior in __loaded_vmcs_clear(). This is important because reboot NMIs
can interfere with operations like copy_shadow_to_vmcs12(), where shadow
VMCSes are loaded directly using VMPTRLD. In such cases, if NMIs occur
right after the VMCS load, the shadow VMCSes will be active but the
"launched" state may not be set.

Fixes: 16f5b9034b69 ("KVM: nVMX: Copy processor-specific shadow-vmcs to VMCS12")
Cc: stable@vger.kernel.org
Signed-off-by: Chao Gao <chao.gao@intel.com>
Reviewed-by: Kai Huang <kai.huang@intel.com>
Link: https://lore.kernel.org/r/20250324140849.2099723-1-chao.gao@intel.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/vmx/vmx.c

index ef2d7208dd208a4ccad3ea5a0cf4b657f7a50f11..848c4963bdb8ef011dd3931790fda43503ab2f8e 100644 (file)
@@ -770,8 +770,11 @@ void vmx_emergency_disable_virtualization_cpu(void)
                return;
 
        list_for_each_entry(v, &per_cpu(loaded_vmcss_on_cpu, cpu),
-                           loaded_vmcss_on_cpu_link)
+                           loaded_vmcss_on_cpu_link) {
                vmcs_clear(v->vmcs);
+               if (v->shadow_vmcs)
+                       vmcs_clear(v->shadow_vmcs);
+       }
 
        kvm_cpu_vmxoff();
 }