DragonFlyBSD Kernel Audit
DF-0234 / fix.diff
← back to finding ↓ download raw
diff --git a/sys/kern/kern_wdog.c b/sys/kern/kern_wdog.c
--- a/sys/kern/kern_wdog.c
+++ b/sys/kern/kern_wdog.c
@@ -102,7 +102,15 @@
 			min_period = period;
 	}
 	if (wdog_auto_enable) {
-		callout_reset(&wdog_callout, min_period * hz / 2,
+		int wdog_ticks;
+		/* DF-0234: min_period may be (close to) INT_MAX; the
+		 * expression min_period * hz would then overflow a signed
+		 * int and yield a negative/garbage callout delay.  Clamp it
+		 * to the largest value that cannot overflow. */
+		if (min_period > INT_MAX / hz)
+			min_period = INT_MAX / hz;
+		wdog_ticks = min_period * hz / 2;
+		callout_reset(&wdog_callout, wdog_ticks,
 			      wdog_reset_all, NULL);
 	}
 	wdog_auto_period = min_period;