Skip to content

Commit 0185604

Browse files
Andrew Honigbonzini
authored andcommitted
KVM: x86: Reload pit counters for all channels when restoring state
Currently if userspace restores the pit counters with a count of 0 on channels 1 or 2 and the guest attempts to read the count on those channels, then KVM will perform a mod of 0 and crash. This will ensure that 0 values are converted to 65536 as per the spec. This is CVE-2015-7513. Signed-off-by: Andy Honig <ahonig@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent e24dea2 commit 0185604

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
@@ -3572,9 +3572,11 @@ static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps)
35723572

35733573
static int kvm_vm_ioctl_set_pit(struct kvm *kvm, struct kvm_pit_state *ps)
35743574
{
3575+
int i;
35753576
mutex_lock(&kvm->arch.vpit->pit_state.lock);
35763577
memcpy(&kvm->arch.vpit->pit_state, ps, sizeof(struct kvm_pit_state));
3577-
kvm_pit_load_count(kvm, 0, ps->channels[0].count, 0);
3578+
for (i = 0; i < 3; i++)
3579+
kvm_pit_load_count(kvm, i, ps->channels[i].count, 0);
35783580
mutex_unlock(&kvm->arch.vpit->pit_state.lock);
35793581
return 0;
35803582
}
@@ -3593,6 +3595,7 @@ static int kvm_vm_ioctl_get_pit2(struct kvm *kvm, struct kvm_pit_state2 *ps)
35933595
static int kvm_vm_ioctl_set_pit2(struct kvm *kvm, struct kvm_pit_state2 *ps)
35943596
{
35953597
int start = 0;
3598+
int i;
35963599
u32 prev_legacy, cur_legacy;
35973600
mutex_lock(&kvm->arch.vpit->pit_state.lock);
35983601
prev_legacy = kvm->arch.vpit->pit_state.flags & KVM_PIT_FLAGS_HPET_LEGACY;
@@ -3602,7 +3605,8 @@ static int kvm_vm_ioctl_set_pit2(struct kvm *kvm, struct kvm_pit_state2 *ps)
36023605
memcpy(&kvm->arch.vpit->pit_state.channels, &ps->channels,
36033606
sizeof(kvm->arch.vpit->pit_state.channels));
36043607
kvm->arch.vpit->pit_state.flags = ps->flags;
3605-
kvm_pit_load_count(kvm, 0, kvm->arch.vpit->pit_state.channels[0].count, start);
3608+
for (i = 0; i < 3; i++)
3609+
kvm_pit_load_count(kvm, i, kvm->arch.vpit->pit_state.channels[i].count, start);
36063610
mutex_unlock(&kvm->arch.vpit->pit_state.lock);
36073611
return 0;
36083612
}

0 commit comments

Comments
 (0)