⬢ DragonFlyBSD Kernel Audit
DF-5464 / fix.diff
← back to finding ↓ download raw
--- /tmp/fixwork/orig/icu_abi.c	2026-10-05 23:29:27.154012889 +0000
+++ /tmp/fixwork/new/icu_abi.c	2026-10-05 23:29:56.341638690 +0000
@@ -177,6 +177,8 @@
 
 	KASSERT(irq >= 0 && irq < IDT_HWI_VECTORS,
 	    ("icu enable, invalid irq %d", irq));
+	if (irq < 0 || irq >= IDT_HWI_VECTORS)
+		return;
 
 	map = &icu_irqmaps[mycpuid][irq];
 	KASSERT(ICU_IMT_ISHWI(map),
@@ -195,6 +197,8 @@
 
 	KASSERT(irq >= 0 && irq < IDT_HWI_VECTORS,
 	    ("icu disable, invalid irq %d", irq));
+	if (irq < 0 || irq >= IDT_HWI_VECTORS)
+		return;
 
 	map = &icu_irqmaps[mycpuid][irq];
 	KASSERT(ICU_IMT_ISHWI(map),
@@ -262,6 +266,8 @@
 
 	KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
 	    ("icu setup, invalid irq %d", intr));
+	if (intr < 0 || intr >= IDT_HWI_VECTORS)
+		return;
 
 	map = &icu_irqmaps[mycpuid][intr];
 	KASSERT(ICU_IMT_ISHWI(map),
@@ -286,6 +292,8 @@
 
 	KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
 	    ("icu teardown, invalid irq %d", intr));
+	if (intr < 0 || intr >= IDT_HWI_VECTORS)
+		return;
 
 	map = &icu_irqmaps[mycpuid][intr];
 	KASSERT(ICU_IMT_ISHWI(map),
@@ -322,6 +330,8 @@
 
 	kgetenv_int("hw.icu.msi_start", &icu_abi_msi_start);
 	icu_abi_msi_start &= ~0x1f;	/* MUST be 32 aligned */
+	if (icu_abi_msi_start < 0 || icu_abi_msi_start >= IDT_HWI_VECTORS)
+		icu_abi_msi_start = 0;	/* DF-5466: never index below the map */
 
 	/*
 	 * NOTE: ncpus is not ready yet
@@ -371,9 +381,13 @@
 	KKASSERT(trig == INTR_TRIGGER_EDGE || trig == INTR_TRIGGER_LEVEL);
 
 	KKASSERT(irq >= 0 && irq < IDT_HWI_VECTORS);
+	if (irq < 0 || irq >= ICU_HWI_VECTORS)
+		return;
 	map = &icu_irqmaps[0][irq];
 
 	KKASSERT(map->im_type == ICU_IMT_LEGACY);
+	if (map->im_type != ICU_IMT_LEGACY)
+		return;
 
 	/* TODO: Check whether it is configured or not */
 	map->im_flags |= ICU_IMF_CONF;
@@ -459,6 +473,8 @@
 
 	KASSERT(count > 0 && count <= 32, ("invalid count %d", count));
 	KASSERT(powerof2(count), ("count %d is not power of 2", count));
+	if (count <= 0 || count > 32 || !powerof2(count))
+		return EINVAL;
 
 	lwkt_gettoken(&icu_irqmap_tok);
 
@@ -525,6 +541,8 @@
 
 	mask = count - 1;
 	KASSERT((count & mask) == 0, ("count %d is not power of 2", count));
+	if (count <= 0 || count > 32 || !powerof2(count))
+		return;
 
 	lwkt_gettoken(&icu_irqmap_tok);