]> git.ipfire.org Git - thirdparty/chrony.git/log
thirdparty/chrony.git
2 years agomakefile: compile getdate.o with -fwrapv option
Miroslav Lichvar [Mon, 26 Jun 2023 11:20:22 +0000 (13:20 +0200)] 
makefile: compile getdate.o with -fwrapv option

The getdate code (copied from gnulib before it was switched to GPLv3)
has multiple issues with signed integer overflows. Use the -fwrapv
compiler option for this object to at least make the operations defined.

2 years agodoc: update NEWS 4.4-pre2
Miroslav Lichvar [Wed, 21 Jun 2023 09:27:41 +0000 (11:27 +0200)] 
doc: update NEWS

2 years agontp: refresh IP addresses periodically
Miroslav Lichvar [Tue, 20 Jun 2023 14:23:34 +0000 (16:23 +0200)] 
ntp: refresh IP addresses periodically

Refresh NTP sources specified by hostname periodically (every 2 weeks
by default) to avoid long-running instances using a server which is no
longer intended for service, even if it is still responding correctly
and would not be replaced as unreachable, and help redistributing load
in large pools like pool.ntp.org. Only one source is refreshed at a time
to not interrupt clock updates if there are multiple selectable servers.

The refresh directive configures the interval. A value of 0 disables
the periodic refreshment.

Suggested-by: Ask Bjørn Hansen <ask@develooper.com>
2 years agodoc: remove out-of-date statement in server description
Miroslav Lichvar [Tue, 20 Jun 2023 13:28:07 +0000 (15:28 +0200)] 
doc: remove out-of-date statement in server description

chronyc refresh no longer forces replacement of sources.

Fixes: b2dac47c8267 ("ntp: avoid unneccessary replacements on refresh command")
2 years agontp: remove resolving timeout in finalization
Miroslav Lichvar [Mon, 19 Jun 2023 14:46:10 +0000 (16:46 +0200)] 
ntp: remove resolving timeout in finalization

Don't assume NSR_Finalise() can be called only on exit when the
scheduler is finalized.

2 years agosched: reset timer queue in finalization
Miroslav Lichvar [Mon, 19 Jun 2023 14:10:45 +0000 (16:10 +0200)] 
sched: reset timer queue in finalization

Don't leave dangling pointers to timer queue entries when they are
freed in the scheduler finalization in case some code tried to remove
a timer later.

Fixes: 6ea1082a72d8 ("sched: free timer blocks on exit")
2 years agoexamples: don't set ProcSubset=pid in systemd unit files
Miroslav Lichvar [Thu, 15 Jun 2023 13:23:40 +0000 (15:23 +0200)] 
examples: don't set ProcSubset=pid in systemd unit files

This option seems to break detection of the FIPS mode, which is needed
by gnutls.

2 years agosources: delay source replacement
Miroslav Lichvar [Thu, 15 Jun 2023 10:54:32 +0000 (12:54 +0200)] 
sources: delay source replacement

Wait for four consecutive source selections giving a bad status
(falseticker, bad distance or jittery) before triggering the source
replacement. This should reduce the rate of unnecessary replacements
and shorten the time needed to find a solution when unreplaceable
falsetickers are preventing other sources from forming a majority due
to switching back and forth to unreachable servers.

2 years agosources: replace reachable sources in selection
Miroslav Lichvar [Wed, 14 Jun 2023 12:52:10 +0000 (14:52 +0200)] 
sources: replace reachable sources in selection

Instead of waiting for the next update of reachability, trigger
replacement of falsetickers, jittery and distant sources as soon as
the selection status is updated in their SRC_SelectSource() call.

2 years agontp: reset poll score
Miroslav Lichvar [Thu, 15 Jun 2023 12:09:21 +0000 (14:09 +0200)] 
ntp: reset poll score

When the polling interval is reset (e.g. after replacement), don't
forget to reset also the score impacting the next poll adjustment.

2 years agomain: wait for parent process to terminate
Miroslav Lichvar [Mon, 12 Jun 2023 14:11:10 +0000 (16:11 +0200)] 
main: wait for parent process to terminate

When starting the daemon, wait in the grandparent process for the parent
process to terminate before exiting to avoid systemd logging a warning
"Supervising process $PID which is not our child". Waiting for the pipe
to be closed by the kernel when the parent process exits is not
sufficient.

Reported-by: Jan Pazdziora <jpazdziora@redhat.com>
2 years agontp: randomize replacement interval
Miroslav Lichvar [Tue, 6 Jun 2023 10:02:53 +0000 (12:02 +0200)] 
ntp: randomize replacement interval

