]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sourcestats: don't fudge refclock LastRx in sources report
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 2 Feb 2023 10:12:31 +0000 (11:12 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 2 Feb 2023 10:26:04 +0000 (11:26 +0100)
The sample time used in calculation of the last_meas_ago (LastRx) value
in the sources report is aligned to the second to minimize the leak
of the NTP receive timestamp, which could be useful in some attacks.

There is no need to do that with reference clocks, which are often used
with very short polling intervals and an extra second in the LastRx
value can be misinterpreted as a missed sample.

sourcestats.c

index eb4705ecd3b1ae76f67e28e63a253ebf8e1e8eec..ce326e9494609c9a5303640f00e6aa6a48673986 100644 (file)
@@ -80,7 +80,7 @@ static LOG_FileID logfileid;
 
 struct SST_Stats_Record {
 
-  /* Reference ID and IP address of source, used for logging to statistics log */
+  /* Reference ID and IP address (NULL if not an NTP source) */
   uint32_t refid;
   IPAddr *ip_addr;
 
@@ -964,9 +964,10 @@ SST_DoSourceReport(SST_Stats inst, RPT_SourceReport *report, struct timespec *no
     report->latest_meas = inst->offsets[i];
     report->latest_meas_err = 0.5*inst->root_delays[j] + inst->root_dispersions[j];
 
-    /* Align the sample time to reduce the leak of the receive timestamp */
+    /* Align the sample time to reduce the leak of the NTP receive timestamp */
     last_sample_time = inst->sample_times[i];
-    last_sample_time.tv_nsec = 0;
+    if (inst->ip_addr)
+      last_sample_time.tv_nsec = 0;
     report->latest_meas_ago = UTI_DiffTimespecsToDouble(now, &last_sample_time);
   } else {
     report->latest_meas_ago = (uint32_t)-1;