]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
rtc: check for backward RTC steps
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 12 Jan 2017 12:43:41 +0000 (13:43 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 12 Jan 2017 15:34:28 +0000 (16:34 +0100)
When accumulating a new sample, check if the new RTC time is newer the
last sample time. If it is not, discard all previous samples, assuming
something has stepped the RTC, or it's a broken RTC/driver.

rtc_linux.c

index 8d7310265092c046dc9731a3fbc75ae59e5ad7d0..7394235bd3f966b390d9c7fa455370fc1309f3bb 100644 (file)
@@ -187,6 +187,11 @@ accumulate_sample(time_t rtc, struct timespec *sys)
     discard_samples(NEW_FIRST_WHEN_FULL);
   }
 
+  /* Discard all samples if the RTC was stepped back (not our trim) */
+  if (n_samples > 0 && rtc_sec[n_samples - 1] - rtc >= rtc_trim[n_samples - 1]) {
+    DEBUG_LOG(LOGF_RtcLinux, "RTC samples discarded");
+    n_samples = 0;
+  }
 
   /* Always use most recent sample as reference */
   /* use sample only if n_sample is not negative*/