diff options
author | pd <pd@cvs.openbsd.org> | 2020-02-26 06:07:10 +0000 |
---|---|---|
committer | pd <pd@cvs.openbsd.org> | 2020-02-26 06:07:10 +0000 |
commit | 29e122a84a8e00436a66545abe35a6cb6730e850 (patch) | |
tree | 3015c1bae91b143c652d53af80746b81a4cd6cb6 | |
parent | dc28546f09e7f1d3e72bcb9d61173cbd03592e1a (diff) |
vmm(4): tighten rdmsr on svm
For MSRs not emulated or passed through explicitly, inject #GP.
With help from brynet@
Reported by Maxime Villard.
ok brynet@
-rw-r--r-- | sys/arch/amd64/amd64/vmm.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/sys/arch/amd64/amd64/vmm.c b/sys/arch/amd64/amd64/vmm.c index 386b8a07845..704f6e927c7 100644 --- a/sys/arch/amd64/amd64/vmm.c +++ b/sys/arch/amd64/amd64/vmm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vmm.c,v 1.262 2020/02/17 18:16:10 pd Exp $ */ +/* $OpenBSD: vmm.c,v 1.263 2020/02/26 06:07:09 pd Exp $ */ /* * Copyright (c) 2014 Mike Larkin <mlarkin@openbsd.org> * @@ -2062,6 +2062,9 @@ vcpu_reset_regs_svm(struct vcpu *vcpu, struct vcpu_reg_state *vrs) /* EFER is R/O so we can ensure the guest always has SVME */ svm_setmsrbr(vcpu, MSR_EFER); + /* allow reading TSC */ + svm_setmsrbr(vcpu, MSR_TSC); + /* Guest VCPU ASID */ if (vmm_alloc_vpid(&asid)) { DPRINTF("%s: could not allocate asid\n", __func__); @@ -6181,10 +6184,10 @@ vmx_handle_wrmsr(struct vcpu *vcpu) int svm_handle_msr(struct vcpu *vcpu) { - uint64_t insn_length, msr; + uint64_t insn_length; uint64_t *rax, *rcx, *rdx; struct vmcb *vmcb = (struct vmcb *)vcpu->vc_control_va; - int i, ret; + int ret; /* XXX: Validate RDMSR / WRMSR insn_length */ insn_length = 2; @@ -6209,23 +6212,21 @@ svm_handle_msr(struct vcpu *vcpu) } } else { switch (*rcx) { - case MSR_LS_CFG: - DPRINTF("%s: guest read LS_CFG msr, injecting " - "#GP\n", __func__); + case MSR_DE_CFG: + /* LFENCE seralizing bit is set by host */ + *rax = DE_CFG_SERIALIZE_LFENCE; + *rdx = 0; + break; + case MSR_INT_PEN_MSG: + *rax = 0; + *rdx = 0; + break; + default: + DPRINTF("%s: guest read msr 0x%llx, injecting " + "#GP\n", __func__, *rcx); ret = vmm_inject_gp(vcpu); return (ret); } - - i = rdmsr_safe(*rcx, &msr); - if (i == 0) { - *rax = msr & 0xFFFFFFFFULL; - *rdx = msr >> 32; - } else { - DPRINTF("%s: rdmsr for unsupported MSR 0x%llx\n", - __func__, *rcx); - *rax = 0; - *rdx = 0; - } } vcpu->vc_gueststate.vg_rip += insn_length; |