]> git.ipfire.org Git - thirdparty/chrony.git/log
thirdparty/chrony.git
2 days agoutil: warn if UTI_OpenFile() is stuck in a loop master
Miroslav Lichvar [Wed, 2 Jul 2025 13:34:03 +0000 (15:34 +0200)] 
util: warn if UTI_OpenFile() is stuck in a loop

When UTI_OpenFile() is removing an existing file to be replaced by a new
file, it could potentially get stuck in an infinite loop if something
was able to consistently win the race and create a new file before
chronyd.

Log a warning message after 100 failed attempts and repeat on each 10x
increase to make it more obvious to the admin, if it ever happens.

Reported-by: Eric Sesterhenn <eric.sesterhenn@x41-dsec.de>
2 days agokeys: remove misleading memset()
Miroslav Lichvar [Wed, 2 Jul 2025 09:16:36 +0000 (11:16 +0200)] 
keys: remove misleading memset()

After (re)loading symmetric NTP keys from the key file, there is an
attempt to erase the strings from the stack by calling memset() on the
buffer. However, compilers are free (and have been shown to do) optimize
this call out.

Remove the memset() call to not pretend the stack cannot not contain any
sensitive information. There is no such attempt made for the server and
client NTS keys.

Reported-by: Eric Sesterhenn <eric.sesterhenn@x41-dsec.de>
2 days agoleapdb: fix ordered comparison against NULL pointer
Ahmad Fatoum [Fri, 27 Jun 2025 11:58:35 +0000 (13:58 +0200)] 
leapdb: fix ordered comparison against NULL pointer

fgets returns either a valid pointer with the same value as its first
argument or NULL on error or EOF.

GCC 12.2.0 -Wextra warns against relational comparison of the return
value:

  leapdb.c:127:38: warning: ordered comparison of pointer with integer zero [-Wextra]

For clarity, and because the C standard doesn't mandate that valid pointers
have to compare greater than the null pointer constant, replace the
relational expression with an equality expression

8 days agotls: move gnutls code into tls_gnutls.c
Anthony Brandon [Fri, 30 May 2025 14:47:21 +0000 (16:47 +0200)] 
tls: move gnutls code into tls_gnutls.c

Currently nts_ke_session.c directly calls into gnutls.
This patch moves the calls to gnutls into tls_gnutls.c with an API
defined in tls.h. This way it becomes possible to use different TLS
implementations in future patches.

Signed-off-by: Anthony Brandon <anthony@amarulasolutions.com>
10 days agosys_linux: drop support for kernels before 2.6.39
Miroslav Lichvar [Tue, 24 Jun 2025 12:55:02 +0000 (14:55 +0200)] 
sys_linux: drop support for kernels before 2.6.39

Linux 2.6.39 was released in 2011.

Refuse to start if a kernel version before 2.6.39 is detected. Assume
the ADJ_SETOFFSET adjtimex mode is always supported. Its verification
briefly reset the timex maxerror value to 0, which possibly confused
applications checking the value at that moment.

Drop the unneeded workaround for slow frequency updates in versions
2.6.27-2.6.32.

3 weeks agodoc: update NEWS 4.7
Miroslav Lichvar [Wed, 11 Jun 2025 07:52:10 +0000 (09:52 +0200)] 
doc: update NEWS

3 weeks agoupdate copyright years
Miroslav Lichvar [Tue, 10 Jun 2025 11:26:24 +0000 (13:26 +0200)] 
update copyright years

3 weeks agoexamples: improve chrony.conf examples
Miroslav Lichvar [Wed, 11 Jun 2025 12:53:47 +0000 (14:53 +0200)] 
examples: improve chrony.conf examples

Add a note that three servers is the generally recommended minimum for
an NTP client to be able to detect a falseticker. Mention that the pool
directive uses four servers. Update the links to the pool join page and
list of public servers.

3 weeks agorefclock_rtc: fix finalization with closed descriptor
Miroslav Lichvar [Wed, 11 Jun 2025 11:30:57 +0000 (13:30 +0200)] 
refclock_rtc: fix finalization with closed descriptor

If the RTC file descriptor was closed and removed after a read error,
don't try to close and remove it again in the driver finalization to
avoid an assertion failure on the negative descriptor.

Fixes: 4f22883f4e71 ("refclock: add new refclock for RTCs")
3 weeks agologging: don't close stderr in finalization
Miroslav Lichvar [Wed, 11 Jun 2025 07:03:48 +0000 (09:03 +0200)] 
logging: don't close stderr in finalization

When logging to stderr, don't close it in finalization in case something
else still wanted to write to it. Leave it as it is together with stdin
and stdout.

3 weeks agotest: extend 110-chronyc test
Miroslav Lichvar [Mon, 9 Jun 2025 10:08:57 +0000 (12:08 +0200)] 
test: extend 110-chronyc test

