]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
hwclock: check if estimated frequency is sane
authorMiroslav Lichvar <mlichvar@redhat.com>
Tue, 22 Aug 2017 11:29:48 +0000 (13:29 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 23 Aug 2017 13:01:30 +0000 (15:01 +0200)
hwclock.c

index a6427c3fb50aaa3012828fc8835c03d0aa5380e3..7f2bf0437ba760310bdc5ec56773ad011e2a52d3 100644 (file)
--- a/hwclock.c
+++ b/hwclock.c
@@ -39,6 +39,9 @@
 /* Maximum number of samples per clock */
 #define MAX_SAMPLES 16
 
+/* Maximum acceptable frequency offset of the clock */
+#define MAX_FREQ_OFFSET (2.0 / 3.0)
+
 struct HCL_Instance_Record {
   /* HW and local reference timestamp */
   struct timespec hw_ref;
@@ -175,8 +178,9 @@ HCL_AccumulateSample(HCL_Instance clock, struct timespec *hw_ts,
   clock->n_samples -= best_start;
 
   /* If the fit doesn't cross the error interval of the last sample,
-     throw away all samples and start again */
-  if (fabs(clock->offset) > err) {
+     or the frequency is not sane, drop all samples and start again */
+  if (fabs(clock->offset) > err ||
+      fabs(clock->frequency - 1.0) > MAX_FREQ_OFFSET) {
     DEBUG_LOG("HW clock reset");
     clock->n_samples = 0;
     clock->valid_coefs = 0;