Replacement attempts are globally rate limited to one per 7*2^8 seconds
to limit the rate of DNS requests for public servers like pool.ntp.org.
If multiple sources are repeatedly attempting replacement (at their
polling intervals), one source can be getting all attempts for periods
of time.

Use a randomly generated interval to randomize the order of source
replacements without changing the average rate.

2 years agontp: use monotonic time for replacement interval
Miroslav Lichvar [Tue, 6 Jun 2023 08:40:51 +0000 (10:40 +0200)] 
ntp: use monotonic time for replacement interval

Avoid errors in the measured interval due to clock steps.

2 years agontp: add debug message for bad sources
Miroslav Lichvar [Mon, 5 Jun 2023 13:18:27 +0000 (15:18 +0200)] 
ntp: add debug message for bad sources

2 years agoclient: check for allocation errors in tab completition
Miroslav Lichvar [Thu, 8 Jun 2023 14:04:21 +0000 (16:04 +0200)] 
client: check for allocation errors in tab completition

2 years agoclient: avoid passing uninitialized address to format_name()
Miroslav Lichvar [Mon, 5 Jun 2023 14:10:46 +0000 (16:10 +0200)] 
client: avoid passing uninitialized address to format_name()

The clang memory sanitizer seems to trigger on an uninitialized value
passed to format_name() when the source is a refclock, even though the
value is not used for anything. Pass 0 in this case to avoid the error.

2 years agomemory: use free() instead of realloc() for size 0
Miroslav Lichvar [Mon, 5 Jun 2023 13:40:22 +0000 (15:40 +0200)] 
memory: use free() instead of realloc() for size 0

valgrind 3.21.0 reports realloc() of 0 bytes as an error due to having
different behavior on different systems. The only place where this can
happen in chrony is the array, which doesn't care what value realloc()
returns.

Modify the realloc wrapper to call free() in this case to make valgrind
happy.

2 years agosys_linux: allow writev and TIOCGWINSZ in seccomp filter
Miroslav Lichvar [Thu, 1 Jun 2023 12:30:40 +0000 (14:30 +0200)] 
sys_linux: allow writev and TIOCGWINSZ in seccomp filter

Allow more syscalls for musl.

Reported-by: jvoisin <julien.voisin@dustri.org>
2 years agotest: set root ownership of tmp directory in system tests
Miroslav Lichvar [Thu, 1 Jun 2023 09:56:29 +0000 (11:56 +0200)] 
test: set root ownership of tmp directory in system tests

Allow the tests to be started under a non-zero GID.

2 years agotest: modify order of scfilter levels in system tests
Miroslav Lichvar [Mon, 29 May 2023 14:17:39 +0000 (16:17 +0200)] 
test: modify order of scfilter levels in system tests

Start with positive levels to get the offending system calls in the
system or audit log.

2 years agotest: fix 010-nts test for AES-GCM-SIV support
Miroslav Lichvar [Thu, 1 Jun 2023 12:51:38 +0000 (14:51 +0200)] 
test: fix 010-nts test for AES-GCM-SIV support

2 years agonts: don't load zero-length keys with unsupported algorithm
Miroslav Lichvar [Mon, 29 May 2023 12:12:54 +0000 (14:12 +0200)] 
nts: don't load zero-length keys with unsupported algorithm

Don't load keys and cookies from the client's dump file if it has an
unsupported algorithm and unparseable keys (matching the algorithm's
expected length of zero). They would fail all SIV operations and trigger
new NTS-KE session.

2 years agodoc: clarify limitation of refresh command
Miroslav Lichvar [Wed, 24 May 2023 13:41:45 +0000 (15:41 +0200)] 
doc: clarify limitation of refresh command

2 years agosys_linux: allow membarrier in seccomp filter
Miroslav Lichvar [Wed, 24 May 2023 08:56:07 +0000 (10:56 +0200)] 
sys_linux: allow membarrier in seccomp filter

This system call is used by musl.

Reported-by: jvoisin <julien.voisin@dustri.org>
2 years agoconfigure: add option to disable AES-GCM-SIV support
Miroslav Lichvar [Tue, 23 May 2023 14:36:25 +0000 (16:36 +0200)] 
configure: add option to disable AES-GCM-SIV support

2 years agonts: remove superfluous semicolon
Miroslav Lichvar [Tue, 23 May 2023 13:40:47 +0000 (15:40 +0200)] 
nts: remove superfluous semicolon

2 years agonts: initialize unused part of server key
Miroslav Lichvar [Tue, 23 May 2023 13:37:06 +0000 (15:37 +0200)] 
nts: initialize unused part of server key

Initialize the unused part of shorter server NTS keys (AES-128-GCM-SIV)
loaded from ntsdumpdir to avoid sending uninitialized data in requests
to the NTS-KE helper process.

