On Fri, Nov 21, 2014 at 01:33:24PM +0100, Christoffer Dall wrote: > On Mon, Nov 17, 2014 at 10:09:58AM +0000, Marc Zyngier wrote: > > On 17/11/14 09:27, wanghaibin wrote: > > > Maybe inject irq action is not only from userspace(like arch_timer or > > > another in-kernel device in future). So, it maybe better that guarantee > > > the parameter valid before inject irq action. > > > > First, we don't defend ourselves from other in-kernel callers. If they > > wrong, we fix them. > > > > > Signed-off-by: wanghaibin <wanghaibin.wang@xxxxxxxxxx> > > > --- > > > virt/kvm/arm/vgic.c | 10 ++++++++++ > > > 1 files changed, 10 insertions(+), 0 deletions(-) > > > > > > diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c > > > index 12026e6..52f3bfa 100644 > > > --- a/virt/kvm/arm/vgic.c > > > +++ b/virt/kvm/arm/vgic.c > > > @@ -1621,10 +1621,20 @@ static bool vgic_update_irq_pending(struct kvm *kvm, int cpuid, > > > { > > > struct vgic_dist *dist = &kvm->arch.vgic; > > > struct kvm_vcpu *vcpu; > > > + int nrcpus = atomic_read(&kvm->online_vcpus); > > > int edge_triggered, level_triggered; > > > int enabled; > > > bool ret = true; > > > > > > + if ((cpuid >= nrcpus) || (irq_num >= dist->nr_irqs)) > > > + return false; > > > + > > > + if (irq_num < VGIC_NR_SGIS) > > > + return false; > > > + > > > + if ((irq_num >= VGIC_NR_PRIVATE_IRQS) && (cpuid != 0)) > > > + return false; > > > + > > > spin_lock(&dist->lock); > > > > > > vcpu = kvm_get_vcpu(kvm, cpuid); > > > > > > > The only check that could be useful is the one against dist->nr_irqs. > > The rest of it is completely useless. > > > I think the right thin to do is to change the check in > arch/arm/kvm/arm.c:kvm_vm_ioctl_irq_line() to check against > dist->nr_irqs for KVM_ARM_IRQ_TYPE_SPI and return an error in that case. > > Wanghaibin, can you send such a patch instead of this one? > Actually, I think we want the check against dist->nr_irqs in both the ioctl handler *and* in this function, with a kvm_err() message in this function if we get here with an invalid irq number. -Christoffer _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm