Skip to contentSkip to conversation

irqchip/gic-v3: Work around insecure GIC integrations

PATCH Applied Marc Zyngier 3 participants 4 messages Dec 13, 2024

Subsystems (3)
lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

PATCH 1/1 irqchip/gic-v3: Work around insecure GIC integrations

It appears that the relatively popular RK3399 SoC has been put together using a large amount of illicit substances, as experiments reveal that its integration of GIC500 exposes the *secure* programming interface to non-secure.

This has some pretty bad effects on the way priorities are handled, and results in a dead machine if booting with pseudo-NMI enabled (irqchip.gicv3_pseudo_nmi=1) if the kernel contains 18fdb6348c480 ("arm64: irqchip/gic-v3: Select priorities at boot time"), which relies on the priorities being programmed using the NS view.

Let's restore some sanity by going one step further and disable security altogether in this case. This is not any worse, and puts us in a mode where priorities actually make some sense.

Huge thanks to Mark Kettenis who initially identified this issue on OpenBSD, and to Chen-Yu Tsai who reported the problem in Linux.

Fixes 18fdb6348c480 ("arm64: irqchip/gic-v3: Select priorities at boot time")
---
 drivers/irqchip/irq-gic-v3.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +16 -1
index 34db379d066a5..79d8cc80693c3 100644
@@ -161,7 +161,22 @@ static bool cpus_have_group0 __ro_after_init;
 
 static void __init gic_prio_init(void)
 {
-	cpus_have_security_disabled = gic_dist_security_disabled();
+	bool ds;
+
+	ds = gic_dist_security_disabled();
+	if (!ds) {
+		u32 val;
+
+		val = readl_relaxed(gic_data.dist_base + GICD_CTLR);
+		val |= GICD_CTLR_DS;
+		writel_relaxed(val, gic_data.dist_base + GICD_CTLR);
+
+		ds = gic_dist_security_disabled();
+		if (ds)
+			pr_warn("Broken GIC integration, security disabled");
+	}
+
+	cpus_have_security_disabled = ds;
 	cpus_have_group0 = gic_has_group0();
 
 	/*
Signature · 1 line
2.39.2
Tested-by on v1 1/1
#1 lore raw
Quoted 16 lines · Marc Zyngier

It appears that the relatively popular RK3399 SoC has been put together using a large amount of illicit substances, as experiments reveal that its integration of GIC500 exposes the *secure* programming interface to non-secure.

This has some pretty bad effects on the way priorities are handled, and results in a dead machine if booting with pseudo-NMI enabled (irqchip.gicv3_pseudo_nmi=1) if the kernel contains 18fdb6348c480 ("arm64: irqchip/gic-v3: Select priorities at boot time"), which relies on the priorities being programmed using the NS view.

Let's restore some sanity by going one step further and disable security altogether in this case. This is not any worse, and puts us in a mode where priorities actually make some sense.

Quoted 7 lines

Huge thanks to Mark Kettenis who initially identified this issue on OpenBSD, and to Chen-Yu Tsai who reported the problem in Linux.

Fixes 18fdb6348c480 ("arm64: irqchip/gic-v3: Select priorities at boot time")

Should be

(I know it's confusing, I even mix up inboxes at work.)

Quoted 2 lines

My RK3399 boots normally with pseudo NMI enabled with this patch now. Also tried NMI backtraces through sysrq, though I'm not sure that always goes through the pseudo NMI path?

Quoted 36 lines
---
 drivers/irqchip/irq-gic-v3.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +16 -2
index 34db379d066a5..79d8cc80693c3 100644
@@ -161,7 +161,22 @@ static bool cpus_have_group0 __ro_after_init;
 
 static void __init gic_prio_init(void)
 {
-       cpus_have_security_disabled = gic_dist_security_disabled();
+       bool ds;
+
+       ds = gic_dist_security_disabled();
+       if (!ds) {
+               u32 val;
+
+               val = readl_relaxed(gic_data.dist_base + GICD_CTLR);
+               val |= GICD_CTLR_DS;
+               writel_relaxed(val, gic_data.dist_base + GICD_CTLR);
+
+               ds = gic_dist_security_disabled();
+               if (ds)
+                       pr_warn("Broken GIC integration, security disabled");
+       }
+
+       cpus_have_security_disabled = ds;
        cpus_have_group0 = gic_has_group0();
 
        /*
--

2.39.2

author maintainer
#2 lore raw
Quoted 26 lines · Chen-Yu Tsai
Quoted 16 lines · Marc Zyngier

It appears that the relatively popular RK3399 SoC has been put together using a large amount of illicit substances, as experiments reveal that its integration of GIC500 exposes the *secure* programming interface to non-secure.

This has some pretty bad effects on the way priorities are handled, and results in a dead machine if booting with pseudo-NMI enabled (irqchip.gicv3_pseudo_nmi=1) if the kernel contains 18fdb6348c480 ("arm64: irqchip/gic-v3: Select priorities at boot time"), which relies on the priorities being programmed using the NS view.

Let's restore some sanity by going one step further and disable security altogether in this case. This is not any worse, and puts us in a mode where priorities actually make some sense.

Quoted 7 lines

Huge thanks to Mark Kettenis who initially identified this issue on OpenBSD, and to Chen-Yu Tsai who reported the problem in Linux.

Fixes 18fdb6348c480 ("arm64: irqchip/gic-v3: Select priorities at boot time")
Quoted 5 lines

Should be

(I know it's confusing, I even mix up inboxes at work.)

Ah, fair enough. Given that the report was on IRC, I had just used the first address git log gave me.

Quoted 8 lines
Quoted 2 lines

My RK3399 boots normally with pseudo NMI enabled with this patch now. Also tried NMI backtraces through sysrq, though I'm not sure that always goes through the pseudo NMI path?

Should do, according to arch/arm64/kernel/smp::ipi_setup().

Thanks for having tested it.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
merge bot Applied
#3 lore raw
In reply to Marc Zyngier
The following commit has been merged into the irq/urgent branch of tip:

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

Commit-ID:     773c05f417fa14e1ac94776619e9c978ec001f0b
Gitweb:        https://git.kernel.org/tip/773c05f417fa14e1ac94776619e9c978ec001f0b
Author:        Marc Zyngier <[email protected]>
AuthorDate:    Fri, 13 Dec 2024 14:10:37 
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Fri, 13 Dec 2024 18:15:29 +01:00

irqchip/gic-v3: Work around insecure GIC integrations

It appears that the relatively popular RK3399 SoC has been put together using a large amount of illicit substances, as experiments reveal that its integration of GIC500 exposes the *secure* programming interface to non-secure.

This has some pretty bad effects on the way priorities are handled, and results in a dead machine if booting with pseudo-NMI enabled (irqchip.gicv3_pseudo_nmi=1) if the kernel contains 18fdb6348c480 ("arm64:
irqchip/gic-v3: Select priorities at boot time"), which relies on the priorities being programmed using the NS view.

Let's restore some sanity by going one step further and disable security altogether in this case. This is not any worse, and puts us in a mode where priorities actually make some sense.

Huge thanks to Mark Kettenis who initially identified this issue on OpenBSD, and to Chen-Yu Tsai who reported the problem in Linux.

---
 drivers/irqchip/irq-gic-v3.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
drivers/irqchip/irq-gic-v3.c +16 -1
index 34db379..79d8cc8 100644
@@ -161,7 +161,22 @@ static bool cpus_have_group0 __ro_after_init;
 
 static void __init gic_prio_init(void)
 {
-	cpus_have_security_disabled = gic_dist_security_disabled();
+	bool ds;
+
+	ds = gic_dist_security_disabled();
+	if (!ds) {
+		u32 val;
+
+		val = readl_relaxed(gic_data.dist_base + GICD_CTLR);
+		val |= GICD_CTLR_DS;
+		writel_relaxed(val, gic_data.dist_base + GICD_CTLR);
+
+		ds = gic_dist_security_disabled();
+		if (ds)
+			pr_warn("Broken GIC integration, security disabled");
+	}
+
+	cpus_have_security_disabled = ds;
 	cpus_have_group0 = gic_has_group0();
 
 	/*