⬢ DragonFlyBSD Kernel Audit
DF-5352 / fix.diff
← back to finding ↓ download raw
--- a/sys/platform/pc64/apic/ioapic_abi.c
+++ b/sys/platform/pc64/apic/ioapic_abi.c
@@ -996,13 +996,23 @@
 	KKASSERT(trig == INTR_TRIGGER_EDGE || trig == INTR_TRIGGER_LEVEL);
 	KKASSERT(pola == INTR_POLARITY_HIGH || pola == INTR_POLARITY_LOW);
 
-	KKASSERT(irq >= 0 && irq < ioapic_abi_legacy_irq_max);
+	/*
+	 * Driver-facing ABI (bus_config_intr()): validate at run time
+	 * instead of relying on INVARIANTS-only KKASSERTs.
+	 */
+	if (irq < 0 || irq >= ioapic_abi_legacy_irq_max)
+		return;
 	for (cpuid = 0; cpuid < ncpus; ++cpuid) {
 		map = &ioapic_irqmaps[cpuid][irq];
 		if (map->im_type == IOAPIC_IMT_LEGACY)
 			break;
 	}
-	KKASSERT(cpuid < ncpus);
+	/*
+	 * IRQ exists but is not a legacy map on any CPU (MSI/MSI-X or
+	 * unused): im_gsi is -1 and ioapic_gsi_pin(-1) would panic.
+	 */
+	if (cpuid >= ncpus)
+		return;
 
 #ifdef notyet
 	if (map->im_flags & IOAPIC_IMF_CONF) {