Skip to content

Commit 376e118

Browse files
00xcsean-jc
authored andcommitted
KVM: x86: Take PIC lock on KVM_GET_IRQCHIP path
When userspace issues the KVM_SET_IRQCHIP ioctl to set the state of the PIC, kvm_vm_ioctl_set_irqchip() grabs @kvm->arch.vpic->lock before updating the state. However, the KVM_GET_IRQCHIP ioctl to retrieve the same PIC state does not grab such lock, potentially causing torn reads for userspace. Fix this by grabbing the lock on the read path. This issue goes all the way back. The bug was introduced with the addition of PIC ioctl code itself in 6ceb9d7 ("KVM: Add get/ set irqchip ioctls for in-kernel PIC live migration support"). Later, 894a9c5 ("KVM: x86: missing locking in PIT/IRQCHIP/SET_BSP_CPU ioctl paths") added the locking for kvm_vm_ioctl_set_irqchip(), but missed kvm_vm_ioctl_get_irqchip(). Fixes: 6ceb9d7 ("KVM: Add get/set irqchip ioctls for in-kernel PIC live migration support") Fixes: 894a9c5 ("KVM: x86: missing locking in PIT/IRQCHIP/SET_BSP_CPU ioctl paths") Reported-by: Claude Code:claude-opus-4.6 Signed-off-by: Carlos López <clopez@suse.de> Link: https://patch.msgid.link/20260529140013.14925-2-clopez@suse.de Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent 555aa0e commit 376e118

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

arch/x86/kvm/irq.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,16 @@ int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
585585
r = 0;
586586
switch (chip->chip_id) {
587587
case KVM_IRQCHIP_PIC_MASTER:
588+
spin_lock(&pic->lock);
588589
memcpy(&chip->chip.pic, &pic->pics[0],
589590
sizeof(struct kvm_pic_state));
591+
spin_unlock(&pic->lock);
590592
break;
591593
case KVM_IRQCHIP_PIC_SLAVE:
594+
spin_lock(&pic->lock);
592595
memcpy(&chip->chip.pic, &pic->pics[1],
593596
sizeof(struct kvm_pic_state));
597+
spin_unlock(&pic->lock);
594598
break;
595599
case KVM_IRQCHIP_IOAPIC:
596600
kvm_get_ioapic(kvm, &chip->chip.ioapic);

0 commit comments

Comments
 (0)