kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] KVM/ARM updates for v4.1, take 2
@ 2015-04-22 15:08 Marc Zyngier
  2015-04-22 15:08 ` [PATCH 1/2] KVM: arm: irqfd: fix value returned by kvm_irq_map_gsi Marc Zyngier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Marc Zyngier @ 2015-04-22 15:08 UTC (permalink / raw)
  To: Paolo Bonzini, Marcelo Tosatti
  Cc: kvm, kvmarm, linux-arm-kernel, Christoffer Dall, Eric Auger,
	Andre Przywara

Paolo, Marcelo,

This is the second pull request for the KVM/ARM updates targeting
v4.1. Not much to see this time, just a couple of borring fixes.

Thanks,

	M.

The following changes since commit b79013b2449c23f1f505bdf39c5a6c330338b244:

  Merge tag 'staging-4.1-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging (2015-04-13 17:37:33 -0700)

are available in the git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/kvmarm/kvmarm.git tags/kvm-arm-for-4.1-take2

for you to fetch changes up to fd1d0ddf2ae92fb3df42ed476939861806c5d785:

  KVM: arm/arm64: check IRQ number on userland injection (2015-04-22 15:42:24 +0100)

----------------------------------------------------------------
KVM/ARM changes for v4.1, take #2:

Rather small this time:

- a fix for a nasty bug with virtual IRQ injection
- a fix for irqfd

----------------------------------------------------------------
Andre Przywara (1):
      KVM: arm/arm64: check IRQ number on userland injection

Eric Auger (1):
      KVM: arm: irqfd: fix value returned by kvm_irq_map_gsi

 arch/arm/include/uapi/asm/kvm.h   | 8 +++++++-
 arch/arm/kvm/arm.c                | 3 +--
 arch/arm64/include/uapi/asm/kvm.h | 8 +++++++-
 virt/kvm/arm/vgic.c               | 5 ++++-
 4 files changed, 19 insertions(+), 5 deletions(-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] KVM: arm: irqfd: fix value returned by kvm_irq_map_gsi
  2015-04-22 15:08 [PATCH 0/2] KVM/ARM updates for v4.1, take 2 Marc Zyngier
@ 2015-04-22 15:08 ` Marc Zyngier
  2015-04-22 15:08 ` [PATCH 2/2] KVM: arm/arm64: check IRQ number on userland injection Marc Zyngier
  2015-04-22 15:11 ` [PATCH 0/2] KVM/ARM updates for v4.1, take 2 Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2015-04-22 15:08 UTC (permalink / raw)
  To: Paolo Bonzini, Marcelo Tosatti
  Cc: Eric Auger, Christoffer Dall, kvm, kvmarm, linux-arm-kernel,
	Andre Przywara

From: Eric Auger <eric.auger@linaro.org>

irqfd/arm curently does not support routing. kvm_irq_map_gsi is
supposed to return all the routing entries associated with the
provided gsi and return the number of those entries. We should
return 0 at this point.

