⬢ DragonFlyBSD Kernel Audit
DF-5351 / fix.diff
← back to finding ↓ download raw
--- a/sys/platform/pc64/apic/ioapic_abi.c
+++ b/sys/platform/pc64/apic/ioapic_abi.c
@@ -1252,9 +1252,16 @@
 
 	KASSERT(cpuid >= 0 && cpuid < ncpus,
 	    ("invalid cpuid %d", cpuid));
+	if (cpuid < 0 || cpuid >= ncpus)
+		return (EINVAL);
 
-	KASSERT(count > 0 && count <= 32, ("invalid count %d", count));
-	KASSERT(powerof2(count), ("count %d is not power of 2", count));
+	/*
+	 * 'count' comes from drivers and the caller's intrs[] array is
+	 * only guaranteed to hold 32 entries; validate at run time, not
+	 * only with INVARIANTS-only KASSERTs.
+	 */
+	if (count <= 0 || count > 32 || (count & (count - 1)) != 0)
+		return (EINVAL);
 
 	lwkt_gettoken(&ioapic_irqmap_tok);
 
@@ -1317,11 +1324,17 @@
 
 	KASSERT(cpuid >= 0 && cpuid < ncpus,
 	    ("invalid cpuid %d", cpuid));
+	if (cpuid < 0 || cpuid >= ncpus)
+		return;
 
 	KASSERT(count > 0 && count <= 32, ("invalid count %d", count));
+	if (count <= 0 || count > 32)
+		return;
 
 	mask = count - 1;
 	KASSERT((count & mask) == 0, ("count %d is not power of 2", count));
+	if ((count & mask) != 0)
+		return;
 
 	lwkt_gettoken(&ioapic_irqmap_tok);