linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] irqchip/gic: prevent buffer overflow in gic_ipi_send_mask()
@ 2024-09-04 20:23 Sergey Shtylyov
  2024-09-05  7:29 ` Thomas Gleixner
  0 siblings, 1 reply; 10+ messages in thread
From: Sergey Shtylyov @ 2024-09-04 20:23 UTC (permalink / raw)
  To: Thomas Gleixner, linux-kernel, Marc Zyngier, linux-arm-kernel

ARM GIC arch v2 spec claims support for just 8 CPU interfaces.  However,
looking at the GIC driver's irq_set_affinity() method, it seems that the
passed CPU mask may contain the logical CPU #s beyond 8, and that method
filters them out before reading gic_cpu_map[], bailing out with -EINVAL.
Such check should also be performed in the ipi_send_mask() method where
it uses for_each_cpu(), in order to prevent accessing beyond the end of
gic_cpu_map[] there as well...

Found by Linux Verification Center (linuxtesting.org) with the Svace static
analysis tool.

Fixes: 384a290283fd ("ARM: gic: use a private mapping for CPU target interfaces")
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>

---
The patch is against the irq/core branch of the tip.git repo...

 drivers/irqchip/irq-gic.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Index: tip/drivers/irqchip/irq-gic.c
===================================================================
--- tip.orig/drivers/irqchip/irq-gic.c
+++ tip/drivers/irqchip/irq-gic.c
@@ -832,8 +832,11 @@ static void gic_ipi_send_mask(struct irq
 	gic_lock_irqsave(flags);
 
 	/* Convert our logical CPU mask into a physical one. */
-	for_each_cpu(cpu, mask)
+	for_each_cpu(cpu, mask) {
+		if (cpu >= NR_GIC_CPU_IF)
+			break;
 		map |= gic_cpu_map[cpu];
+	}
 
 	/*
 	 * Ensure that stores to Normal memory are visible to the


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

end of thread, other threads:[~2024-09-10  7:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-04 20:23 [PATCH] irqchip/gic: prevent buffer overflow in gic_ipi_send_mask() Sergey Shtylyov
2024-09-05  7:29 ` Thomas Gleixner
2024-09-05  7:47   ` Marc Zyngier
2024-09-06 20:29     ` Sergey Shtylyov
2024-09-06 20:36       ` Sergey Shtylyov
2024-09-08  9:37       ` Marc Zyngier
2024-09-09 19:48         ` Sergey Shtylyov
2024-09-10  7:38           ` Marc Zyngier
2024-09-09 19:23   ` Sergey Shtylyov
2024-09-10  7:50     ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).