* [PATCH v2] KVM: x86: Take PIC lock on KVM_GET_IRQCHIP path
@ 2026-05-29 14:00 Carlos López
2026-06-05 18:31 ` Sean Christopherson
0 siblings, 1 reply; 2+ messages in thread
From: Carlos López @ 2026-05-29 14:00 UTC (permalink / raw)
To: kvm, seanjc, pbonzini
Cc: Carlos López, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
H. Peter Anvin, He, Qing, Yaozu (Eddie) Dong, Avi Kivity,
Marcelo Tosatti, open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)
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 6ceb9d791eee ("KVM: Add get/
set irqchip ioctls for in-kernel PIC live migration support"). Later,
894a9c5543ab ("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: 6ceb9d791eee ("KVM: Add get/set irqchip ioctls for in-kernel PIC live migration support")
Fixes: 894a9c5543ab ("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>
---
v2:
- Remove stable tag
- Use regular locking instead of guards
arch/x86/kvm/irq.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/x86/kvm/irq.c b/arch/x86/kvm/irq.c
index 9519fec09ee6..8c62c6d4d5c1 100644
--- a/arch/x86/kvm/irq.c
+++ b/arch/x86/kvm/irq.c
@@ -585,12 +585,16 @@ int kvm_vm_ioctl_get_irqchip(struct kvm *kvm, struct kvm_irqchip *chip)
r = 0;
switch (chip->chip_id) {
case KVM_IRQCHIP_PIC_MASTER:
+ spin_lock(&pic->lock);
memcpy(&chip->chip.pic, &pic->pics[0],
sizeof(struct kvm_pic_state));
+ spin_unlock(&pic->lock);
break;
case KVM_IRQCHIP_PIC_SLAVE:
+ spin_lock(&pic->lock);
memcpy(&chip->chip.pic, &pic->pics[1],
sizeof(struct kvm_pic_state));
+ spin_unlock(&pic->lock);
break;
case KVM_IRQCHIP_IOAPIC:
kvm_get_ioapic(kvm, &chip->chip.ioapic);
base-commit: d1568b1332b6b3b36b222c2868fc102727c12a34
--
2.51.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH v2] KVM: x86: Take PIC lock on KVM_GET_IRQCHIP path
2026-05-29 14:00 [PATCH v2] KVM: x86: Take PIC lock on KVM_GET_IRQCHIP path Carlos López
@ 2026-06-05 18:31 ` Sean Christopherson
0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2026-06-05 18:31 UTC (permalink / raw)
To: Sean Christopherson, kvm, pbonzini, Carlos López
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, He, Qing, Yaozu (Eddie) Dong, Avi Kivity,
Marcelo Tosatti, linux-kernel
On Fri, 29 May 2026 16:00:14 +0200, Carlos López wrote:
> 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.
>
> [...]
Applied to kvm-x86 misc, thanks!
[1/1] KVM: x86: Take PIC lock on KVM_GET_IRQCHIP path
https://github.com/kvm-x86/linux/commit/376e11855154
--
https://github.com/kvm-x86/linux/tree/next
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-05 18:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-29 14:00 [PATCH v2] KVM: x86: Take PIC lock on KVM_GET_IRQCHIP path Carlos López
2026-06-05 18:31 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®