Skip to contentSkip to conversation

irqchip/gic-v4: Harden against bogus command line

PATCH Superseded Mostafa Saleh 2 participants 5 messages May 21 – May 26

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 irqchip/gic-v4: Harden against bogus command line

When accidentally setting “kvm-arm.vgic_v4_enable=1” on the wrong setup that has no MSI controller device tree node (it exists but not used) and GICv4, it caused a panic as “gic_domain” is NULL and the kernel attempted to access its ops.

Originally, I hit this on an older kernel, but was able to reproduce it on upstream with Qemu by hacking this unreasonable setup.

[   33.145536] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000028
[   33.145658] Mem abort info:
[   33.145751]   ESR = 0x0000000096000006
...
[   33.154057] CPU: 1 UID: 0 PID: 295 Comm: lkvm-static Not tainted 7.1.0-rc4-ge3f15ad3970e #5 PREEMPT
[   33.156922] Hardware name: linux,dummy-virt (DT)
[   33.158780] pstate: 81402005 (Nzcv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[   33.160340] pc : __irq_domain_instantiate+0x1d4/0x578
[   33.162602] lr : __irq_domain_instantiate+0x1cc/0x578

Add a hardening check to avoid the NULL access, and fail the VM creation in that case.

---
 drivers/irqchip/irq-gic-v4.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v4.c +3 -0
index 8455b4a5fbb0..7e39f7eae85f 100644
@@ -159,6 +159,9 @@ int its_alloc_vcpu_irqs(struct its_vm *vm)
 {
 	int vpe_base_irq, i;
 
+	if (!gic_domain)
+		return -EINVAL;
+
 	vm->fwnode = irq_domain_alloc_named_id_fwnode("GICv4-vpe",
 						      task_pid_nr(current));
 	if (!vm->fwnode)
Signature · 1 line
2.54.0.669.g59709faab0-goog
maintainer
#1 lore raw
Quoted 5 lines · Mostafa Saleh

When accidentally setting “kvm-arm.vgic_v4_enable=1” on the wrong setup that has no MSI controller device tree node (it exists but not used) and GICv4, it caused a panic as “gic_domain” is NULL and the kernel attempted to access its ops.

When you say "that has no MSI controller device tree node", does it mean that the ITS has not been probed at all?

Quoted 27 lines

Originally, I hit this on an older kernel, but was able to reproduce it on upstream with Qemu by hacking this unreasonable setup.

[   33.145536] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000028
[   33.145658] Mem abort info:
[   33.145751]   ESR = 0x0000000096000006
...
[   33.154057] CPU: 1 UID: 0 PID: 295 Comm: lkvm-static Not tainted 7.1.0-rc4-ge3f15ad3970e #5 PREEMPT
[   33.156922] Hardware name: linux,dummy-virt (DT)
[   33.158780] pstate: 81402005 (Nzcv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[   33.160340] pc : __irq_domain_instantiate+0x1d4/0x578
[   33.162602] lr : __irq_domain_instantiate+0x1cc/0x578

Add a hardening check to avoid the NULL access, and fail the VM creation in that case.

---
 drivers/irqchip/irq-gic-v4.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v4.c +0 -0
index 8455b4a5fbb0..7e39f7eae85f 100644

drivers/irqchip/irq-gic-v4.c int its_alloc_vcpu_irqs(struct its_vm *vm) · line 167

Quoted 9 lines
drivers/irqchip/irq-gic-v4.c +3 -0
@@ -159,6 +159,9 @@ int its_alloc_vcpu_irqs(struct its_vm *vm)
 {
 	int vpe_base_irq, i;
 
+	if (!gic_domain)
+		return -EINVAL;
+
 	vm->fwnode = irq_domain_alloc_named_id_fwnode("GICv4-vpe",
 						      task_pid_nr(current));
 	if (!vm->fwnode)

I think this check is a good few levels too late. If you want to fix this, I'd rather make sure that kvm_vgic_global_state.has_gicv4 is reliable and covers this case. Which means making sure that gic_kvm_info::has_v4 is itself reliable.

If my above understanding is correct, I'd expect the following (untested) hack to help.

Thanks,

	M.
drivers/irqchip/irq-gic-v3-its.c +1 -0
index 291d7668cc8da..e6b9fee1b6786 100644
@@ -5838,6 +5838,7 @@ int __init its_init(struct fwnode_handle *handle, struct rdists *rdists,
 
 	if (list_empty(&its_nodes)) {
 		pr_warn("ITS: No ITS available, not enabling LPIs\n");
+		rdists->has_vlpis = false;
 		return -ENXIO;
 	}
 
Signature · 1 line
Without deviation from the norm, progress is not possible.
#2 lore raw
Quoted 10 lines · Marc Zyngier
Quoted 5 lines · Mostafa Saleh

When accidentally setting “kvm-arm.vgic_v4_enable=1” on the wrong setup that has no MSI controller device tree node (it exists but not used) and GICv4, it caused a panic as “gic_domain” is NULL and the kernel attempted to access its ops.

When you say "that has no MSI controller device tree node", does it mean that the ITS has not been probed at all?

Yes.

Quoted 43 lines
Quoted 28 lines

Originally, I hit this on an older kernel, but was able to reproduce it on upstream with Qemu by hacking this unreasonable setup.

[   33.145536] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000028
[   33.145658] Mem abort info:
[   33.145751]   ESR = 0x0000000096000006
...
[   33.154057] CPU: 1 UID: 0 PID: 295 Comm: lkvm-static Not tainted 7.1.0-rc4-ge3f15ad3970e #5 PREEMPT
[   33.156922] Hardware name: linux,dummy-virt (DT)
[   33.158780] pstate: 81402005 (Nzcv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[   33.160340] pc : __irq_domain_instantiate+0x1d4/0x578
[   33.162602] lr : __irq_domain_instantiate+0x1cc/0x578

Add a hardening check to avoid the NULL access, and fail the VM creation in that case.

---
 drivers/irqchip/irq-gic-v4.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v4.c +0 -0
index 8455b4a5fbb0..7e39f7eae85f 100644

drivers/irqchip/irq-gic-v4.c int its_alloc_vcpu_irqs(struct its_vm *vm) · line 167

Quoted 9 lines
drivers/irqchip/irq-gic-v4.c +3 -0
@@ -159,6 +159,9 @@ int its_alloc_vcpu_irqs(struct its_vm *vm)
 {
 	int vpe_base_irq, i;
 
+	if (!gic_domain)
+		return -EINVAL;
+
 	vm->fwnode = irq_domain_alloc_named_id_fwnode("GICv4-vpe",
 						      task_pid_nr(current));
 	if (!vm->fwnode)

I think this check is a good few levels too late. If you want to fix this, I'd rather make sure that kvm_vgic_global_state.has_gicv4 is reliable and covers this case. Which means making sure that gic_kvm_info::has_v4 is itself reliable.

Quoted 2 lines

If my above understanding is correct, I'd expect the following (untested) hack to help.

Thanks! That also fixes the crash, the VM will launch with a vGIC with no ITS in that case.

Thanks,
Mostafa

Quoted 20 lines

Thanks,

	M.
drivers/irqchip/irq-gic-v3-its.c +1 -0
index 291d7668cc8da..e6b9fee1b6786 100644
@@ -5838,6 +5838,7 @@ int __init its_init(struct fwnode_handle *handle, struct rdists *rdists,
 
 	if (list_empty(&its_nodes)) {
 		pr_warn("ITS: No ITS available, not enabling LPIs\n");
+		rdists->has_vlpis = false;
 		return -ENXIO;
 	}
 
Signature · 2 lines
-- 
Without deviation from the norm, progress is not possible.
maintainer
#3 lore raw
Quoted 58 lines · Mostafa Saleh
Quoted 10 lines · Marc Zyngier
Quoted 5 lines · Mostafa Saleh

When accidentally setting “kvm-arm.vgic_v4_enable=1” on the wrong setup that has no MSI controller device tree node (it exists but not used) and GICv4, it caused a panic as “gic_domain” is NULL and the kernel attempted to access its ops.

When you say "that has no MSI controller device tree node", does it mean that the ITS has not been probed at all?

Yes.

Quoted 43 lines
Quoted 28 lines

Originally, I hit this on an older kernel, but was able to reproduce it on upstream with Qemu by hacking this unreasonable setup.

[   33.145536] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000028
[   33.145658] Mem abort info:
[   33.145751]   ESR = 0x0000000096000006
...
[   33.154057] CPU: 1 UID: 0 PID: 295 Comm: lkvm-static Not tainted 7.1.0-rc4-ge3f15ad3970e #5 PREEMPT
[   33.156922] Hardware name: linux,dummy-virt (DT)
[   33.158780] pstate: 81402005 (Nzcv daif +PAN -UAO -TCO +DIT -SSBS BTYPE=--)
[   33.160340] pc : __irq_domain_instantiate+0x1d4/0x578
[   33.162602] lr : __irq_domain_instantiate+0x1cc/0x578

Add a hardening check to avoid the NULL access, and fail the VM creation in that case.

---
 drivers/irqchip/irq-gic-v4.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/irqchip/irq-gic-v4.c +0 -0
index 8455b4a5fbb0..7e39f7eae85f 100644

drivers/irqchip/irq-gic-v4.c int its_alloc_vcpu_irqs(struct its_vm *vm) · line 167

Quoted 9 lines
drivers/irqchip/irq-gic-v4.c +3 -0
@@ -159,6 +159,9 @@ int its_alloc_vcpu_irqs(struct its_vm *vm)
 {
 	int vpe_base_irq, i;
 
+	if (!gic_domain)
+		return -EINVAL;
+
 	vm->fwnode = irq_domain_alloc_named_id_fwnode("GICv4-vpe",
 						      task_pid_nr(current));
 	if (!vm->fwnode)

I think this check is a good few levels too late. If you want to fix this, I'd rather make sure that kvm_vgic_global_state.has_gicv4 is reliable and covers this case. Which means making sure that gic_kvm_info::has_v4 is itself reliable.

Quoted 5 lines
Quoted 2 lines

If my above understanding is correct, I'd expect the following (untested) hack to help.

Thanks! That also fixes the crash, the VM will launch with a vGIC with no ITS in that case.

You should still be able to have a virtual ITS, just no direct injection of any sort.

If you're happy with that, please respin a patch with this hack.

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#4 lore raw
Quoted 5 lines · Marc Zyngier

You should still be able to have a virtual ITS, just no direct injection of any sort.

True, my bad.

Quoted 2 lines

If you're happy with that, please respin a patch with this hack.

Done!

Thanks,
Mostafa

Quoted 6 lines

Thanks,

        M.

--
Without deviation from the norm, progress is not possible.