[Skiboot] [PATCH 1/8] interrupts: add_opal_interrupts avoid NULL dereference on P10 mambo

Nicholas Piggin npiggin at gmail.com
Sun Oct 3 12:22:03 AEDT 2021


On P10, get_ics_phandle() calls xive2_get_phandle() directly. This
results in a NULL dereference on mambo when xive2 is not set up.

This was caught with the virtual memory boot patch on P10 mambo.

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
 core/interrupts.c | 7 ++++++-
 hw/xive2.c        | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/core/interrupts.c b/core/interrupts.c
index 5d2d04db5..c39c2801c 100644
--- a/core/interrupts.c
+++ b/core/interrupts.c
@@ -204,10 +204,15 @@ void add_opal_interrupts(void)
 {
 	struct irq_source *is;
 	unsigned int i, ns, tns = 0, count = 0;
+	uint32_t parent;
 	uint32_t isn;
 	__be32 *irqs = NULL;
 	char *names = NULL;
 
+	parent = get_ics_phandle();
+	if (!parent)
+		return;
+
 	lock(&irq_lock);
 	list_for_each(&irq_sources, is, link) {
 		/*
@@ -251,7 +256,7 @@ void add_opal_interrupts(void)
 	/* First create the standard "interrupts" property and the
 	 * corresponding names property
 	 */
-	dt_add_property_cells(opal_node, "interrupt-parent", get_ics_phandle());
+	dt_add_property_cells(opal_node, "interrupt-parent", parent);
 	dt_add_property(opal_node, "interrupts", irqs, count * 8);
 	dt_add_property(opal_node, "opal-interrupts-names", names, tns);
 	dt_add_property(opal_node, "interrupt-names", names, tns);
diff --git a/hw/xive2.c b/hw/xive2.c
index 810ab91d8..0254175a9 100644
--- a/hw/xive2.c
+++ b/hw/xive2.c
@@ -1977,6 +1977,9 @@ static void xive_create_mmio_dt_node(struct xive *x)
 
 uint32_t xive2_get_phandle(void)
 {
+	if (!xive_dt_node)
+		return 0;
+
 	return xive_dt_node->phandle;
 }
 
-- 
2.23.0



More information about the Skiboot mailing list