Skip to content

Commit 7289fdb

Browse files
stevenrutherfordbonzini
authored andcommitted
KVM: Remove CREATE_IRQCHIP/SET_PIT2 race
Fixes a NULL pointer dereference, caused by the PIT firing an interrupt before the interrupt table has been initialized. SET_PIT2 can race with the creation of the IRQchip. In particular, if SET_PIT2 is called with a low PIT timer period (after the creation of the IOAPIC, but before the instantiation of the irq routes), the PIT can fire an interrupt at an uninitialized table. Signed-off-by: Steve Rutherford <[email protected]> Signed-off-by: Jon Cargille <[email protected]> Reviewed-by: Jim Mattson <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 56a87e5 commit 7289fdb

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
@@ -5049,10 +5049,13 @@ long kvm_arch_vm_ioctl(struct file *filp,
50495049
r = -EFAULT;
50505050
if (copy_from_user(&u.ps, argp, sizeof(u.ps)))
50515051
goto out;
5052+
mutex_lock(&kvm->lock);
50525053
r = -ENXIO;
50535054
if (!kvm->arch.vpit)
5054-
goto out;
5055+
goto set_pit_out;
50555056
r = kvm_vm_ioctl_set_pit(kvm, &u.ps);
5057+
set_pit_out:
5058+
mutex_unlock(&kvm->lock);
50565059
break;
50575060
}
50585061
case KVM_GET_PIT2: {
@@ -5072,10 +5075,13 @@ long kvm_arch_vm_ioctl(struct file *filp,
50725075
r = -EFAULT;
50735076
if (copy_from_user(&u.ps2, argp, sizeof(u.ps2)))
50745077
goto out;
5078+
mutex_lock(&kvm->lock);
50755079
r = -ENXIO;
50765080
if (!kvm->arch.vpit)
5077-
goto out;
5081+
goto set_pit2_out;
50785082
r = kvm_vm_ioctl_set_pit2(kvm, &u.ps2);
5083+
set_pit2_out:
5084+
mutex_unlock(&kvm->lock);
50795085
break;
50805086
}
50815087
case KVM_REINJECT_CONTROL: {

0 commit comments

Comments
 (0)