Skip to content

Commit 6ec4c5e

Browse files
marpombonzini
authored andcommitted
KVM: x86: Protect MSR-based index computations from Spectre-v1/L1TF attacks in x86.c
This fixes a Spectre-v1/L1TF vulnerability in set_msr_mce() and get_msr_mce(). Both functions contain index computations based on the (attacker-controlled) MSR number. Fixes: 890ca9a ("KVM: Add MCE support") Signed-off-by: Nick Finco <[email protected]> Signed-off-by: Marios Pomonis <[email protected]> Reviewed-by: Andrew Honig <[email protected]> Cc: [email protected] Reviewed-by: Jim Mattson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 13c5183 commit 6ec4c5e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,7 +2545,10 @@ static int set_msr_mce(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
25452545
default:
25462546
if (msr >= MSR_IA32_MC0_CTL &&
25472547
msr < MSR_IA32_MCx_CTL(bank_num)) {
2548-
u32 offset = msr - MSR_IA32_MC0_CTL;
2548+
u32 offset = array_index_nospec(
2549+
msr - MSR_IA32_MC0_CTL,
2550+
MSR_IA32_MCx_CTL(bank_num) - MSR_IA32_MC0_CTL);
2551+
25492552
/* only 0 or all 1s can be written to IA32_MCi_CTL
25502553
* some Linux kernels though clear bit 10 in bank 4 to
25512554
* workaround a BIOS/GART TBL issue on AMD K8s, ignore
@@ -2986,7 +2989,10 @@ static int get_msr_mce(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, bool host)
29862989
default:
29872990
if (msr >= MSR_IA32_MC0_CTL &&
29882991
msr < MSR_IA32_MCx_CTL(bank_num)) {
2989-
u32 offset = msr - MSR_IA32_MC0_CTL;
2992+
u32 offset = array_index_nospec(
2993+
msr - MSR_IA32_MC0_CTL,
2994+
MSR_IA32_MCx_CTL(bank_num) - MSR_IA32_MC0_CTL);
2995+
29902996
data = vcpu->arch.mce_banks[offset];
29912997
break;
29922998
}

0 commit comments

Comments
 (0)