Signed-off-by: Eric Auger <eric.auger@linaro.org>
Acked-by: Christoffer Dall <christoffer.dall@linaro.org>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 virt/kvm/arm/vgic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 8d550ff..7ed7873 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -2141,7 +2141,7 @@ int kvm_irq_map_gsi(struct kvm *kvm,
 		    struct kvm_kernel_irq_routing_entry *entries,
 		    int gsi)
 {
-	return gsi;
+	return 0;
 }
 
 int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned irqchip, unsigned pin)
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] KVM: arm/arm64: check IRQ number on userland injection
  2015-04-22 15:08 [PATCH 0/2] KVM/ARM updates for v4.1, take 2 Marc Zyngier
  2015-04-22 15:08 ` [PATCH 1/2] KVM: arm: irqfd: fix value returned by kvm_irq_map_gsi Marc Zyngier
@ 2015-04-22 15:08 ` Marc Zyngier
  2015-04-22 15:11 ` [PATCH 0/2] KVM/ARM updates for v4.1, take 2 Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2015-04-22 15:08 UTC (permalink / raw)
  To: Paolo Bonzini, Marcelo Tosatti
  Cc: Andre Przywara, stable, Christoffer Dall, kvm, kvmarm,
	linux-arm-kernel, Eric Auger

From: Andre Przywara <andre.przywara@arm.com>

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 #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>
---
 arch/arm/include/uapi/asm/kvm.h   | 8 +++++++-
 arch/arm/kvm/arm.c                | 3 +--
 arch/arm64/include/uapi/asm/kvm.h | 8 +++++++-
 virt/kvm/arm/vgic.c               | 3 +++
 4 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h
index 2499867..df3f60c 100644
--- a/arch/arm/include/uapi/asm/kvm.h
+++ b/arch/arm/include/uapi/asm/kvm.h
@@ -195,8 +195,14 @@ struct kvm_arch_memory_slot {
 #define KVM_ARM_IRQ_CPU_IRQ		0
 #define KVM_ARM_IRQ_CPU_FIQ		1
 
-/* Highest supported SPI, from VGIC_NR_IRQS */
+/*
+ * This used to hold the highest supported SPI, but it is now obsolete
+ * and only here to provide source code level compatibility with older
+ * userland. The highest SPI number can be set via KVM_DEV_ARM_VGIC_GRP_NR_IRQS.
+ */
+#ifndef __KERNEL__
 #define KVM_ARM_IRQ_GIC_MAX		127
+#endif
 
 /* One single KVM irqchip, ie. the VGIC */
 #define KVM_NR_IRQCHIPS          1
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 6f53645..d9631ec 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -671,8 +671,7 @@ int kvm_vm_ioctl_irq_line(struct kvm *kvm, struct kvm_irq_level *irq_level,
 		if (!irqchip_in_kernel(kvm))
 			return -ENXIO;
 
-		if (irq_num < VGIC_NR_PRIVATE_IRQS ||
-		    irq_num > KVM_ARM_IRQ_GIC_MAX)
+		if (irq_num < VGIC_NR_PRIVATE_IRQS)
 			return -EINVAL;
 
 		return kvm_vgic_inject_irq(kvm, 0, irq_num, level);
diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h
index c154c0b..d268320 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -188,8 +188,14 @@ struct kvm_arch_memory_slot {
 #define KVM_ARM_IRQ_CPU_IRQ		0
 #define KVM_ARM_IRQ_CPU_FIQ		1
 
-/* Highest supported SPI, from VGIC_NR_IRQS */
+/*
+ * This used to hold the highest supported SPI, but it is now obsolete
+ * and only here to provide source code level compatibility with older
+ * userland. The highest SPI number can be set via KVM_DEV_ARM_VGIC_GRP_NR_IRQS.
+ */
+#ifndef __KERNEL__
 #define KVM_ARM_IRQ_GIC_MAX		127
+#endif
 
 /* One single KVM irqchip, ie. the VGIC */
 #define KVM_NR_IRQCHIPS          1
diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 7ed7873..78fb820 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -1561,6 +1561,9 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num,
 			goto out;
 	}
 
+	if (irq_num >= kvm->arch.vgic.nr_irqs)
+		return -EINVAL;
+
 	vcpu_id = vgic_update_irq_pending(kvm, cpuid, irq_num, level);
 	if (vcpu_id >= 0) {
 		/* kick the specified vcpu */
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] KVM/ARM updates for v4.1, take 2
  2015-04-22 15:08 [PATCH 0/2] KVM/ARM updates for v4.1, take 2 Marc Zyngier
  2015-04-22 15:08 ` [PATCH 1/2] KVM: arm: irqfd: fix value returned by kvm_irq_map_gsi Marc Zyngier
  2015-04-22 15:08 ` [PATCH 2/2] KVM: arm/arm64: check IRQ number on userland injection Marc Zyngier
@ 2015-04-22 15:11 ` Paolo Bonzini
  2 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2015-04-22 15:11 UTC (permalink / raw)
  To: Marc Zyngier, Marcelo Tosatti
  Cc: kvm, kvmarm, linux-arm-kernel, Christoffer Dall, Eric Auger,
	Andre Przywara



On 22/04/2015 17:08, Marc Zyngier wrote:
> Paolo, Marcelo,
> 
> This is the second pull request for the KVM/ARM updates targeting
> v4.1. Not much to see this time, just a couple of borring fixes.

Pulled.

Paolo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-04-22 15:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-22 15:08 [PATCH 0/2] KVM/ARM updates for v4.1, take 2 Marc Zyngier
2015-04-22 15:08 ` [PATCH 1/2] KVM: arm: irqfd: fix value returned by kvm_irq_map_gsi Marc Zyngier
2015-04-22 15:08 ` [PATCH 2/2] KVM: arm/arm64: check IRQ number on userland injection Marc Zyngier
2015-04-22 15:11 ` [PATCH 0/2] KVM/ARM updates for v4.1, take 2 Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).