Skip to content

Commit 4bf79cb

Browse files
marpombonzini
authored andcommitted
KVM: x86: Protect kvm_lapic_reg_write() from Spectre-v1/L1TF attacks
This fixes a Spectre-v1/L1TF vulnerability in kvm_lapic_reg_write(). This function contains index computations based on the (attacker-controlled) MSR number. Fixes: 0105d1a ("KVM: x2apic interface to lapic") 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 6705645 commit 4bf79cb

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

arch/x86/kvm/lapic.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,15 +1960,20 @@ int kvm_lapic_reg_write(struct kvm_lapic *apic, u32 reg, u32 val)
19601960
case APIC_LVTTHMR:
19611961
case APIC_LVTPC:
19621962
case APIC_LVT1:
1963-
case APIC_LVTERR:
1963+
case APIC_LVTERR: {
19641964
/* TODO: Check vector */
1965+
size_t size;
1966+
u32 index;
1967+
19651968
if (!kvm_apic_sw_enabled(apic))
19661969
val |= APIC_LVT_MASKED;
1967-
1968-
val &= apic_lvt_mask[(reg - APIC_LVTT) >> 4];
1970+
size = ARRAY_SIZE(apic_lvt_mask);
1971+
index = array_index_nospec(
1972+
(reg - APIC_LVTT) >> 4, size);
1973+
val &= apic_lvt_mask[index];
19691974
kvm_lapic_set_reg(apic, reg, val);
1970-
19711975
break;
1976+
}
19721977

19731978
case APIC_LVTT:
19741979
if (!kvm_apic_sw_enabled(apic))

0 commit comments

Comments
 (0)