⬢ DragonFlyBSD Kernel Audit
DF-5640 / fix.diff
← back to finding ↓ download raw
diff -u -r sys/cpu/x86_64/misc/cputimer_tsc.c sys/cpu/x86_64/misc/cputimer_tsc.c
--- sys/cpu/x86_64/misc/cputimer_tsc.c
+++ sys/cpu/x86_64/misc/cputimer_tsc.c
@@ -138,6 +138,12 @@
 	if (!enable)
 		return;
 
+	if (tsc_frequency == 0) {
+		kprintf("TSC: frequency is not calibrated; "
+		    "TSC cputimer disabled\n");
+		return;
+	}
+
 	/*
 	 * NOTE: We no longer shift the tsc to limit the reported
 	 *	 frequency.  We use the actual tsc frequency as-is.
@@ -159,6 +165,11 @@
 #ifndef _KERNEL_VIRTUAL
 regcnt:
 #endif
+	if (tsc_frequency == 0) {
+		kprintf("TSC: frequency is not calibrated; "
+		    "TSC cpucounter disabled\n");
+		return;
+	}
 	tsc_cpucounter.freq = tsc_frequency;
 	if (cpu_vendor_id == CPU_VENDOR_INTEL) {
 		tsc_cpucounter.count =
diff -u -r sys/kern/kern_cputimer.c sys/kern/kern_cputimer.c
--- sys/kern/kern_cputimer.c
+++ sys/kern/kern_cputimer.c
@@ -186,6 +186,11 @@
 void
 cputimer_set_frequency(struct cputimer *timer, sysclock_t freq)
 {
+    if (freq == 0) {
+	kprintf("cputimer: refusing zero frequency for %s "
+	    "(cputimer unchanged)\n", timer->name);
+	return;
+    }
     timer->freq = freq;
     timer->freq64_usec = (1000000LL << 32) / freq;
     timer->freq64_nsec = (1000000000LL << 32) / freq;