Skip to content

Commit e580744

Browse files
Andre-ARMsashalevin
authored andcommitted
KVM: arm/arm64: check IRQ number on userland injection
[ Upstream commit fd1d0dd ] When userland injects a SPI via the KVM_IRQ_LINE ioctl we currently only check it against a fixed limit, which historically is set to 127. With the new dynamic IRQ allocation the effective limit may actually be smaller (64). So when now a malicious or buggy userland injects a SPI in that range, we spill over on our VGIC bitmaps and bytemaps memory. I could trigger a host kernel NULL pointer dereference with current mainline by injecting some bogus IRQ number from a hacked kvmtool: ----------------- .... DEBUG: kvm_vgic_inject_irq(kvm, cpu=0, irq=114, level=1) DEBUG: vgic_update_irq_pending(kvm, cpu=0, irq=114, level=1) DEBUG: IRQ torvalds#114 still in the game, writing to bytemap now... Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = ffffffc07652e000 [00000000] *pgd=00000000f658b003, *pud=00000000f658b003, *pmd=0000000000000000 Internal error: Oops: 96000006 [#1] PREEMPT SMP Modules linked in: CPU: 1 PID: 1053 Comm: lkvm-msi-irqinj Not tainted 4.0.0-rc7+ #3027 Hardware name: FVP Base (DT) task: ffffffc0774e9680 ti: ffffffc0765a8000 task.ti: ffffffc0765a8000 PC is at kvm_vgic_inject_irq+0x234/0x310 LR is at kvm_vgic_inject_irq+0x30c/0x310 pc : [<ffffffc0000ae0a8>] lr : [<ffffffc0000ae180>] pstate: 80000145 ..... So this patch fixes this by checking the SPI number against the actual limit. Also we remove the former legacy hard limit of 127 in the ioctl code. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> CC: <stable@vger.kernel.org> # 4.0, 3.19, 3.18 [maz: wrap KVM_ARM_IRQ_GIC_MAX with #ifndef __KERNEL__, as suggested by Christopher Covington] Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
1 parent 35e1329 commit e580744

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

arch/arm/include/uapi/asm/kvm.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,14 @@ struct kvm_arch_memory_slot {
193193
#define KVM_ARM_IRQ_CPU_IRQ 0
194194
#define KVM_ARM_IRQ_CPU_FIQ 1
195195

196-
/* Highest supported SPI, from VGIC_NR_IRQS */
196+
/*
197+
* This used to hold the highest supported SPI, but it is now obsolete
198+
* and only here to provide source code level compatibility with older
199+
* userland. The highest SPI number can be set via KVM_DEV_ARM_VGIC_GRP_NR_IRQS.
200+
*/
201+
#ifndef __KERNEL__
197202
#define KVM_ARM_IRQ_GIC_MAX 127
203+
#endif
198204

199205
/* PSCI interface */
200206
#define KVM_PSCI_FN_BASE 0x95c1ba5e

arch/arm/kvm/arm.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,7 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
653653
if (!irqchip_in_kernel(kvm))
654654
return -ENXIO;
655655

656-
if (irq_num < VGIC_NR_PRIVATE_IRQS ||
657-
irq_num > KVM_ARM_IRQ_GIC_MAX)
656+
if (irq_num < VGIC_NR_PRIVATE_IRQS)
658657
return -EINVAL;
659658

660659
return kvm_vgic_inject_irq(kvm, 0, irq_num, level);

arch/arm64/include/uapi/asm/kvm.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,14 @@ struct kvm_arch_memory_slot {
179179
#define KVM_ARM_IRQ_CPU_IRQ 0
180180
#define KVM_ARM_IRQ_CPU_FIQ 1
181181

182-
/* Highest supported SPI, from VGIC_NR_IRQS */
182+
/*
183+
* This used to hold the highest supported SPI, but it is now obsolete
184+
* and only here to provide source code level compatibility with older
185+
* userland. The highest SPI number can be set via KVM_DEV_ARM_VGIC_GRP_NR_IRQS.
186+
*/
187+
#ifndef __KERNEL__
183188
#define KVM_ARM_IRQ_GIC_MAX 127
189+
#endif
184190

185191
/* PSCI interface */
186192
#define KVM_PSCI_FN_BASE 0x95c1ba5e

virt/kvm/arm/vgic.c

+3
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,9 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num,
17211721
goto out;
17221722
}
17231723

1724+
if (irq_num >= kvm->arch.vgic.nr_irqs)
1725+
return -EINVAL;
1726+
17241727
vcpu_id = vgic_update_irq_pending(kvm, cpuid, irq_num, level);
17251728
if (vcpu_id >= 0) {
17261729
/* kick the specified vcpu */

0 commit comments

Comments
 (0)