Do that also for newly generated keys in case the memory will be
allocated dynamically.

Fixes: b1230efac333 ("nts: add support for encrypting cookies with AES-128-GCM-SIV")
2 years agontp: randomize address selection on all source replacements
Miroslav Lichvar [Mon, 22 May 2023 09:58:41 +0000 (11:58 +0200)] 
ntp: randomize address selection on all source replacements

If the resolver orders addresses by IP family, there is more than one
address in the preferred IP family, and they are all reachable, but
not selectable (e.g. falsetickers in a small pool which cannot remove
them from DNS), chronyd is unable to switch to addresses in the other IP
family as it follows the resolver's order.

Enable randomization of the address selection for all source
replacements and not just replacement of (unreachable) tentative
sources. If the system doesn't have connectivity in the other family,
the addresses will be skipped and no change in behavior should be
observed.

2 years agontp: set minimum polltarget
Miroslav Lichvar [Wed, 17 May 2023 14:37:55 +0000 (16:37 +0200)] 
ntp: set minimum polltarget

The polltarget value is used in a floating-point division in the
calculation of the poll adjustment. Set 1 as the minimum accepted
polltarget value to avoid working with infinite values.

2 years agontp: reset polling interval when replacing sources
Miroslav Lichvar [Tue, 16 May 2023 13:11:22 +0000 (15:11 +0200)] 
ntp: reset polling interval when replacing sources

Set the polling interval to minpoll when changing address of a source,
but only if it is reachable to avoid increasing load on server or
network in case that is the reason for the source being unreachable.

This shortens the time needed to replace a falseticker or
unsynchronized source with a selectable source.

2 years agontp: avoid unneccessary replacements on refresh command
Miroslav Lichvar [Mon, 15 May 2023 14:26:21 +0000 (16:26 +0200)] 
ntp: avoid unneccessary replacements on refresh command

When the refresh command is issued, instead of trying to replace all
NTP sources as if they were unreachable or falsetickers, keep using the
current address if it is still returned by the resolver for the name.
This avoids unnecessary loss of measurements and switching to
potentially unreachable addresses.

2 years agodoc: update NEWS 4.4-pre1
Miroslav Lichvar [Wed, 10 May 2023 09:42:01 +0000 (11:42 +0200)] 
doc: update NEWS

2 years agodoc: update list of contributors in README
Miroslav Lichvar [Wed, 10 May 2023 07:59:44 +0000 (09:59 +0200)] 
doc: update list of contributors in README

2 years agoexamples: improve chrony.nm-dispatcher.onoffline script
Rupesh Patel [Fri, 28 Apr 2023 15:31:40 +0000 (15:31 +0000)] 
examples: improve chrony.nm-dispatcher.onoffline script

2 years agotest: add 146-offline test
Miroslav Lichvar [Tue, 18 Apr 2023 09:39:27 +0000 (11:39 +0200)] 
test: add 146-offline test

2 years agomd5: fix old-style function definitions
Miroslav Lichvar [Mon, 17 Apr 2023 09:40:18 +0000 (11:40 +0200)] 
md5: fix old-style function definitions

This fixes -Wdeprecated-non-prototype clang warnings.

Reported-by: Bryan Christianson <bryan@whatroute.net>
2 years agotest: free memory in unit tests on exit
Miroslav Lichvar [Wed, 12 Apr 2023 15:24:28 +0000 (17:24 +0200)] 
test: free memory in unit tests on exit

2 years agosched: free timer blocks on exit
Miroslav Lichvar [Wed, 12 Apr 2023 14:48:36 +0000 (16:48 +0200)] 
sched: free timer blocks on exit

Save pointers to allocated timer blocks and free them on exit. This
fixes the long-standing annoying "possibly lost" leak reported by
valgrind.

2 years agotest: add 145-rtc test
Miroslav Lichvar [Wed, 12 Apr 2023 10:36:49 +0000 (12:36 +0200)] 
test: add 145-rtc test

2 years agodoc: improve description of chronyd -Q option
Miroslav Lichvar [Mon, 3 Apr 2023 13:01:19 +0000 (15:01 +0200)] 
doc: improve description of chronyd -Q option

2 years agotest: add option to dump traffic to pcaps
Miroslav Lichvar [Mon, 3 Apr 2023 12:36:30 +0000 (14:36 +0200)] 
test: add option to dump traffic to pcaps

This will be useful for debugging.

2 years agontp: save response when waiting for HW TX timestamp
Miroslav Lichvar [Tue, 28 Mar 2023 13:33:50 +0000 (15:33 +0200)] 
ntp: save response when waiting for HW TX timestamp

