use rdmsr_safe() instead of rdmsr() for probing feature
authorsemarie <semarie@openbsd.org>
Sun, 6 Oct 2024 16:24:02 +0000 (16:24 +0000)
committersemarie <semarie@openbsd.org>
Sun, 6 Oct 2024 16:24:02 +0000 (16:24 +0000)
the second could raise general protection fault on non-existant MSR

fix with help of jsg@
ok dv@

sys/arch/amd64/amd64/cpu.c

index 60ce18d..42ea565 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cpu.c,v 1.193 2024/09/26 13:18:25 dv Exp $    */
+/*     $OpenBSD: cpu.c,v 1.194 2024/10/06 16:24:02 semarie Exp $       */
 /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
 
 /*-
@@ -904,8 +904,8 @@ cpu_init_vmm(struct cpu_info *ci)
                ci->ci_vmcs_pa = VMX_VMCS_PA_CLEAR;
                rw_init(&ci->ci_vmcs_lock, "vmcslock");
 
-               msr = rdmsr(IA32_VMX_EPT_VPID_CAP);
-               if (msr & IA32_EPT_VPID_CAP_INVEPT_CONTEXT)
+               if (rdmsr_safe(IA32_VMX_EPT_VPID_CAP, &msr) == 0 &&
+                   msr & IA32_EPT_VPID_CAP_INVEPT_CONTEXT)
                        ci->ci_vmm_cap.vcc_vmx.vmx_invept_mode =
                            IA32_VMX_INVEPT_SINGLE_CTX;
                else