3 weeks agotest: extend 009-sourceselection test
Miroslav Lichvar [Mon, 9 Jun 2025 10:07:50 +0000 (12:07 +0200)] 
test: extend 009-sourceselection test

4 weeks agotest: include disabled cmdmon in 003-sanitizers
Miroslav Lichvar [Thu, 5 Jun 2025 11:32:10 +0000 (13:32 +0200)] 
test: include disabled cmdmon in 003-sanitizers

4 weeks agotest: fix 015-ipv6 test to skip when IPv6 is disabled
Miroslav Lichvar [Thu, 5 Jun 2025 11:28:58 +0000 (13:28 +0200)] 
test: fix 015-ipv6 test to skip when IPv6 is disabled

4 weeks agotest: fix tests for disabled cmdmon
Miroslav Lichvar [Tue, 3 Jun 2025 13:40:35 +0000 (15:40 +0200)] 
test: fix tests for disabled cmdmon

4 weeks agotest: add 149-sourcedir test
Miroslav Lichvar [Tue, 3 Jun 2025 08:58:00 +0000 (10:58 +0200)] 
test: add 149-sourcedir test

4 weeks agoconf: fix sourcedir reloading to not multiply sources
Miroslav Lichvar [Mon, 2 Jun 2025 08:53:47 +0000 (10:53 +0200)] 
conf: fix sourcedir reloading to not multiply sources

The sourcedir reload triggered by the chronyc "reload sources"
command incorrectly assumed that NSR_AddSourceByName() can return
only the NSR_Success status when a source is added. It ignored the
NSR_UnresolvedName status returned for a source whose name needs to
be resolved after the call (i.e. not specified with an IP address)
and added the source again, effectively multiplying it if the name
can be resolved to a different IP address.

Fix the code to check for the NSR_UnresolvedName status to correctly
determine whether the source was already added before and should not be
added again.

Reported-by: MichaelR <MichaelR42@runbox.com>
Fixes: 916ed70c4a81 ("conf: save source status in sourcedir reload")
5 weeks agodoc: mention RFC on interleaved modes
Miroslav Lichvar [Mon, 26 May 2025 06:43:44 +0000 (08:43 +0200)] 
doc: mention RFC on interleaved modes

The specification of the interleaved modes is now published as
RFC 9769.

5 weeks agotest: make 007-cmdmon test more reliable
Miroslav Lichvar [Mon, 26 May 2025 14:33:31 +0000 (16:33 +0200)] 
test: make 007-cmdmon test more reliable

5 weeks agotest: add RTC test to 106-refclock
Miroslav Lichvar [Mon, 26 May 2025 14:32:29 +0000 (16:32 +0200)] 
test: add RTC test to 106-refclock

5 weeks agotest: fix IPv6 test in 139-nts
Miroslav Lichvar [Thu, 22 May 2025 10:55:20 +0000 (12:55 +0200)] 
test: fix IPv6 test in 139-nts

Make sure an IPv6 address is actually used and don't forget to remove
the measurements log to not interfere with the subsequent test.

5 weeks agosched: don't define FD_SETSIZE
Miroslav Lichvar [Thu, 22 May 2025 12:56:57 +0000 (14:56 +0200)] 
sched: don't define FD_SETSIZE

Don't make any assumptions about fd_set size if FD_SETSIZE is missing.
POSIX requires the macro to be defined.

6 weeks agomain: improve error message about failed notification
Miroslav Lichvar [Thu, 22 May 2025 07:17:42 +0000 (09:17 +0200)] 
main: improve error message about failed notification

Mention the NOTIFY_SOCKET variable to make it more obvious what is
preventing chronyd from starting in case it's unexpectedly inherited in
a chroot etc.

6 weeks agodoc: fix typo in chronyc man page
Vincent Blut [Wed, 21 May 2025 17:44:39 +0000 (19:44 +0200)] 
doc: fix typo in chronyc man page

6 weeks agodoc: update NEWS 4.7-pre1
Miroslav Lichvar [Wed, 21 May 2025 10:04:00 +0000 (12:04 +0200)] 
doc: update NEWS

6 weeks agodoc: update README
Miroslav Lichvar [Wed, 21 May 2025 08:06:52 +0000 (10:06 +0200)] 
doc: update README

6 weeks agogetdate+nts+rtc: avoid some coverity false positives
Miroslav Lichvar [Wed, 21 May 2025 06:43:12 +0000 (08:43 +0200)] 
getdate+nts+rtc: avoid some coverity false positives

Modify the code to avoid making the following calls incorrectly reported
as important findings by the coverity static analyzer:

- memset() of size 0 at the end of an array
- mktime() on a struct tm that has uninitialized tm_yday

6 weeks agosocket: drop messages from unterminated Unix paths
Miroslav Lichvar [Tue, 20 May 2025 14:02:09 +0000 (16:02 +0200)] 
socket: drop messages from unterminated Unix paths

