Skip to content

Commit 25a5ede

Browse files
marpombonzini
authored andcommitted
KVM: x86: Protect MSR-based index computations in fixed_msr_to_seg_unit() from Spectre-v1/L1TF attacks
This fixes a Spectre-v1/L1TF vulnerability in fixed_msr_to_seg_unit(). This function contains index computations based on the (attacker-controlled) MSR number. Fixes: de9aef5 ("KVM: MTRR: introduce fixed_mtrr_segment table") 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 4bf79cb commit 25a5ede

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/x86/kvm/mtrr.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,15 @@ static bool fixed_msr_to_seg_unit(u32 msr, int *seg, int *unit)
192192
break;
193193
case MSR_MTRRfix16K_80000 ... MSR_MTRRfix16K_A0000:
194194
*seg = 1;
195-
*unit = msr - MSR_MTRRfix16K_80000;
195+
*unit = array_index_nospec(
196+
msr - MSR_MTRRfix16K_80000,
197+
MSR_MTRRfix16K_A0000 - MSR_MTRRfix16K_80000 + 1);
196198
break;
197199
case MSR_MTRRfix4K_C0000 ... MSR_MTRRfix4K_F8000:
198200
*seg = 2;
199-
*unit = msr - MSR_MTRRfix4K_C0000;
201+
*unit = array_index_nospec(
202+
msr - MSR_MTRRfix4K_C0000,
203+
MSR_MTRRfix4K_F8000 - MSR_MTRRfix4K_C0000 + 1);
200204
break;
201205
default:
202206
return false;

0 commit comments

Comments
 (0)