[tip: irq/drivers] irqchip/riscv-imsic: Reject overlapping group index fields

From: tip-bot2 for Pengpeng Hou

Date: Thu Oct 15 2026 - 05:59:26 EST


The following commit has been merged into the irq/drivers branch of tip:

Commit-ID: 8caa8fcec8db5358437b9b7ca456bc3093d2a4d0
Gitweb: https://git.kernel.org/tip/8caa8fcec8db5358437b9b7ca456bc3093d2a4d0
Author: Pengpeng Hou <hppiscas@xxxxxxx>
AuthorDate: Sun, 20 Sep 2026 21:07:54 +08:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Thu, 15 Oct 2026 11:50:48 +02:00

irqchip/riscv-imsic: Reject overlapping group index fields

The IMSIC address layout places the group index above the page offset,
guest index and HART index. imsic_parse_fwnode() checks the individual
field widths and the upper end of the group field, but does not check
that its lower end is above the other fields.

Reject a nonzero group field whose shift overlaps the lower fields.
Otherwise a firmware-supplied layout can assign the same address bit to
different indices when MSI target addresses are constructed.

Keep the existing upper-bound check unchanged. The new lower-bound
check applies only when group index bits are present.

The issue was found by our static-analysis tool.

Fixes: 21a8f8a0eb35 ("irqchip: Add RISC-V incoming MSI controller early driver")
Signed-off-by: Pengpeng Hou <hppiscas@xxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Assisted-by: gpt 5
Reviewed-by: Anup Patel <anup@xxxxxxxxxxxxxx>
Link: https://patch.msgid.link/caplitmus-rv.v2.imsic.f2c0e5bdc627451c83deb0cf7eb8834a@xxxxxxx
---
drivers/irqchip/irq-riscv-imsic-state.c | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/drivers/irqchip/irq-riscv-imsic-state.c b/drivers/irqchip/irq-riscv-imsic-state.c
index 9505ddb..960c71d 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -740,6 +740,14 @@ static int __init imsic_parse_fwnode(struct fwnode_handle *fwnode,
return -EINVAL;
}

+ /* Group index bits must not overlap guest and HART index bits. */
+ i = IMSIC_MMIO_PAGE_SHIFT + global->guest_index_bits +
+ global->hart_index_bits;
+ if (global->group_index_bits && global->group_index_shift < i) {
+ pr_err("%pfwP: group index shift too small\n", fwnode);
+ return -EINVAL;
+ }
+
/* Sanity check group index shift */
i = global->group_index_bits + global->group_index_shift - 1;
if (i >= BITS_PER_LONG) {