On some systems (e.g. FreeBSD) the source Unix domain socket path
provided by recvmsg() as msg_name is not always null-terminated even if
more space than required for sockaddr_un is provided due to the padding
in the sockaddr_all union, and the returned msg_namelen value does not
indicate it is missing the termination. If a cmdmon client bound its
socket to a maximum-length path (chronyc doesn't allow that), the path
would be overread when printing a debug message and trying to send a
response.

Drop messages from paths not shorter than sun_path to avoid working with
un-printf()able and/or unreachable addresses. The clients are expected
to not use the maximum-length paths.

6 weeks agolocal+reference: fix tracking offset after failed step
Miroslav Lichvar [Tue, 20 May 2025 05:59:38 +0000 (07:59 +0200)] 
local+reference: fix tracking offset after failed step

If a clock step enabled by the makestep directive or requested by the
makestep command fails, accumulate the missing step back to keep the
tracking offset valid.

This fixes time served by an instance configured with the makestep
directive and the -x option (the null driver cannot perform steps) at
the same time. It will still generate error log messages.

6 weeks agodoc: warn about makestep not working with -x option
Miroslav Lichvar [Tue, 20 May 2025 06:24:43 +0000 (08:24 +0200)] 
doc: warn about makestep not working with -x option

6 weeks agodoc: specify maximum accepted value of ntsprocesses
Miroslav Lichvar [Mon, 19 May 2025 14:39:55 +0000 (16:39 +0200)] 
doc: specify maximum accepted value of ntsprocesses

6 weeks agoconf+cmdparse: parenthesize all macro arguments
Miroslav Lichvar [Mon, 19 May 2025 12:33:39 +0000 (14:33 +0200)] 
conf+cmdparse: parenthesize all macro arguments

6 weeks agodoc: improve description of server directive
Miroslav Lichvar [Mon, 19 May 2025 10:46:44 +0000 (12:46 +0200)] 
doc: improve description of server directive

7 weeks agoexamples: fix unset OPTIONS variable warning in systemd services
Andreas Fenkart [Mon, 12 May 2025 08:32:57 +0000 (10:32 +0200)] 
examples: fix unset OPTIONS variable warning in systemd services

Modify chronyd.service to handle cases where OPTIONS is undefined,
which occurs when /etc/sysconfig/chronyd doesn't exist or doesn't set
the variable. This prevents the warning:

 "chronyd.service: Referenced but unset environment variable
  evaluates to an empty string: OPTIONS"

7 weeks agoconfigure: check for nettle_memeql_sec()
Miroslav Lichvar [Mon, 5 May 2025 12:17:26 +0000 (14:17 +0200)] 
configure: check for nettle_memeql_sec()

This fixes build with nettle versions before 3.3.

8 weeks agosocket: fix compiler warning on macOS
Miroslav Lichvar [Mon, 5 May 2025 10:09:22 +0000 (12:09 +0200)] 
socket: fix compiler warning on macOS

Disable get_default_inet_domain() together with check_socket_flag() to
avoid a warning about unused function.

Reported-by: Bryan Christianson <bryan@whatroute.net>
8 weeks agotest: fix 110-chronyc for disabled SW timestamping
Miroslav Lichvar [Mon, 5 May 2025 09:19:33 +0000 (11:19 +0200)] 
test: fix 110-chronyc for disabled SW timestamping

8 weeks agorefclock_phc: support ethernet ifname as specifier
Shachar Raindel [Wed, 23 Apr 2025 20:46:44 +0000 (13:46 -0700)] 
refclock_phc: support ethernet ifname as specifier

This commit allows the user to select a PHC refclock associated with
an Ethernet interface by specifying the interface name. This allows
the user to handle situations where multiple NICs are exposing PHC
devices (or non-NIC PHC device files exist in the system) in a more
streamline manner.

2 months agotest: add IPv6 simulation tests
Miroslav Lichvar [Wed, 30 Apr 2025 09:50:15 +0000 (11:50 +0200)] 
test: add IPv6 simulation tests

2 months agosocket: open IPv6 socket by default if IPv4 is disabled
Miroslav Lichvar [Wed, 30 Apr 2025 09:33:38 +0000 (11:33 +0200)] 
socket: open IPv6 socket by default if IPv4 is disabled

When no remote and local address is specified, and IPv4 is disabled by
the -6 option, open an IPv6 socket. This is used by the Linux-specific
timestamping configuration and socket option checking. It enables
operation on a system that has no support for IPv4 sockets.

2 months agodoc: diverse fixes
Paul Donald [Fri, 25 Apr 2025 16:43:05 +0000 (18:43 +0200)] 
doc: diverse fixes

2 months agodoc: un-split infinitives
Paul Donald [Fri, 25 Apr 2025 15:55:02 +0000 (17:55 +0200)] 
doc: un-split infinitives

2 months agodoc: fix should word order
Paul Donald [Fri, 25 Apr 2025 00:18:49 +0000 (02:18 +0200)] 
doc: fix should word order

2 months agodoc: improve the usage of however
Paul Donald [Fri, 25 Apr 2025 00:18:43 +0000 (02:18 +0200)] 
doc: improve the usage of however

However at the start means "in whatever way"/"to whatever extent".
("However chrony is configured, it won't let you in without allow")
However incorrectly at the start usually means "But" was intended.

2 months agodoc: improve description of logbanner
Paul Donald [Fri, 25 Apr 2025 00:18:32 +0000 (02:18 +0200)] 
doc: improve description of logbanner

3 months agosys_timex: detect clock interference from other processes
Miroslav Lichvar [Thu, 3 Apr 2025 13:50:29 +0000 (15:50 +0200)] 
sys_timex: detect clock interference from other processes

After an ntp_adjtime()/adjtimex() call, check if the frequency, PLL time
constant and PLL status are as expected from the previous call. If they
changed, log a warning message to indicate that another NTP client might
be running on the system and interfering with the system clock.

3 months agokeys: compare MACs in constant time
Miroslav Lichvar [Wed, 2 Apr 2025 13:34:43 +0000 (15:34 +0200)] 
keys: compare MACs in constant time

Switch from memcmp() to the new constant-time function to compare the
received and expected authentication data generated with a symmetric key
(NTP MAC or AES CMAC).

While this doesn't seem to be strictly necessary with the current
code, it is a recommended practice to prevent timing attacks. If
memcmp() compared the MACs one byte at a time (a typical memcmp()
implementation works with wider integers for better performance) and
chronyd as an NTP client/server/peer was leaking the timing of the
comparison (e.g. in the monitoring protocol), an attacker might be able
for a given NTP request or response find in a sequence the individual
bytes of the MAC by observing differences in the timing over a large
number of attempts. However, this process would likely be so slow the
authenticated request or response would not be useful in a MITM attack
as the expected origin timestamp is changing with each poll.

Extend the keys unit test to compare the time the function takes to
compare two identical MACs and MACs differing in the first byte
(maximizing the timing difference). It should fail if the compiler's
optimizations figure out the function can return early. The test is not
included in the util unit test to avoid compile-time optimizations with
the function and its caller together. The test can be disabled by
setting NO_TIMING_TESTS environment variable if it turns out to be
unreliable.

3 months agoutil: add function for constant-time memory comparison
Miroslav Lichvar [Wed, 2 Apr 2025 13:32:05 +0000 (15:32 +0200)] 
util: add function for constant-time memory comparison

Add a function to check if two buffers of the same length contain the
same data, but do the comparison in a constant time with respect to the
returned value to avoid creating a timing side channel, i.e. the time
depends only on the buffer length, not on the content.

Use the gnutls_memcmp() or nettle_memeql_sec() functions if available,
otherwise use the same algorithm as nettle - bitwise ORing XORed data.

3 months agologging: try to reopen message log on cyclelogs command
Miroslav Lichvar [Thu, 20 Mar 2025 11:57:37 +0000 (12:57 +0100)] 
logging: try to reopen message log on cyclelogs command

When the cyclelogs command is issued, check if the file specified by the
-l option is still in its place and if not try opening it again. If that
fails (e.g. due to chrony no longer having root privileges), keep the
old file handle to avoid losing log messages.

3 months agoconfigure: make NTP and ASYNCDNS support nonoptional
Miroslav Lichvar [Wed, 19 Mar 2025 15:11:39 +0000 (16:11 +0100)] 
configure: make NTP and ASYNCDNS support nonoptional

Don't allow the NTP support and asynchronous name resolving to be
disabled. pthreads are now a hard requirement.

NTP is the primary task of chrony. This functionality doesn't seem to be
commonly disabled (allowing only refclocks and manual input).

This removes rarely (if ever) used code and simplifies testing.

3 months agoconf: improve some error messages
Miroslav Lichvar [Thu, 20 Mar 2025 14:12:07 +0000 (15:12 +0100)] 
conf: improve some error messages

3 months agoconf+cmdparse: check sanity of configured integer values
Miroslav Lichvar [Wed, 19 Mar 2025 13:35:54 +0000 (14:35 +0100)] 
conf+cmdparse: check sanity of configured integer values

Verify that integer values specified in the configuration are sane:
interval log2 values are between -32 and 32, ports between 0 and 65535,
stratum between 0 and 16, values that should not be negative are not
negative, numbers that specify large intervals in seconds fit in the
32-bit integer, numbers don't have non-digit characters, etc.

3 months agocmdparse: add status for server and local command
Miroslav Lichvar [Wed, 19 Mar 2025 11:07:29 +0000 (12:07 +0100)] 
cmdparse: add status for server and local command

Add an enum to describe the error in the parsed directive: missing
argument, invalid option, or invalid value.

Update the error messages in conf.c and client.c.

3 months agoconf: switch other_parse_error() to variable arguments
Miroslav Lichvar [Thu, 20 Mar 2025 14:20:46 +0000 (15:20 +0100)] 
conf: switch other_parse_error() to variable arguments

3 months agoconf: change parse_null() to accept pointer for consistency
Miroslav Lichvar [Tue, 18 Mar 2025 13:58:27 +0000 (14:58 +0100)] 
conf: change parse_null() to accept pointer for consistency

3 months agoconf: don't return unused values from parse functions
Miroslav Lichvar [Tue, 18 Mar 2025 13:52:45 +0000 (14:52 +0100)] 
conf: don't return unused values from parse functions

No need to return success. These functions terminate the process on
errors.

3 months agoreference: add wait options for local reference activation
Miroslav Lichvar [Thu, 13 Mar 2025 14:00:06 +0000 (15:00 +0100)] 
reference: add wait options for local reference activation

Add "waitunsynced" option to specify how long chronyd needs to wait
before it can activate the local reference when the clock is not
synchronized to give the configured sources a chance to synchronize the
local clock after start. The default is 300 seconds when the orphan
option is enabled (same as the ntpd's default orphanwait), 0 otherwise.

Add "waitsynced" option to specify how long it should wait when the
clock is synchronized. It is an additional requirement to the distance
and activate options.

3 months agosources: increase severity of can't-synchronise log messages
Miroslav Lichvar [Thu, 13 Mar 2025 15:03:59 +0000 (16:03 +0100)] 
sources: increase severity of can't-synchronise log messages

Switch the info-level "Can't synchronise" selection messages to
warnings.

3 months agosources: improve no-selectable-sources log message
Miroslav Lichvar [Thu, 13 Mar 2025 14:55:32 +0000 (15:55 +0100)] 
sources: improve no-selectable-sources log message

Include the number of unreachable sources in the "Can't synchronise: no
selectable sources" log message to provide a hint whether it might be a
networking issue.

3 months agosources: switch unselect_selected_source() to variable arguments
Miroslav Lichvar [Thu, 13 Mar 2025 14:40:47 +0000 (15:40 +0100)] 
sources: switch unselect_selected_source() to variable arguments

Switch the function to the full printf style, which will be needed to
log an integer.

3 months agosources: delay maxjitter/maxdistance warning messages
Miroslav Lichvar [Wed, 12 Mar 2025 14:21:18 +0000 (15:21 +0100)] 
sources: delay maxjitter/maxdistance warning messages

Avoid logging the new warning messages about exceeded maxjitter or
maxdistance when only a small number of samples is collected after the
source becomes reachable and the values are unstable. Log the messages
only when a replacement attempt is made.

3 months agorewrite some assertions for better readability
Miroslav Lichvar [Wed, 5 Mar 2025 11:28:46 +0000 (12:28 +0100)] 
rewrite some assertions for better readability

Some assertions are written as "if (x) assert(0)" to avoid having
the text of a long argument compiled in the binary. Rewrite them
to use a new BRIEF_ASSERT macro to make the condition easier to read in
its non-negated form and make it easier to turn it back to the full-text
assert if needed.

3 months agosources: improve no majority log message
Miroslav Lichvar [Thu, 6 Mar 2025 11:46:09 +0000 (12:46 +0100)] 
sources: improve no majority log message

Add the number of sources that form an agreement (overlapping
intervals), if at least two agree with each other, and number of
reachable sources to the "Can't synchronize: no majority" log message to
better explain why synchronization is failing and hint that adding more
sources might help.

3 months agosources: warn about sources exceeding maxdistance or maxjitter
Miroslav Lichvar [Wed, 5 Mar 2025 09:45:20 +0000 (10:45 +0100)] 
sources: warn about sources exceeding maxdistance or maxjitter

Log a warning message if a source is rejected in the source selecting
due to exceeding the maxdistance or maxjitter limit to make it more
obvious when synchronization is failing for this reason. Delay the
message until the reachability register is full (8 updates), or a
replacement of the source is attempted.

3 months agosources: refactor logging of source-specific selection status
Miroslav Lichvar [Mon, 3 Mar 2025 14:48:37 +0000 (15:48 +0100)] 
sources: refactor logging of source-specific selection status

Move logging of falsetickers and system peers to the mark_source()
function. Use an array to flag already logged messages in preparation
for logging of other status. Support variable number of arguments in the
logging functions.

3 months agoprivops: mark res_fatal() for printf format compiler check
Miroslav Lichvar [Wed, 5 Mar 2025 09:44:04 +0000 (10:44 +0100)] 
privops: mark res_fatal() for printf format compiler check

3 months agodoc: improve description of refresh directive
Miroslav Lichvar [Thu, 27 Feb 2025 09:04:41 +0000 (10:04 +0100)] 
doc: improve description of refresh directive

4 months agoclient: fix memory leak of empty readline() string
Miroslav Lichvar [Wed, 12 Feb 2025 12:22:04 +0000 (13:22 +0100)] 
client: fix memory leak of empty readline() string

4 months agodoc: mention localhost exception in cmdallow description
Miroslav Lichvar [Tue, 11 Feb 2025 15:25:05 +0000 (16:25 +0100)] 
doc: mention localhost exception in cmdallow description

4 months agocmdmon: make open commands configurable
Miroslav Lichvar [Tue, 11 Feb 2025 11:27:23 +0000 (12:27 +0100)] 
cmdmon: make open commands configurable

Replace the hardcoded list of open commands (accessible over UDP),
with a list that can be configured with a new "opencommands" directive.
The default matches the original list. All read-only commands except
accheck and cmdaccheck can be enabled. The naming follows the chronyc
naming. Enable the N_SOURCES request only when needed.

This makes it possible to have a full monitoring access without access
to the Unix domain socket. It also allows restricting the monitoring
access to a smaller number of commands if some commands from the default
list are not needed.

Mention in the man page that the protocol of the non-default commands is
not consider stable and the information they provide may have security
implications.

4 months agocmdmon: refactor command authorization checks
Miroslav Lichvar [Mon, 10 Feb 2025 14:32:26 +0000 (15:32 +0100)] 
cmdmon: refactor command authorization checks

Try to simplify the code and make it more robust to potential bugs.

Instead of maintaing a table mapping all commands to open/auth
permissions, use a short list of open commands. Split the processing
of the commands into two groups, read-write commands and read-only
(monitoring) commands, where the first group is processed only with full
access. Check both the socket descriptor and address type before giving
full access. While moving the code, reorder the commands alphabetically.

4 months agocmdmon: drop handling of NULL and LOGON requests
Miroslav Lichvar [Mon, 10 Feb 2025 14:08:03 +0000 (15:08 +0100)] 
cmdmon: drop handling of NULL and LOGON requests

Handle the NULL and LOGON requests as unknown (invalid) instead of
returning the success and failed status respectively. They have
been unused for very long time now.

4 months agosocket: rework setting of struct sockaddr_un
Miroslav Lichvar [Wed, 5 Feb 2025 14:20:41 +0000 (15:20 +0100)] 
socket: rework setting of struct sockaddr_un

Add a function to fill the Unix sockaddr for binding, connecting and
sending to avoid code duplication. Use memcpy() instead of snprintf()
and provide the minimum length of the address containing the terminating
null byte. This makes it easier to support abstract sockets if needed in
future (e.g. for systemd support).

4 months agomain: add support for systemd notification
Miroslav Lichvar [Wed, 5 Feb 2025 08:30:46 +0000 (09:30 +0100)] 
main: add support for systemd notification

On Linux, if the NOTIFY_SOCKET variable is set, send a "READY=1"
and "STOPPING=1" message to the Unix domain socket after initialization
and before finalization respectively. This is used with the systemd
"notify" service type as documented in the sd_notity(3) man page. It's
a recommended alternative to the "forking" service type, which does not
need the PID file to determine the main process.

Support pathname Unix sockets only. Abstract sockets don't seem to be
used by systemd for notifications since version 212.

Switch the example services to the notify type, but keep the PID
file. It's still useful to prevent start of other chronyd instances.
systemd doesn't seem to care about the content of the file and should
just remove it in case chronyd didn't terminate cleanly.

Suggested-by: Luca Boccassi <bluca@debian.org>
6 months agorefclock: drop filter length adjustment for polling drivers
Miroslav Lichvar [Wed, 11 Dec 2024 10:16:30 +0000 (11:16 +0100)] 
refclock: drop filter length adjustment for polling drivers

In the refclock initialization, if the driver provides a poll()
function and 2^(poll-dpoll) is smaller than the configured length of the
median filter (64 by default), the filter is shortened to 2^(poll-dpoll)
samples, assuming the driver provides samples only in the poll()
function and at most one per call, to avoid wasting memory and before
commit 12237bf28393 ("refclock: stop requiring 4 samples in median
filter") also simplify configuration (for polling drivers only)

But this assumption is not always correct. The PHC driver can read
external PPS timestamps independently from the driver polling and the
RTC driver can timestamp interrupts. If the dpoll was too large to cover
the sample rate, some samples would be lost.

Drop the adjustment of the filter length to avoid this unexpected impact
on filtering and make it work as documented.

6 months agorefclock: fix build on non-Linux systems
Bryan Christianson [Tue, 10 Dec 2024 09:14:43 +0000 (10:14 +0100)] 
refclock: fix build on non-Linux systems

Fixes: 5fd71e27831f ("refclock: add new refclock for RTCs")
6 months agorefclock: add new refclock for RTCs
Uwe Kleine-König [Wed, 30 Jun 2021 14:47:21 +0000 (16:47 +0200)] 
refclock: add new refclock for RTCs

This refclock uses an RTC as reference source. If the RTC doesn't
support reporting an update event this source is quite coarse as it
usually needs a slow bus access to be read and has a precision of only
one second. If reporting an update event is available, the time is read
just after such an event which improves precision.

Depending on hardware capabilities you might want to combine it with a
PPS reference clock sourced from the same chip.

Note that you can enable UIE emulation in the Linux kernel to make a RTC
without interrupt support look like one with irqs in return for some
system and bus overhead.

Co-authored-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
6 months agortc: optionally return raw time from RTC_Linux_ReadTime*
Ahmad Fatoum [Mon, 22 Jul 2024 15:41:47 +0000 (17:41 +0200)] 
rtc: optionally return raw time from RTC_Linux_ReadTime*

For use with RCL_AddSample in the incoming RTC reference clock driver,
we'll want access not to the cooked timestamps, but to the raw ones.

Otherwise, the core reference clock code complains:

  (valid_sample_time) RTC0 refclock sample time 1721242673.092211891
    not valid age=-3.092007

Support both use cases by have the RTC_Linux_ReadTime_* functions take
two nullable pointers, one for cooked and the other for raw time.

6 months agortc: factor out RTC_Linux_ReadTimeNow
Ahmad Fatoum [Mon, 22 Jul 2024 15:46:44 +0000 (17:46 +0200)] 
rtc: factor out RTC_Linux_ReadTimeNow

We have code to read RTC time and handle the error associated with
having no UIE interrupt, which we currently use as part of maintaining
the correction file.

In a later commit, we will need the same functionality for using the RTC
as reference clock, so export the function and give it a descriptive
name appropriate for a globally visible function.

6 months agortc: factor out RTC_Linux_ReadTimeAfterInterrupt
Ahmad Fatoum [Wed, 17 Jul 2024 11:00:39 +0000 (13:00 +0200)] 
rtc: factor out RTC_Linux_ReadTimeAfterInterrupt

We have code to read time after an RTC's UIE interrupt, which we
currently use as part of maintaining the correction file.

In a later commit, we will need the same functionality for using the RTC
as reference clock, so export the function and give it a descriptive
name appropriate for a globally visible function.

6 months agortc: export RTC_Linux_{SwitchInterrupt,CheckInterrupt}
Ahmad Fatoum [Mon, 15 Jul 2024 20:23:09 +0000 (22:23 +0200)] 
rtc: export RTC_Linux_{SwitchInterrupt,CheckInterrupt}

We have code to enable and disable the RTC's UIE interrupt, as well as
check whether it occurred and skip the first interrupt as it may be
bogus.
This is currently used as part of maintaining the correction file.

In a later commit, we will need the same functionality for using the RTC
as reference clock, so export the functions and give them descriptive
names appropriate for globally visible functions.

6 months agortc: pass info whether RTC is on UTC as a function parameter
Ahmad Fatoum [Mon, 22 Jul 2024 11:40:59 +0000 (13:40 +0200)] 
rtc: pass info whether RTC is on UTC as a function parameter

rtc_from_t() and t_from_rtc() call either gmtime or localtime depending
on the value of a global rtc_on_utc variable.

This will not be appropriate anymore when we start exporting functions
that call rtc_from_t() and t_from_rtc() for use outside of rtc_linux.c
as the rtc_on_utc variable may not have been initialized yet or at all.

Therefore make whether the RTC is on UTC a function parameter of these
functions, so the value can be propagated from the callers.

6 months agortc: let t_from_rtc/rtc_from_t operate on struct rtc_time directly
Ahmad Fatoum [Fri, 12 Jul 2024 14:12:44 +0000 (16:12 +0200)] 
rtc: let t_from_rtc/rtc_from_t operate on struct rtc_time directly

Both functions operate on struct tm even though the struct tm is only
used as intermediary format from struct rtc_time.

In the case of rtc_from_t, the code to convert from struct tm to struct
rtc is even duplicated.

Let's simplify code a bit by moving the struct translation code into
these conversion functions.

6 months agotest: pass make options in features compilation test
Miroslav Lichvar [Wed, 4 Dec 2024 11:03:57 +0000 (12:03 +0100)] 
test: pass make options in features compilation test

6 months agotest: extend socket unit test
Miroslav Lichvar [Mon, 2 Dec 2024 13:43:29 +0000 (14:43 +0100)] 
test: extend socket unit test

7 months agotest: add valgrind support to system tests
Miroslav Lichvar [Thu, 28 Nov 2024 15:05:48 +0000 (16:05 +0100)] 
test: add valgrind support to system tests

7 months agonts: close socket in helper process on exit
Miroslav Lichvar [Thu, 28 Nov 2024 13:45:23 +0000 (14:45 +0100)] 
nts: close socket in helper process on exit

Close the socket used for receiving helper requests before exit to avoid
another valgrind error.

7 months agomain: close pipe in grandparent process
Miroslav Lichvar [Thu, 28 Nov 2024 13:35:58 +0000 (14:35 +0100)] 
main: close pipe in grandparent process

Close the other end of the pipe in the grandparent process before exit
to avoid valgrind error.

Also, in the daemon process avoid closing the pipe for second time in
the 0-1024 close() loop to avoid another error.

7 months agoclient: close /dev/urandom on exit
Miroslav Lichvar [Thu, 28 Nov 2024 13:35:01 +0000 (14:35 +0100)] 
client: close /dev/urandom on exit

7 months agotest: enable valgrind fd tracking
Miroslav Lichvar [Thu, 28 Nov 2024 10:16:20 +0000 (11:16 +0100)] 
test: enable valgrind fd tracking

7 months agotest: update 106-refclock
Miroslav Lichvar [Wed, 27 Nov 2024 15:08:33 +0000 (16:08 +0100)] 
test: update 106-refclock

With the latest clknetsim all PHC readings should be valid (no
timestamps from future).

Also don't forget to remove refclock.log between tests.

7 months agoquantiles: add parameter to limit negative step
Miroslav Lichvar [Thu, 21 Nov 2024 13:30:14 +0000 (14:30 +0100)] 
quantiles: add parameter to limit negative step

Add a new parameter to limit the negative value of the step state
variable. It's set as a maximum delay in number of updates before the
actual step applied to the quantile estimate starts growing from the
minimum step when the input value is consistently larger or smaller than
the estimate.

This prevents the algorithm from effectively becoming the slower 1U
variant if the quantile estimate is stable most of the time.

Set it to 100 updates for the NTP delay and 1000 updates for the hwclock
delay. An option could be added later to make it configurable.

7 months agoquantiles: force step update with stable input values
Miroslav Lichvar [Thu, 21 Nov 2024 09:11:48 +0000 (10:11 +0100)] 
quantiles: force step update with stable input values

The algorithm was designed for estimating quantiles in streams of
integer values. When the estimate is equal to the input value, the
step state variable does not change. This causes problems for the
floating-point adaptation used for measurents of delay in chrony.

One problem is numerical instability due to the strict comparison of
the input value and the current estimate.

Another problem is with signals that are so stable that the nanosecond
resolution of the system functions becomes the limitation. There is a
large difference in the value of the step state variable, which
determines how quickly the estimate will adapt to a new distribution,
between signals that are constant in the nanosecond resolution and
signals that can move in two nanoseconds.

Change the estimate update to never consider the input value equal to
the current estimate and don't set the estimate exactly to the input
value. Keep it off by a quarter of the minimum step to force jumping
around the input value if it's constant and decreasing the step variable
to negative values. Also fix the initial adjustment to step at least by
the minimum step (the original algorithm is described with ceil(), not
fabs()).

7 months agontp+hwclock: add margin to estimated delay quantiles
Miroslav Lichvar [Mon, 18 Nov 2024 15:18:40 +0000 (16:18 +0100)] 
ntp+hwclock: add margin to estimated delay quantiles

Extend the interval of accepted delays by half of the quantile minimum
step in both directions to make room for floating-point errors in the
quantile calculation and an error that will be intentionally added in
the next commit.

7 months agoquantiles: add functions to get max k and min step
Miroslav Lichvar [Mon, 18 Nov 2024 14:54:17 +0000 (15:54 +0100)] 
quantiles: add functions to get max k and min step

7 months agoquantiles: fix assertion for requested k
Miroslav Lichvar [Mon, 18 Nov 2024 14:51:42 +0000 (15:51 +0100)] 
quantiles: fix assertion for requested k

7 months agotest: improve nts_ntp_auth test
Miroslav Lichvar [Thu, 14 Nov 2024 12:43:22 +0000 (13:43 +0100)] 
test: improve nts_ntp_auth test

7 months agotest: add 014-intermittent test
Miroslav Lichvar [Thu, 14 Nov 2024 12:41:41 +0000 (13:41 +0100)] 
test: add 014-intermittent test

7 months agotest: indicate failed sync stats
Miroslav Lichvar [Thu, 14 Nov 2024 12:40:43 +0000 (13:40 +0100)] 
test: indicate failed sync stats

7 months agotest: make system test users configurable
Miroslav Lichvar [Thu, 14 Nov 2024 09:53:35 +0000 (10:53 +0100)] 
test: make system test users configurable