Rework handling of late HW TX timestamps. Instead of suspending reading
from client-only sockets that have HW TX timestamping enabled, save the
whole response if it is valid and a HW TX timestamp was received for the
source before. When the timestamp is received, or the configurable
timeout is reached, process the saved response again, but skip the
authentication test as the NTS code allows only one response per
request. Only one valid response per source can be saved. If a second
valid response is received while waiting for the timestamp, process both
responses immediately in the order they were received.

The main advantage of this approach is that it works on all sockets, i.e.
even in the symmetric mode and with NTP-over-PTP, and the kernel does
not need to buffer invalid responses.

2 years agontp: rework calculation of transmit timeout
Miroslav Lichvar [Thu, 23 Mar 2023 16:04:57 +0000 (17:04 +0100)] 
ntp: rework calculation of transmit timeout

Previously, in the calculation of the next transmission time
corresponding to the current polling interval, the reference point was
the current time in the client mode (i.e. the time when the response is
processed) and the last transmission time in the symmetric mode.

Rework the code to use the last transmission in both modes and make it
independent from the time when the response is processed to avoid extra
delays due to waiting for HW TX timestamps.

2 years agoclient: avoid casting to long
Miroslav Lichvar [Thu, 23 Mar 2023 13:07:44 +0000 (14:07 +0100)] 
client: avoid casting to long

Use the PRI*32 specifiers in printf formats to avoid casting received
values to unsigned long.

2 years agocmdmon: switch serverstats to 64-bit integers
Miroslav Lichvar [Thu, 23 Mar 2023 11:42:30 +0000 (12:42 +0100)] 
cmdmon: switch serverstats to 64-bit integers

Update the serverstats response to use the new 64-bit integers.

Don't define a new value for the response as it already had an
incompatible change since the latest release (new fields added for
timestamp counters).

2 years agoclientlog: extend serverstats counters to 64 bits
Miroslav Lichvar [Thu, 23 Mar 2023 11:32:57 +0000 (12:32 +0100)] 
clientlog: extend serverstats counters to 64 bits

On a busy server the 32-bit counters included in the serverstats report
may overflow every few hours or days. Extend them to 64 bits.

2 years agocmdmon: define 64-bit integer
Miroslav Lichvar [Thu, 23 Mar 2023 10:37:11 +0000 (11:37 +0100)] 
cmdmon: define 64-bit integer

Add a structure for 64-bit integers without requiring 64-bit alignment
to be usable in CMD_Reply without struct packing.

Add utility functions for conversion to/from network order. Avoid using
be64toh() and htobe64() as they don't seem to be available on all
supported systems.

2 years agocmdmon: add timestamp counters to serverstats report
Miroslav Lichvar [Thu, 16 Mar 2023 15:59:18 +0000 (16:59 +0100)] 
cmdmon: add timestamp counters to serverstats report

Add the new RX/TX daemon/kernel/hardware timestamp counters to the
serverstats report.

2 years agoclientlog: count RX and TX timestamps for each source
Miroslav Lichvar [Thu, 16 Mar 2023 15:56:28 +0000 (16:56 +0100)] 
clientlog: count RX and TX timestamps for each source

Count served timestamps in all combinations of RX/TX and
daemon/kernel/hardware. Repurpose CLG_LogAuthNtpRequest() to update all
NTP-specific stats in one call per accepted request and response.

2 years agoclientlog: save source of transmit timestamps
Miroslav Lichvar [Thu, 16 Mar 2023 15:51:12 +0000 (16:51 +0100)] 
clientlog: save source of transmit timestamps

Add the timestamp source to the data kept for clients using interleaved
mode to allow extending server statistics.

2 years agontp: remove unnecessary check for NULL local timestamp
Miroslav Lichvar [Thu, 16 Mar 2023 16:19:33 +0000 (17:19 +0100)] 
ntp: remove unnecessary check for NULL local timestamp

