Re: [PATCH] RISC-V: KVM: Fix out-of-bounds index into aia_irq2bitpos[]
From: Wang Yechao
Date: Tue Oct 27 2026 - 08:16:07 EST
> [Severity: Medium]
> Can irq actually reach 64..67 in aia_get_iprio8() or aia_set_iprio8()?
>
> Both helpers are static and only called from aia_rmw_iprio() via
> kvm_riscv_vcpu_aia_rmw_ireg() when isel is between ISELECT_IPRIO0 (0x30) and
> ISELECT_IPRIO15 (0x3f).
>
> In arch/riscv/kvm/aia.c, aia_rmw_iprio() rejects odd isel values on RV64
> before computing first_irq:
>
> arch/riscv/kvm/aia.c:aia_rmw_iprio() {
> #ifndef CONFIG_32BIT
> if (isel & 0x1)
> return KVM_INSN_ILLEGAL_TRAP;
> #endif
>
> nirqs = 4 * (BITS_PER_LONG / 32);
> first_irq = (isel - ISELECT_IPRIO0) * 4;
> ...
> }
>
> Because ISELECT_IPRIO15 (0x3f) is odd, it returns KVM_INSN_ILLEGAL_TRAP on
> RV64. The largest even isel reaching the loop on RV64 is ISELECT_IPRIO14
> (0x3e), which gives first_irq = (0x3e - 0x30) * 4 = 56 and nirqs = 8, so
> first_irq + i is at most 56 + 7 = 63. On RV32, isel can be ISELECT_IPRIO15
> (0x3f), which gives first_irq = 60 and nirqs = 4, so first_irq + i is also
> at most 60 + 3 = 63.
>
> Since ARRAY_SIZE(aia_irq2bitpos) is 64, isn't irq already guaranteed to be
> in 0..63, making these bounds checks unreachable?
Right,
I missed the odd-isel check in aia_rmw_iprio().
Please drop this patch.
Thanks,
Yechao