]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
LoongArch: KVM: Validate irqchip index in irqfd routing
authorYanfei Xu <yanfei.xu@bytedance.com>
Thu, 11 Jun 2026 12:46:43 +0000 (20:46 +0800)
committerHuacai Chen <chenhuacai@loongson.cn>
Thu, 11 Jun 2026 12:46:43 +0000 (20:46 +0800)
Sashiko reported that the irqchip index is not validated for LoongArch.
Add validation and reject out-of-range irqchip indexes to avoid indexing
past the routing table's chip array.

Cc: stable@vger.kernel.org
Fixes: 1928254c5ccb ("LoongArch: KVM: Add irqfd support")
Closes: https://lore.kernel.org/kvm/20260525051714.485D51F000E9@smtp.kernel.org/
Reported-by: Sashiko <sashiko-bot@kernel.org>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Signed-off-by: Yanfei Xu <yanfei.xu@bytedance.com>
Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
arch/loongarch/kvm/irqfd.c

index f4f953b22419259c606127a00bf51fffc30871c8..40ed1081c4b622586fa5a2ea077307076dbf97db 100644 (file)
@@ -51,7 +51,8 @@ int kvm_set_routing_entry(struct kvm *kvm,
                e->irqchip.irqchip = ue->u.irqchip.irqchip;
                e->irqchip.pin = ue->u.irqchip.pin;
 
-               if (e->irqchip.pin >= KVM_IRQCHIP_NUM_PINS)
+               if (e->irqchip.pin >= KVM_IRQCHIP_NUM_PINS ||
+                   e->irqchip.irqchip >= KVM_NR_IRQCHIPS)
                        return -EINVAL;
 
                return 0;