After 5f4cbaab7e0e ("ntp: optimize detection of clients using
interleaved mode") the local TX timestamp is saved for all requests
indicating interleaved mode even when no previous RX timestamp is found.

2 years agontp: add maximum PHC poll interval
Miroslav Lichvar [Tue, 14 Mar 2023 11:23:21 +0000 (12:23 +0100)] 
ntp: add maximum PHC poll interval

Specify maxpoll for HW timestamping (default minpoll + 1) to track the
PHC well even when there is little NTP traffic on the interface. After
each PHC reading schedule a timeout according to the maxpoll. Polling
between minpoll and maxpoll is still triggered by HW timestamps.

Wait for the first HW timestamp before adding the timeout to avoid
polling PHCs on interfaces that are enabled in the configuration but
not used for NTP. Add a new scheduling class to separate polling of
different PHCs to avoid too long intervals between processing I/O
events.

2 years agodoc: add missing word in serverstats description
Miroslav Lichvar [Thu, 16 Mar 2023 15:19:59 +0000 (16:19 +0100)] 
doc: add missing word in serverstats description

2 years agodoc: replace offensive words
Miroslav Lichvar [Tue, 21 Mar 2023 15:38:10 +0000 (16:38 +0100)] 
doc: replace offensive words

2 years agodoc: mention NTP port number in FAQ
Miroslav Lichvar [Mon, 13 Mar 2023 15:03:11 +0000 (16:03 +0100)] 
doc: mention NTP port number in FAQ

2 years agontp: make socket resume timeout configurable
Miroslav Lichvar [Thu, 9 Mar 2023 10:09:33 +0000 (11:09 +0100)] 
ntp: make socket resume timeout configurable

In some cases even the new timeout of 1 millisecond is not sufficient to
get all HW TX timestamps. Add a new directive to allow users to
specify longer timeouts.

2 years agontp: increase socket resume timeout to 1 millisecond
Miroslav Lichvar [Thu, 9 Mar 2023 10:37:45 +0000 (11:37 +0100)] 
ntp: increase socket resume timeout to 1 millisecond

This seems to work significantly better on some hardware and is still
shorter than burst interval at the minimum configurable poll.

2 years agontp: add support for multiple suspended sockets
Miroslav Lichvar [Wed, 8 Mar 2023 16:07:38 +0000 (17:07 +0100)] 
ntp: add support for multiple suspended sockets

With some hardware it takes milliseconds to get the HW TX timestamp.

Rework the code to handle multiple suspended client-only sockets at the
same time in order to allow longer timeouts, which may overlap for
different sources. Instead of waiting for the first read event simply
suspend the socket and create timeout when the HW TX timestamp is
requested.

2 years agontp: increment sequence id in PTP messages
Dan Drown [Tue, 7 Mar 2023 15:29:19 +0000 (16:29 +0100)] 
ntp: increment sequence id in PTP messages

2 years agotest: update description of 106-refclock
Miroslav Lichvar [Thu, 2 Mar 2023 10:29:49 +0000 (11:29 +0100)] 
test: update description of 106-refclock

2 years agorefclock_phc: support multiple extpps refclocks on one PHC
Miroslav Lichvar [Wed, 1 Mar 2023 15:39:35 +0000 (16:39 +0100)] 
refclock_phc: support multiple extpps refclocks on one PHC

The Linux kernel (as of 6.2) has a shared queue of external timestamps
for all descriptors of the same PHC. If multiple refclocks using the
same PHC and the same or different channels were specified, some
refclocks didn't receive any or most of their timestamps, depending on
the rate and timing of the events (with the previous commit avoiding
blocking reads).

Track extpps-enabled refclocks in an array. Add PHC index to the PHC
instance. When a timestamp is read from the descriptor, provide it to
all refclocks that have the same PHC index and a channel matching the
event.

Make sure the timestamp is different from the previous one in case the
kernel will be improved to duplicate the timestamps for different
descriptors.

Reported-by: Matt Corallo <ntp-lists@mattcorallo.com>
2 years agosys_linux: avoid blocking in reading of external PHC timestamp
Miroslav Lichvar [Wed, 1 Mar 2023 13:41:34 +0000 (14:41 +0100)] 
sys_linux: avoid blocking in reading of external PHC timestamp

The kernel has a common queue for all readers of a PHC device. With
multiple PHC refclocks using the same device some reads blocked. PHC
devices don't seem to support non-blocking reads. Use poll() to check if
a timestamp is available before reading from the descriptor.

2 years agotest: add array unit test
Miroslav Lichvar [Wed, 1 Mar 2023 15:02:50 +0000 (16:02 +0100)] 
test: add array unit test

2 years agoarray: add function for removing elements
Miroslav Lichvar [Wed, 1 Mar 2023 15:02:16 +0000 (16:02 +0100)] 
array: add function for removing elements

2 years agontp: count missing samples when waiting for NTS-KE
Miroslav Lichvar [Mon, 27 Feb 2023 14:29:44 +0000 (15:29 +0100)] 
ntp: count missing samples when waiting for NTS-KE

Count missing samples for the median filter when
NAU_PrepareRequestAuth() is failing.

Fixes: 4234732b0883 ("ntp: rework filter option to count missing samples")
2 years agontp: don't adjust poll interval when waiting for NTS-KE
Miroslav Lichvar [Mon, 27 Feb 2023 14:00:50 +0000 (15:00 +0100)] 
ntp: don't adjust poll interval when waiting for NTS-KE

Don't adjust the NTP polling interval and decrement the burst count when
NAU_PrepareRequestAuth() fails (e.g. no NTS-KE response received yet,
network being down, or the server refusing connections), same as if an
NTP request could not be sent. Rely on the rate limiting implemented in
the NTS code.

2 years agonts: use shorter NTS-KE retry interval when network is down
Miroslav Lichvar [Thu, 23 Feb 2023 12:10:11 +0000 (13:10 +0100)] 
nts: use shorter NTS-KE retry interval when network is down

When chronyd configured with an NTS source not specified as offline and
resolvable without network was started before the network was up, it was
using an unnecessarily long NTS-KE retry interval, same as if the server
was refusing the connections.

When the network is down, the connect() call made from NKC_Start() on
the non-blocking TCP socket should fail with a different error than
EINPROGRESS and cause NKC_Start() to return with failure. Add a constant
2-second retry interval (matching default iburst) for this case.

2 years agonts: destroy NTS-KE client right after failed start
Miroslav Lichvar [Thu, 23 Feb 2023 13:58:29 +0000 (14:58 +0100)] 
nts: destroy NTS-KE client right after failed start

When NKC_Start() fails (e.g. due to unreachable network), don't wait for
the next poll to destroy the client and another poll to create and start
it again.

2 years agoclient: add -e option to indicate end of response
Miroslav Lichvar [Thu, 2 Feb 2023 15:38:11 +0000 (16:38 +0100)] 
client: add -e option to indicate end of response

In a non-tty session with chronyc it is not possible to detect the
end of the response without relying on timeouts, or separate responses
to a repeated command if using the -c option.

Add -e option to end each response with a line containing a single dot.

2 years agodoc: improve description of refclock filter option
Miroslav Lichvar [Thu, 2 Feb 2023 14:05:05 +0000 (15:05 +0100)] 
doc: improve description of refclock filter option

2 years agodoc: describe minimum useful ntsrefresh
Miroslav Lichvar [Thu, 2 Feb 2023 13:43:19 +0000 (14:43 +0100)] 
doc: describe minimum useful ntsrefresh

2 years agosourcestats: don't fudge refclock LastRx in sources report
Miroslav Lichvar [Thu, 2 Feb 2023 10:12:31 +0000 (11:12 +0100)] 
sourcestats: don't fudge refclock LastRx in sources report

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.

2 years agosources: warn about detected falsetickers
Miroslav Lichvar [Thu, 26 Jan 2023 15:21:11 +0000 (16:21 +0100)] 
sources: warn about detected falsetickers

Log a warning message for each detected falseticker, but only once
between changes in the selection of the best source. Don't print all
sources when no majority is reached as that case has its own warning
message.

2 years agosources: enable no majority message before first selection
Miroslav Lichvar [Thu, 26 Jan 2023 15:12:26 +0000 (16:12 +0100)] 
sources: enable no majority message before first selection

Add a separate flag to allow the "no majority" message to be logged even
before the first successful selection.

2 years agosources: increase log level of no majority message
Miroslav Lichvar [Thu, 26 Jan 2023 15:05:57 +0000 (16:05 +0100)] 
sources: increase log level of no majority message

When the selection fails due to no majority, log the message as a
warning to get the admin's attention.

2 years agodoc: add missing description of selection log field
Miroslav Lichvar [Thu, 26 Jan 2023 11:03:48 +0000 (12:03 +0100)] 
doc: add missing description of selection log field

2 years agoexamples: add AES keys to chrony.keys.example
Miroslav Lichvar [Wed, 25 Jan 2023 14:58:37 +0000 (15:58 +0100)] 
examples: add AES keys to chrony.keys.example

2 years agoconf: warn if not having read-only access to keys
Miroslav Lichvar [Wed, 25 Jan 2023 13:29:06 +0000 (14:29 +0100)] 
conf: warn if not having read-only access to keys

After dropping root privileges, log a warning message if chronyd
doesn't have read access or has (unnecessary) write access to the
files containing symmetric and server NTS keys.

2 years agokeys+nts: warn if loading world-readable/writable key
Miroslav Lichvar [Thu, 19 Jan 2023 15:09:40 +0000 (16:09 +0100)] 
keys+nts: warn if loading world-readable/writable key

Log a warning message if the file specified by the keyfile or
ntsserverkey directive is world-readable or writable, which is likely
an insecure misconfiguration. There is no check of directories
containing the file.

2 years agorefclock: fix preprocessor conditional
Miroslav Lichvar [Thu, 19 Jan 2023 10:34:55 +0000 (11:34 +0100)] 
refclock: fix preprocessor conditional

Split the new SOCK conditional using __GLIBC_PREREQ macro (which has
arguments) to fix compilation when it is not defined.

Fix also debug message using sizeof(time_t) in case it's enabled on
64-bit systems.

Reported-by: Bryan Christianson <bryan@whatroute.net>
Fixes: badaa83c319a ("refclock: convert mismatched timeval in SOCK messages")
2 years agorefclock: convert mismatched timeval in SOCK messages
Miroslav Lichvar [Wed, 18 Jan 2023 15:14:10 +0000 (16:14 +0100)] 
refclock: convert mismatched timeval in SOCK messages

On 32-bit glibc-based (>=2.34) systems, allow the SOCK client to send
messages with timevals using the other time_t size than chrony. If the
length of the received message corresponds to the other size, convert
the timeval and move the rest of the message before its processing.

This is needed for compatibility with the current development version of
gpsd, which forces 64-bit time_t on these systems, while chrony needs to
be compiled with the same time_t as gnutls.

2 years agodoc: deprecate SHM refclocks in favor of SOCK
Miroslav Lichvar [Thu, 12 Jan 2023 14:23:21 +0000 (15:23 +0100)] 
doc: deprecate SHM refclocks in favor of SOCK

The NTP SHM refclock protocol has the following properties:

- the memory segments have a predictable key (first segment 0x4e545030)
- it's expected to work in any order of starting chronyd and the program
  providing samples to chronyd, i.e. both the consumer and producer need
  to be able to create the segment
- the producer and consumer generally don't know under which user is
  the other side running (e.g. gpsd can create the segment as root and
  also as nobody after it drops root privileges)
- there is no authentication of data provided via SHM
- there is no way to restart the protocol

This makes it difficult for chronyd to ensure it is receiving
measurements from the process that the admin expects it to and not some
other process that managed to create the segment before it was started.
It's up to the admin to configure the system so that chronyd or the
producer is started before untrusted applications or users can create
the segment, or at least verify at some point later that the segment was
created with the expected owner and permissions.

There doesn't seem to be a backward-compatible fix of the protocol. Even
if one side could detect the segment had a wrong owner or permissions,
it wouldn't be able to tell the other side to reattach after recreating
the segment with the expected owner and permissions, if it still had the
permissions to do that.

The protocol would need to specify which side is responsible for
creating the segment and the start order would need to strictly follow
that.

As gpsd (likely the most common refclock source for chronyd) now
supports in the latest version SOCK even for message-based timing,
update the man page and FAQ to deprecate SHM in favor of SOCK.

2 years agoexamples: add chronyd-restricted.service
Miroslav Lichvar [Tue, 10 Jan 2023 14:02:49 +0000 (15:02 +0100)] 
examples: add chronyd-restricted.service

This is a more restricted version of the chronyd service intended for
minimal NTP/NTS client configurations. The daemon is started without
root privileges and is allowed to write only to its own runtime, state,
and log directories. It cannot bind to privileged ports in order to
operate as an NTP server, or provide monitoring access over IPv4/IPv6.
It cannot use reference clocks, HW timestamping, RTC tracking, and other
features.

2 years agocmdmon+client: add selectopts command
Miroslav Lichvar [Wed, 14 Dec 2022 15:04:43 +0000 (16:04 +0100)] 
cmdmon+client: add selectopts command

This command uses the new source function to modify configured selection
options of an NTP source or reference clock.

2 years agocmdmon+client: split out conversion of selection options
Miroslav Lichvar [Wed, 14 Dec 2022 14:28:52 +0000 (15:28 +0100)] 
cmdmon+client: split out conversion of selection options

This will be shared with new command modifying the selection options.

2 years agosources: add function to modify selection options
Miroslav Lichvar [Wed, 14 Dec 2022 14:15:41 +0000 (15:15 +0100)] 
sources: add function to modify selection options

Add a function to add new selection options or remove existing options
specified in the configuration for both NTP sources and reference
clocks.

Provide a pair of IP address and reference ID to identify the source
depending on the type. Find the source directly in the array of sources
instead of going through the NSR hashtable for NTP sources to not
complicate it unnecessarily.

2 years agosources: add assertion for instance index
Miroslav Lichvar [Wed, 14 Dec 2022 13:57:42 +0000 (14:57 +0100)] 
sources: add assertion for instance index

2 years agocmdparse: add functions for parsing refclock refid and select options
Miroslav Lichvar [Tue, 6 Dec 2022 15:33:03 +0000 (16:33 +0100)] 
cmdparse: add functions for parsing refclock refid and select options

This will be used in new chronyc command working on refclocks.

2 years agontp: update comment about minimum request spacing
Miroslav Lichvar [Mon, 5 Dec 2022 15:44:38 +0000 (16:44 +0100)] 
ntp: update comment about minimum request spacing

2 years agolog more changes made by chronyc commands
Miroslav Lichvar [Thu, 1 Dec 2022 13:43:45 +0000 (14:43 +0100)] 
log more changes made by chronyc commands

Log important changes from chronyc for auditing purposes.

Add log messages for:
- loaded symmetric keys and server NTS keys (logged also on start)
- modified maxupdateskew and makestep
- enabled/disabled local reference mode (logged also on start)
- reset time smoothing (logged also on clock steps)
- reset sources

2 years agontp: set DSCP for IPv6
Mike Ryan [Wed, 16 Nov 2022 14:13:09 +0000 (09:13 -0500)] 
ntp: set DSCP for IPv6

Chrony's dscp setting currently applies to IPv4 only. This patch sets
the necessary option for IPv6 as well.

2 years agontp+cmdmon: log allow/deny commands
Miroslav Lichvar [Wed, 16 Nov 2022 14:59:49 +0000 (15:59 +0100)] 
ntp+cmdmon: log allow/deny commands

Log added NTP and command access restrictions, using INFO severity if
from a chronyc command, DEBUG otherwise (i.e. from the config).

2 years agoutil: add function for printing access subnets
Miroslav Lichvar [Wed, 16 Nov 2022 14:57:46 +0000 (15:57 +0100)] 
util: add function for printing access subnets

2 years agontp: log added and removed sources
Miroslav Lichvar [Tue, 15 Nov 2022 15:38:50 +0000 (16:38 +0100)] 
ntp: log added and removed sources

Log a message when a single NTP source or pool of sources is added or
removed. Use the INFO severity if it's a result of a chronyc command or
(re)load of sourcefiles (which are assumed to change over time), and
DEBUG for other contexts, e.g. sources loaded from the config, sources
removed when pruning pools after reaching maxsources, and other parts of
normal operation.

2 years agologging: support context-specific severity
Miroslav Lichvar [Tue, 15 Nov 2022 14:05:36 +0000 (15:05 +0100)] 
logging: support context-specific severity

Allow messages to have severity set to INFO or DEBUG depending on the
context in which they are made to allow logging important changes made
from chronyc or sourcefile, but not spam the system log if those changes
are normally expected (e.g. specified in the config).

2 years agogetdate: fix various warnings which will be errors with clang-16
Holger Hoffstätte [Wed, 9 Nov 2022 08:17:14 +0000 (09:17 +0100)] 
getdate: fix various warnings which will be errors with clang-16

These were found by Gentoo's QA while rebuilding the world with
clang-16: https://bugs.gentoo.org/880519

Signed-off-by: Holger Hoffstätte <holger@applied-asynchrony.com>
2 years agonts: warn if server started without ntsdumpdir
Miroslav Lichvar [Mon, 24 Oct 2022 14:14:35 +0000 (16:14 +0200)] 
nts: warn if server started without ntsdumpdir

If an NTS server is configured without ntsdumpdir, keys will not be
saved and reloaded after restart, which will cause existing cookies
to be invalidated and can cause a short-term denial of service if
the server has so many clients that it cannot handle them all
making an NTS-KE session within one polling interval.

Log a warning message if a server key+certificate is specified without
ntsdumpdir.

2 years agonts: fix number of extension fields after failed encryption
Miroslav Lichvar [Wed, 19 Oct 2022 12:57:16 +0000 (14:57 +0200)] 
nts: fix number of extension fields after failed encryption

If the authenticator SIV encryption fails (e.g. due to wrong nonce
length), decrement the number of extension fields to keep the packet
info consistent.

2 years agonts: change ntskeys format to support different algorithms
Miroslav Lichvar [Thu, 13 Oct 2022 13:35:53 +0000 (15:35 +0200)] 
nts: change ntskeys format to support different algorithms

Specify the AEAD ID for each key saved in the ntskeys file instead of
one ID for all keys. Keep support for loading files in the old format.

This will allow servers to save their keys after upgrading to a new
version with AES-128-GCM-SIV support before the loaded AES-SIV-CMAC-256
keys are rotated out.

If an unsupported key is found, don't load any keys. Also, change the
severity of the error message from debug to error.

2 years agonts: add support for encrypting cookies with AES-128-GCM-SIV
Miroslav Lichvar [Wed, 12 Oct 2022 14:46:56 +0000 (16:46 +0200)] 
nts: add support for encrypting cookies with AES-128-GCM-SIV

If AES-128-GCM-SIV is available on the server, use it for encryption of
cookies. This makes them shorter by 4 bytes due to shorter nonce and it
might also improve the server performance.

After server upgrade and restart with ntsdumpdir, the switch will happen
on the second rotation of the server key. Clients should accept shorter
cookies without restarting NTS-KE. The first response will have extra
padding in the authenticator field to make the length symmetric.