mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] irqchip/riscv-imsic: Reject overlapping group index fields
@ 2026-09-20 13:07 Pengpeng Hou
  2026-09-23 11:12 ` Anup Patel
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Pengpeng Hou @ 2026-09-20 13:07 UTC (permalink / raw)
  To: anup, tglx
  Cc: Pengpeng Hou, Alexandre Ghiti, Andrew Jones, Albert Ou,
	Bjorn Topel, linux-kernel, linux-riscv, Palmer Dabbelt,
	Paul Walmsley, Radu Rendec

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")
Assisted-by: gpt 5
Signed-off-by: Pengpeng Hou <hppiscas@163.com>
---
Changes since v1: https://lore.kernel.org/r/caplitmus-rv.bc36e3a0ebcb4a01838171f27625004b.imsic-overlap@163.com/
- Limit the change to the lower-bound check discussed with Anup.
- Keep the existing upper-bound check unchanged.
- Send this as a standalone patch, without the zero-width-group change.
- Do not change APLIC configuration or require the earlier series.

 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 b8d1bbb..a7b241f 100644
--- a/drivers/irqchip/irq-riscv-imsic-state.c
+++ b/drivers/irqchip/irq-riscv-imsic-state.c
@@ -739,6 +739,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) {

base-commit: 518e5b794c06c0f0eb40df3e202274a66202c137


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-01 22:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-20 13:07 [PATCH v2] irqchip/riscv-imsic: Reject overlapping group index fields Pengpeng Hou
2026-09-23 11:12 ` Anup Patel
2026-10-14  8:59 ` Pengpeng Hou
2026-10-15  9:54 ` [tip: irq/drivers] " tip-bot2 for Pengpeng Hou
2026-11-01 22:16 ` [PATCH v2] " patchwork-bot+linux-riscv

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®