Skip to content

Commit ea74005

Browse files
marpombonzini
authored andcommitted
KVM: x86: Protect DR-based index computations from Spectre-v1/L1TF attacks
This fixes a Spectre-v1/L1TF vulnerability in __kvm_set_dr() and kvm_get_dr(). Both kvm_get_dr() and kvm_set_dr() (a wrapper of __kvm_set_dr()) are exported symbols so KVM should tream them conservatively from a security perspective. Fixes: 020df07 ("KVM: move DR register access handling into generic code") 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 c926f2f commit ea74005

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

arch/x86/kvm/x86.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,9 +1063,11 @@ static u64 kvm_dr6_fixed(struct kvm_vcpu *vcpu)
10631063

10641064
static int __kvm_set_dr(struct kvm_vcpu *vcpu, int dr, unsigned long val)
10651065
{
1066+
size_t size = ARRAY_SIZE(vcpu->arch.db);
1067+
10661068
switch (dr) {
10671069
case 0 ... 3:
1068-
vcpu->arch.db[dr] = val;
1070+
vcpu->arch.db[array_index_nospec(dr, size)] = val;
10691071
if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP))
10701072
vcpu->arch.eff_db[dr] = val;
10711073
break;
@@ -1102,9 +1104,11 @@ EXPORT_SYMBOL_GPL(kvm_set_dr);
11021104

11031105
int kvm_get_dr(struct kvm_vcpu *vcpu, int dr, unsigned long *val)
11041106
{
1107+
size_t size = ARRAY_SIZE(vcpu->arch.db);
1108+
11051109
switch (dr) {
11061110
case 0 ... 3:
1107-
*val = vcpu->arch.db[dr];
1111+
*val = vcpu->arch.db[array_index_nospec(dr, size)];
11081112
break;
11091113
case 4:
11101114
/* fall through */

0 commit comments

Comments
 (0)