Skip to contentSkip to conversation

KVM: arm64: fix potential bug

PATCH In review John Gong 2 participants 4 messages Mar 12, 2019 KVM arm64

lore
Share & tools
lore

John Gong

author
#0 lore raw

PATCH 1/1 KVM: arm64: fix potential bug

Since intid always >= VGIC_NR_PRIVATE_IRQS, so then even vcpu == NULL, it never return -EINVAL.

---
 virt/kvm/arm/vgic/vgic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic.c +1 -1
index abd9c7352677..d3cb1ce880e2 100644
@@ -424,7 +424,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
 		return ret;
 
 	vcpu = kvm_get_vcpu(kvm, cpuid);
-	if (!vcpu && intid < VGIC_NR_PRIVATE_IRQS)
+	if (!vcpu)
 		return -EINVAL;
 
 	irq = vgic_get_irq(kvm, vcpu, intid);
Signature · 1 line
2.17.1
#1 lore raw

On 12/03/2019 00:32, John Gong wrote:
Hi,

Quoted 1 line

Since intid always >= VGIC_NR_PRIVATE_IRQS,

How so? The PMU and the arch timer emulation use PPIs, so intid is definitely < VGIC_NR_PRIVATE_IRQS there.

Quoted 1 line

so then even vcpu == NULL, it never return -EINVAL.

I am not sure I follow.
To uniquely identify an SPI interrupt, we just need the interrupt ID (which is always >= 32). For PPIs and SGIs, we additionally need the vCPU ID this private interrupt belongs to, as there are multiple interrupts with the same INTID (one per VCPU).
The VCPU ID passed in for SPIs is just a dummy value (because we use the same function to inject private and shared interrupts), so we don't need to check for its validity.

Cheers,
Andre.

Quoted 21 lines
---
 virt/kvm/arm/vgic/vgic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic.c +1 -1
index abd9c7352677..d3cb1ce880e2 100644
@@ -424,7 +424,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
 		return ret;
 
 	vcpu = kvm_get_vcpu(kvm, cpuid);
-	if (!vcpu && intid < VGIC_NR_PRIVATE_IRQS)
+	if (!vcpu)
 		return -EINVAL;
 
 	irq = vgic_get_irq(kvm, vcpu, intid);
author
#2 lore raw

Hi Andre,

Quoted 20 lines · André Przywara

On 12/03/2019 00:32, John Gong wrote:
Hi,

Quoted 1 line

Since intid always >= VGIC_NR_PRIVATE_IRQS,

How so? The PMU and the arch timer emulation use PPIs, so intid is definitely < VGIC_NR_PRIVATE_IRQS there.

Quoted 1 line

so then even vcpu == NULL, it never return -EINVAL.

I am not sure I follow.
To uniquely identify an SPI interrupt, we just need the interrupt ID (which is always >= 32). For PPIs and SGIs, we additionally need the vCPU ID this private interrupt belongs to, as there are multiple interrupts with the same INTID (one per VCPU).
The VCPU ID passed in for SPIs is just a dummy value (because we use the same function to inject private and shared interrupts), so we don't need to check for its validity.

Quoted 3 lines

Cheers,
Andre.

Thanks for your explanation. It's my fault to not consider the PPIs and SGIs injection.
Sorry for polluting the mail list.

Cheers,
John Gong

Quoted 22 lines
Quoted 21 lines
---
 virt/kvm/arm/vgic/vgic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic.c +1 -1
index abd9c7352677..d3cb1ce880e2 100644
@@ -424,7 +424,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
              return ret;
 
      vcpu = kvm_get_vcpu(kvm, cpuid);
-     if (!vcpu && intid < VGIC_NR_PRIVATE_IRQS)
+     if (!vcpu)
              return -EINVAL;
 
      irq = vgic_get_irq(kvm, vcpu, intid);
#3 lore raw

On Tue, 12 Mar 2019 11:15:14 +0800
Gong John <[email protected]> wrote:

Hi,

Quoted 21 lines · André Przywara
Quoted 20 lines · John Gong

Hi,

Quoted 1 line

Since intid always >= VGIC_NR_PRIVATE_IRQS,

How so? The PMU and the arch timer emulation use PPIs, so intid is definitely < VGIC_NR_PRIVATE_IRQS there.

Quoted 1 line

so then even vcpu == NULL, it never return -EINVAL.

I am not sure I follow.
To uniquely identify an SPI interrupt, we just need the interrupt ID (which is always >= 32). For PPIs and SGIs, we additionally need the vCPU ID this private interrupt belongs to, as there are multiple interrupts with the same INTID (one per VCPU).
The VCPU ID passed in for SPIs is just a dummy value (because we use the same function to inject private and shared interrupts), so we don't need to check for its validity.

Quoted 5 lines
Quoted 3 lines

Cheers,
Andre.

Thanks for your explanation. It's my fault to not consider the PPIs and SGIs injection.

Don't worry, we are glad when people actually look at the code. And we rather have a false positive report than a bug slipping through.

Cheers,
Andre.

Quoted 26 lines

Sorry for polluting the mail list.

Cheers,
John Gong

Quoted 22 lines
Quoted 21 lines
---
 virt/kvm/arm/vgic/vgic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/arm/vgic/vgic.c +1 -1
index abd9c7352677..d3cb1ce880e2 100644
@@ -424,7 +424,7 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int intid,
              return ret;
 
      vcpu = kvm_get_vcpu(kvm, cpuid);
-     if (!vcpu && intid < VGIC_NR_PRIVATE_IRQS)
+     if (!vcpu)
              return -EINVAL;
 
      irq = vgic_get_irq(kvm, vcpu, intid);