Skip to content

Commit a5d5638

Browse files
committed
KVM: x86: Reject userspace attempts to access ARCH_CAPABILITIES w/o support
Reject userspace accesses to ARCH_CAPABILITIES if the MSR isn't supposed to exist, according to guest CPUID. However, "reject" accesses with KVM_MSR_RET_UNSUPPORTED, so that reads get '0' and writes of '0' are ignored if KVM advertised support ARCH_CAPABILITIES. KVM's ABI is that userspace must set guest CPUID prior to setting MSRs, and that setting MSRs that aren't supposed exist is disallowed (modulo the '0' exemption). Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent a103911 commit a5d5638

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

arch/x86/kvm/x86.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3795,8 +3795,9 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
37953795
vcpu->arch.microcode_version = data;
37963796
break;
37973797
case MSR_IA32_ARCH_CAPABILITIES:
3798-
if (!msr_info->host_initiated)
3799-
return 1;
3798+
if (!msr_info->host_initiated ||
3799+
!guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES))
3800+
return KVM_MSR_RET_UNSUPPORTED;
38003801
vcpu->arch.arch_capabilities = data;
38013802
break;
38023803
case MSR_IA32_PERF_CAPABILITIES:
@@ -4256,9 +4257,8 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
42564257
msr_info->data = vcpu->arch.microcode_version;
42574258
break;
42584259
case MSR_IA32_ARCH_CAPABILITIES:
4259-
if (!msr_info->host_initiated &&
4260-
!guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES))
4261-
return 1;
4260+
if (!guest_cpuid_has(vcpu, X86_FEATURE_ARCH_CAPABILITIES))
4261+
return KVM_MSR_RET_UNSUPPORTED;
42624262
msr_info->data = vcpu->arch.arch_capabilities;
42634263
break;
42644264
case MSR_IA32_PERF_CAPABILITIES:

0 commit comments

Comments
 (0)