]> git.ipfire.org Git - thirdparty/chrony.git/log
thirdparty/chrony.git
10 days agosourcestats: change MAX_SKEW to 1.0 master
Miroslav Lichvar [Tue, 9 Jun 2026 10:05:59 +0000 (12:05 +0200)] 
sourcestats: change MAX_SKEW to 1.0

Change the upper limit of skew from 100.0 to more reasonable 1.0.

10 days agotest: make hwclock test more reliable
Miroslav Lichvar [Tue, 9 Jun 2026 09:56:11 +0000 (11:56 +0200)] 
test: make hwclock test more reliable

10 days agoutil: fix discarded-qualifiers warning in UTI_PathToDir()
Miroslav Lichvar [Tue, 9 Jun 2026 06:41:16 +0000 (08:41 +0200)] 
util: fix discarded-qualifiers warning in UTI_PathToDir()

With new glibc strrchr() seems to return "const char *" when the input
is const, which triggers the -Wdiscarded-qualifiers warning.

10 days agolocal: limit maxdrift to 100000 ppm
Miroslav Lichvar [Mon, 8 Jun 2026 11:30:42 +0000 (13:30 +0200)] 
local: limit maxdrift to 100000 ppm

Change the maximum accepted maxdrift from 500000 ppm to 100000 ppm to
match the Linux kernel and driver. The OpenBSD kernel can work with
larger offsets of up to 50%, but that would likely not be covered well
in testing (e.g. to make sure the loop doesn't become unstable).

This change prevents the drivers from getting larger frequencies from
the local module.

10 days agoclientlog: reduce number of records per slot
Miroslav Lichvar [Mon, 8 Jun 2026 10:44:40 +0000 (12:44 +0200)] 
clientlog: reduce number of records per slot

Change the number of records per slot from 16 to 8 to reduce the maximum
number of records that need to be inspected in the linear search for an
IP address in the hash table.

This improves the server performance when the clientlog limit is too
small for the expected number of clients (e.g. the default on a public
server).

With the improved IP address hashing this shouldn't have a significant
impact on the quality of rate limiting and client monitoring.

10 days agoutil: switch UTI_IPToHash() to FNV-1a
Miroslav Lichvar [Mon, 8 Jun 2026 10:04:45 +0000 (12:04 +0200)] 
util: switch UTI_IPToHash() to FNV-1a

Use the 32-bit FNV prime and xor operation to improve the quality of
IP address hashing.

10 days agoclientlog: optimize get_record()
Miroslav Lichvar [Thu, 4 Jun 2026 14:43:13 +0000 (16:43 +0200)] 
clientlog: optimize get_record()

In the clientlog get_record() function use a simplified local version of
UTI_CompareIPs() to be inlined to minimize the overhead of searching in
the slot.

Revert commit 837323d687b9 ("clientlog: simplify code") and unroll the
first assignment in the search for the last hit to help the compiler to
produce faster code.

10 days agotest: add simple benchmark to clientlog unit test
Miroslav Lichvar [Thu, 4 Jun 2026 14:13:32 +0000 (16:13 +0200)] 
test: add simple benchmark to clientlog unit test

10 days agotest: verify loaded seccomp/pledge filter in system tests
Miroslav Lichvar [Wed, 3 Jun 2026 10:50:23 +0000 (12:50 +0200)] 
test: verify loaded seccomp/pledge filter in system tests

10 days agosys_openbsd: drop unnecessary read after setting frequency
Miroslav Lichvar [Wed, 3 Jun 2026 12:24:52 +0000 (14:24 +0200)] 
sys_openbsd: drop unnecessary read after setting frequency

In the OpenBSD set_frequency() function assume the clock frequency was
set exactly as requested instead of reading it back from the kernel.
This avoids an unnecessary privops helper call and system call.

10 days agosys_openbsd: allow late binding to privileged ports
Miroslav Lichvar [Wed, 3 Jun 2026 10:14:34 +0000 (12:14 +0200)] 
sys_openbsd: allow late binding to privileged ports

Binding UDP sockets to ports below 1024 is a privileged operation on
OpenBSD, same as on other supported systems. If chronyd was started
without any allow directives (enabling NTP server sockets) and dropped
root privileges, but some access was allowed later by chronyc, it failed
to bind its server sockets.

Enable the BINDSOCKET privops function and modify the pledge filter to
allow passing of the socket and binding it in the helper.

10 days agosys_openbsd: simplify selection of pledge promises
Miroslav Lichvar [Wed, 3 Jun 2026 09:48:35 +0000 (11:48 +0200)] 
sys_openbsd: simplify selection of pledge promises

Instead of switching between all needed combinations of promises passed
to pledge(), format the string in a buffer from parts added by
individual conditions. This will make it easier to add more conditions
and promises.

10 days agotls_gnutls: remove trailing dot for certificate verification
Miroslav Lichvar [Wed, 3 Jun 2026 09:12:27 +0000 (11:12 +0200)] 
tls_gnutls: remove trailing dot for certificate verification

Although not documented, gnutls_session_set_verify_cert() doesn't work
correctly with hostnames specified with the trailing dot (FQDN). The
verification fails. Keep an additional copy of the hostname with the dot
removed in the TLS instance for the verification.

This allows NTS sources to be specified with the trailing dot.

2 months agomain: add -N option for s6-style service readiness notification
Emery Hemingway [Thu, 9 Apr 2026 14:29:11 +0000 (14:29 +0000)] 
main: add -N option for s6-style service readiness notification

In this notification scheme a service supervisor creates a pipe
and passes the write file descriptor to chronyd. When chronyd is
initialised it writes a newline to the descriptor and the
supervisor is informed that chronyd has successfully started and
is in a ready state.

https://skarnet.org/software/s6/notifywhenup.html

3 months agoclient: fix -v option to not require argument
Miroslav Lichvar [Mon, 9 Mar 2026 07:34:16 +0000 (08:34 +0100)] 
client: fix -v option to not require argument

Reported-by: Bryan Christianson <bryan@whatroute.net>
Fixes: d622b222a9ac ("chronyc: add wider output option")
3 months agotest: finalize LOG when skipping in unit test
Miroslav Lichvar [Mon, 2 Mar 2026 11:24:40 +0000 (12:24 +0100)] 
test: finalize LOG when skipping in unit test

This fixes a leak reported by valgrind.

3 months agocmac+hash: add support for Nettle 4.0
Miroslav Lichvar [Mon, 2 Mar 2026 10:55:30 +0000 (11:55 +0100)] 
cmac+hash: add support for Nettle 4.0

Support for truncated digests was removed in Nettle 4.0. The digest
functions no longer accept the output length. Provide a full-length
buffer and copy the requested length of the digest, same as with the
other crypto providers.

3 months agochronyc: add wider output option
Thomas Kupper [Sat, 14 Feb 2026 11:24:32 +0000 (12:24 +0100)] 
chronyc: add wider output option

Add option '-w' which set the output width from 80 to 94. This allows
for all table-outputting operations to display IPv4 and IPv6 addresses
aligned with the headers.

Extend test/simulation/110-chronyc to test for the five commands which
support wide mode.

To set wide display, call `chronyc` with option `-w`.

Example of a `clients` list before and after:

chronyc -n clients -p 5
Hostname                      NTP   Drop Int IntL Last     Cmd   Drop Int  Last
===============================================================================
2001:db8:1234:5678:90ab:cdef:1234:5678     952      0   7   -    75       0      0   -     -
192.168.1.1                     0      0   -   -     -       0      0   -     -

chronyc -n -w clients -p 5
Hostname                                    NTP   Drop Int IntL Last     Cmd   Drop Int  Last
=============================================================================================
2001:db8:1234:5678:90ab:cdef:1234:5678      952      0   7   -    75       0      0   -     -
192.168.1.1                                   0      0   -   -     -       0      0   -     -

3 months agosys: add OpenBSD support
Thomas Kupper [Wed, 4 Feb 2026 21:09:09 +0000 (22:09 +0100)] 
sys: add OpenBSD support

Add OpenBSD support, including pledge(2) support by implementing
SYS_EnableSystemCallFilter().

This commit depends on the addition of AdjustFreq() privops and the
addtion of invoking SYS_EnableSystemCallFilter() from PRV_StartHelper().

Only system call filter levels on/off' are supported. Setting level
to 0 disables the filter and setting it to 1 enables it.

Update the documentation to reflect that OpenBSD supports:
- the SCHED_FIFO real-time scheduler (option -P)
- locking chronyd into memory (option -m)
- reload sample history of servers and ref clocks (option -r)
- forking into two process when run as non-root user (option -u)
- maxdrift/maxslewrate of 100000.

3 months agoprivops: add method PRV_AdjustFreq()
Thomas Kupper [Wed, 4 Feb 2026 20:53:52 +0000 (21:53 +0100)] 
privops: add method PRV_AdjustFreq()

In preparation of adding OpenBSD support:

OpenBSD doesn't support timex but adjusting frequency using the
adjfreq(2) system call. Add a privops method PRV_AdjustFreq() to allow
unprivileged processes to set the time.

3 months agoprivops: enable system call filter
Thomas Kupper [Wed, 11 Feb 2026 06:53:41 +0000 (07:53 +0100)] 
privops: enable system call filter

In preparation of OpenBSD support, add SYS_EnableSystemCallFilter() call
to PRV_StartHelper().

In OpenBSD the privops helper will use a system call filter (pledge(2)),
whereas in Linux the privops helper doesn't use any system call filter
at the moment.

Modify Unit test ntp_sources call to PRV_Initialise() with parameter
scfilter_level set to 0.

4 months agomakefile: rebuild everything after configure
Miroslav Lichvar [Thu, 12 Feb 2026 10:52:37 +0000 (11:52 +0100)] 
makefile: rebuild everything after configure

4 months agodoc: fix list of open commands enabled by default
Ingmar Stein [Sat, 7 Feb 2026 11:57:33 +0000 (12:57 +0100)] 
doc: fix list of open commands enabled by default

`DEFAULT_OPEN_COMMANDS` is defined as `activity manual rtcdata smoothing
sourcename sources sourcestats tracking`, so it looks like `sourcestats`
and `serverstats` were swapped in the documentation.

4 months agosys_macosx: fix macOS driver using timeval instead of timespec
Bryan Christianson [Fri, 6 Feb 2026 07:02:51 +0000 (20:02 +1300)] 
sys_macosx: fix macOS driver using timeval instead of timespec

The macOS driver was using the old settimeofday() variables. Now uses
timespec as required by updated PRV_SetTime().

Fixes: e313f5abf7b4 ("privops: switch from settimeofday() to clock_settime()")
4 months agoprivops: switch from settimeofday() to clock_settime()
Miroslav Lichvar [Thu, 29 Jan 2026 08:29:30 +0000 (09:29 +0100)] 
privops: switch from settimeofday() to clock_settime()

Following the removal of gettimeofday() calls, change PRV_SetTime() to
use clock_settime() instead of settimeofday(). Only CLOCK_REALTIME is
supported for now.

4 months agoclient+test: switch from gettimeofday() to clock_gettime()
Miroslav Lichvar [Tue, 27 Jan 2026 15:33:01 +0000 (16:33 +0100)] 
client+test: switch from gettimeofday() to clock_gettime()

Replace the remaining calls of gettimeofday().

4 months agosys_macosx: remove clock_gettime() override function
Bryan Christianson [Wed, 28 Jan 2026 07:35:44 +0000 (20:35 +1300)] 
sys_macosx: remove clock_gettime() override function

This will also remove a call to gettimeofday() that was used on very
early versions of macOS where clock_gettime was not implemented.

4 months agolocal: require clock_gettime()
Miroslav Lichvar [Tue, 27 Jan 2026 15:32:28 +0000 (16:32 +0100)] 
local: require clock_gettime()

Make clock_gettime() a hard requirement of chrony. It should be
available on all reasonably recent versions of the supported systems.

This enables adoption of the clockid_t type (CLOCK_* identifiers).

4 months agocmdmon: drop unused variable
Miroslav Lichvar [Mon, 26 Jan 2026 14:39:54 +0000 (15:39 +0100)] 
cmdmon: drop unused variable

4 months agortc: check for gmtime()/localtime() error when setting RTC
Miroslav Lichvar [Thu, 8 Jan 2026 08:42:59 +0000 (09:42 +0100)] 
rtc: check for gmtime()/localtime() error when setting RTC

Make sure the time conversion succeeded before using the result in
setting of the RTC.

6 months agontp: update NTP-over-PTP support
Miroslav Lichvar [Wed, 26 Nov 2025 11:14:08 +0000 (12:14 +0100)] 
ntp: update NTP-over-PTP support

Update the support for NTP over PTP to the latest specification
(currently in the RFC editor queue). Switch the NTP TLV to the
organization-specific TLV using the IANA OUI and assigned TLV
subtype 0x1. The Network Correction extension field has been
assigned type 0x10A. The extfield option accepts F324 as an alias
for 10A to not break existing configurations. Drop the experimental
status.

6 months agosys_linux: drop dhz variable
Miroslav Lichvar [Wed, 19 Nov 2025 15:50:45 +0000 (16:50 +0100)] 
sys_linux: drop dhz variable

Avoid keeping the system USER_HZ in two variables as an int and a
double. The integer value is not really needed. Replace sys_hz with dhz.

6 months agosys_linux: stop sticking ticks as workaround for old kernels
Miroslav Lichvar [Thu, 20 Nov 2025 08:53:49 +0000 (09:53 +0100)] 
sys_linux: stop sticking ticks as workaround for old kernels

Drop the old workaround avoiding small changes in ticks needed to avoid
frequency steps due to inexact scaling of frequency vs ticks in kernels
before 2.6.18. chrony doesn't support such old kernels anymore.

6 months agoconfigure: add -Wshadow to gcc/clang-specific CFLAGS
Miroslav Lichvar [Wed, 19 Nov 2025 15:31:52 +0000 (16:31 +0100)] 
configure: add -Wshadow to gcc/clang-specific CFLAGS

6 months agofix -Wshadow warnings
Miroslav Lichvar [Wed, 19 Nov 2025 15:05:38 +0000 (16:05 +0100)] 
fix -Wshadow warnings

Rename variables to avoid conflicts in naming of local and global
variables.

6 months agocmdmon: refactor handling of sources report
Miroslav Lichvar [Wed, 19 Nov 2025 13:12:09 +0000 (14:12 +0100)] 
cmdmon: refactor handling of sources report

The NSR_ReportSource() and RCL_ReportSource() functions assume that the
provided report already has some data prefilled by SRC_ReportSource()
and it's assumed these functions cannot fail.

Change them to accept the required data (refid and IP address) as
a parameter, remove unneeded parameters, and return an error status
(if the refid/address doesn't exist) to be handled in cmdmon
handle_source_data(). Also, catch unexpected values of the source state
and mode to make chronyc report an error instead of incorrect data.

6 months agotest: add 152-maxtxbuffers test
Miroslav Lichvar [Tue, 18 Nov 2025 15:47:32 +0000 (16:47 +0100)] 
test: add 152-maxtxbuffers test

7 months agontp: add alternative method of retrieving transmitted messages
Miroslav Lichvar [Thu, 13 Nov 2025 15:02:17 +0000 (16:02 +0100)] 
ntp: add alternative method of retrieving transmitted messages

When chronyd gets a kernel or hardware transmit timestamp after sending
an NTP message to a server, peer, or client (using interleaved mode), it
needs the address and content of the message to be able to correctly
assign the timestamp to the server, peer, or client. The timestamps are
processed asynchronously. The kernel provides with each timestamp the
data-link frame that was timestamped, but chronyd can extract the
necessary data only from plain IPv4 and IPv6 packets in Ethernet frames,
possibly including VLAN tags. If the NTP packets are transmitted by a
non-Ethernet device, or they are encapsulated in another layer (e.g. a
WireGuard tunnel), chronyd is not able to extract the data and use the
kernel or hardware transmit timestamps, having to fall back to less
accurate daemon timestamps.

Add an alternative method using transmit IDs assigned to each message
(supported since Linux 6.13), which are provided by the kernel with the
timestamp in the error queue, and map them to messages, addresses and
ports saved in a ring buffer, whose size can be configured by the new
maxtxbuffers directive.

Fow now, set the default maxtxbuffers to 0 (disabled). If set to a
non-zero value, allocate the ring buffer to the maximum size on start.
As a future improvement, it could be allocated only when the extraction
of the UDP payload fails, or the extracted message is not the expected
NTP message. The size could grow dynamically when a transmit ID is
missed.

7 months agosocket: add support for Linux timestamping transmit IDs
Miroslav Lichvar [Thu, 13 Nov 2025 10:14:35 +0000 (11:14 +0100)] 
socket: add support for Linux timestamping transmit IDs

Add a new field to the SCK_Message structure to enable setting and
getting of the Linux timestamping transmit IDs enabled by the
SOF_TIMESTAMPING_OPT_ID socket option. The ID can be set for each packet
individually by the SCM_TS_OPT_ID control message (supported on Linux
6.13 and newer).

This will allow procesing of transmit timestamps without extracting data
from the data-link frames.

7 months agontp: pass SCK_Message to extract_udp_data()
Miroslav Lichvar [Mon, 27 Oct 2025 14:01:39 +0000 (15:01 +0100)] 
ntp: pass SCK_Message to extract_udp_data()

Modify the message length directly in extract_udp_data() to make the
caller's code more clear.

7 months agoclient: fix typo in selectdata help text
Miroslav Lichvar [Tue, 4 Nov 2025 11:14:37 +0000 (12:14 +0100)] 
client: fix typo in selectdata help text

7 months agosources: add configurable limits for stratum
Miroslav Lichvar [Tue, 4 Nov 2025 10:39:40 +0000 (11:39 +0100)] 
sources: add configurable limits for stratum

Add minstratum and maxstratum directives to specify the minimum and
maximum allowed stratum of sources to be selected. The default values
are 0 and 15 respectively, allowing all NTP sources and refclocks.

Sources that are rejected due to having too large or too small stratum
are marked with 'r' in the selection log and selectdata report.

This is similar to the "tos floor" and "tos ceiling" settings of ntpd,
except that maxstratum is interpreted as one below the ceiling.

7 months agosources: rename min_stratum in SRC_SelectSource()
Miroslav Lichvar [Mon, 3 Nov 2025 13:33:44 +0000 (14:33 +0100)] 
sources: rename min_stratum in SRC_SelectSource()

Rename the variable to min_sel_stratum to make it more specific and
avoid shadowing a variable that will be added in the next commit.

7 months agosources: don't save SST_GetSelectionData() status
Miroslav Lichvar [Mon, 3 Nov 2025 11:51:00 +0000 (12:51 +0100)] 
sources: don't save SST_GetSelectionData() status

There is no need to save the SST_GetSelectionData() "select_ok" status
as the source is immediately marked as SRC_BAD_STATS if it is not ok.
Nothing else is using this information.

7 months agosourcestats: change ST_GetSelectionData() to return status directly
Miroslav Lichvar [Mon, 3 Nov 2025 11:44:58 +0000 (12:44 +0100)] 
sourcestats: change ST_GetSelectionData() to return status directly

For better consistency, indicate success (usable data) by returning 1
instead of setting a pointer parameter.

7 months agosourcestats: drop disabled code in SST_GetSelectionData()
Miroslav Lichvar [Mon, 3 Nov 2025 11:29:03 +0000 (12:29 +0100)] 
sourcestats: drop disabled code in SST_GetSelectionData()

7 months agotest: make 007-cmdmon test even more reliable
Miroslav Lichvar [Mon, 27 Oct 2025 14:57:05 +0000 (15:57 +0100)] 
test: make 007-cmdmon test even more reliable

The last hit value in the clients report may be "-", because there is
a backward step of the clock caused by the doffset and reset sources
commands.

7 months agosys_linux: fix building with older compilers and some archs
Miroslav Lichvar [Wed, 22 Oct 2025 08:53:11 +0000 (10:53 +0200)] 
sys_linux: fix building with older compilers and some archs

The recent replacement of <termios.h> with <linux/termios.h> to get
TCGETS2 seems to work only with compilers (or C standards) that allow
the same structure to be defined multiple times. There is a conflict
between <sys/ioctl.h> and <linux/termios.h>.

Another problem is that TCGETS2 is not used on some archs like ppc64.

Switch back to <termios.h> and move TCGETS2 to a list in a separate
file where it can be compiled without <sys/ioctl.h>.

Fixes: 03875f1ea5c4 ("sys_linux: allow ioctl(TCGETS2) in seccomp filter")
7 months agosys_linux: allow ioctl(TCGETS2) in seccomp filter
Miroslav Lichvar [Tue, 21 Oct 2025 12:06:38 +0000 (14:06 +0200)] 
sys_linux: allow ioctl(TCGETS2) in seccomp filter

Add TCGETS2 to the list of allowed ioctls. It seems to be called by the
latest glibc version from isatty(), which is called from libpcsclite
used by gnutls in an NTS-KE session.

Include the linux termios header instead of glibc header to get a usable
definition of TCGETS2.

8 months agolocal: improve measurement of clock precision
Miroslav Lichvar [Wed, 8 Oct 2025 11:09:10 +0000 (13:09 +0200)] 
local: improve measurement of clock precision

By default, the clock precision is set to the minimum measured time
needed to read the clock. This value is typically larger than the actual
resolution, which causes the NTP server to add more noise to NTP
timestamps than necessary. With HW timestamping and PTP corrections
enabled by the NTP-over-PTP transport that can be the limiting factor in
the stability of NTP measurements.

Try to determine the actual resolution of the clock. On non-Linux
systems use the clock_getres() function. On FreeBSD and NetBSD it seems
to provide expected values. On illumos it returns a large value (kernel
tick length?). On Linux it seems to be the internal timer resolution,
which is 1 ns with hrtimers, even when using a lower-resolution
clocksource like hpet or acpi_pm.

On Linux, try to measure the resolution as the minimum observed change
in differences between consecutive readings of the CLOCK_MONOTONIC_RAW
clock with a varying amount of busy work. Ignore 1ns changes due to
the kernel converting readings to timespec. This seems to work reliably.
In a test with the acpi_pm clocksource, differences of 3073, 3352, and
3631 ns were measured, which gives a resolution of 279 ns, matching the
clocksource frequency of ~3.58 MHz. With a tsc clocksource it gives
the minimum accepted resolution of 2 ns and with kvm-clock 10 ns.

As the final value of the precision, use the minimum value from the
measured or clock_getres() resolution and the original minimum time
needed to read the clock.

8 months agoleapdb: fix compiler warning on NetBSD about isspace()
Miroslav Lichvar [Wed, 8 Oct 2025 11:00:24 +0000 (13:00 +0200)] 
leapdb: fix compiler warning on NetBSD about isspace()

9 months agotest: fix socket unit test to use non-blocking accepted sockets
Miroslav Lichvar [Thu, 28 Aug 2025 07:33:34 +0000 (09:33 +0200)] 
test: fix socket unit test to use non-blocking accepted sockets

SCK_AcceptConnection() always returns a non-blocking socket. Clear the
O_NONBLOCK flag in the socket unit test, which relies on blocking, to
avoid failures.

Reported-by: Matthias Andree <matthias.andree@gmx.de>
9 months agosys_linux: improve error message for failed PHC open 4.8
Miroslav Lichvar [Wed, 27 Aug 2025 10:22:48 +0000 (12:22 +0200)] 
sys_linux: improve error message for failed PHC open

If the specified PHC device cannot be opened directly, an attempt is
made to open it as a network interface. When that fails, the error
"Could not open PHC of iface" is misleading the user that it was handled
only as an interface. Change the message to "Could not open PHC (of)" to
better cover both possibilities. Also remove the errno as it's not set
in all code paths.

9 months agotest: avoid using cmdport equal to ntpport in system tests
Miroslav Lichvar [Wed, 27 Aug 2025 08:58:42 +0000 (10:58 +0200)] 
test: avoid using cmdport equal to ntpport in system tests

Make sure the two randomly generated port numbers used in system tests
are different to avoid failures.

9 months agodoc: update URL in test documentation
Miroslav Lichvar [Tue, 26 Aug 2025 10:29:05 +0000 (12:29 +0200)] 
doc: update URL in test documentation

9 months agotest: check credentials in nts_ke_session test
Miroslav Lichvar [Tue, 26 Aug 2025 08:20:18 +0000 (10:20 +0200)] 
test: check credentials in nts_ke_session test

Make it more clear when the test fails because the credentials could not
be created.

9 months agoutil: switch create_dir() from chown() to lchown()
Miroslav Lichvar [Tue, 26 Aug 2025 06:38:07 +0000 (08:38 +0200)] 
util: switch create_dir() from chown() to lchown()

Use lchown(), the safer variant of chown() that does not follow
symlinks, when changing the ownership of a created directory (logdir,
dumpdir, ntsdumpdir, and the directory of bindcmdaddress) to the chrony
user.

9 months agoclient: fix sizeof in open_unix_socket()
Miroslav Lichvar [Mon, 25 Aug 2025 14:30:39 +0000 (16:30 +0200)] 
client: fix sizeof in open_unix_socket()

Fix one of the sizeofs in open_unix_socket() to correctly specify
sock_dir2 instead of sock_dir1. They have the same size, but don't rely
on that.

Fixes: 90d808ed2897 ("client: mitigate unsafe permissions change on chronyc socket")
10 months agodoc: update NEWS 4.8-pre1
Miroslav Lichvar [Thu, 14 Aug 2025 13:55:15 +0000 (15:55 +0200)] 
doc: update NEWS

10 months agodoc: update credits in README
Miroslav Lichvar [Thu, 14 Aug 2025 10:32:50 +0000 (12:32 +0200)] 
doc: update credits in README

10 months agodoc: update FAQ
Miroslav Lichvar [Wed, 6 Aug 2025 07:29:38 +0000 (09:29 +0200)] 
doc: update FAQ

10 months agoupdate copyright years
Miroslav Lichvar [Thu, 14 Aug 2025 12:53:33 +0000 (14:53 +0200)] 
update copyright years

10 months agoutil: avoid compiler warning in UTI_IPSockAddrToString()
Miroslav Lichvar [Thu, 14 Aug 2025 13:26:17 +0000 (15:26 +0200)] 
util: avoid compiler warning in UTI_IPSockAddrToString()

Don't print directly a buffer of the pool to another buffer of
the pool to avoid a -Wrestrict warning produced by a recent gcc version.

10 months agoconfigure: fix compiler warnings in system function checks
Miroslav Lichvar [Thu, 14 Aug 2025 11:55:54 +0000 (13:55 +0200)] 
configure: fix compiler warnings in system function checks

Avoid using (void *)1 as an output buffer to fix detection of supported
system functions due to -Werror and -Wstringop-overflow etc.

10 months agorefclock: rework update of reachability again
Miroslav Lichvar [Mon, 11 Aug 2025 14:13:20 +0000 (16:13 +0200)] 
refclock: rework update of reachability again

The recent rework of refclock reachability to better work with
driver-specific filtering (PHC driver dropping samples with unexpected
delay) introduced an issue that a PPS refclock is indicated as reachable
even when its "lock" refclock is permanently unreachable, or its samples
constistently fail in other sample checks, and no actual samples can be
accumulated. This breaks the new maxunreach option.

Rework the refclock code to provide samples from drivers together with
their quality level (all drivers except PHC provide samples with
constant quality of 1) and drop samples with quality 0 after passing
all checks, right before the actual accumulation in the median sample
filter. Increment the reachability counter only for samples that would
be accumulated.

This fixes the problem with refclocks indicated as reachable when their
samples would be dropped for other reasons than the PHC-specific delay
filter, and the maxunreach option can work as expected.

Fixes: b9b338a8df23 ("refclock: rework update of reachability")
10 months agohwclock: don't drop valid samples in HCL_ProcessReadings()
Miroslav Lichvar [Mon, 11 Aug 2025 14:00:38 +0000 (16:00 +0200)] 
hwclock: don't drop valid samples in HCL_ProcessReadings()

Modify the HCL_ProcessReadings() function to try to always provide
a valid sample. Instead of dropping a sample outside of the expected
delay, provide its assumed quality level as a small integer (relative to
already accumulated samples), and let the caller decide what quality is
acceptable.

10 months agorefclock_phc: open device for writing with extpps option
Miroslav Lichvar [Thu, 7 Aug 2025 12:04:22 +0000 (14:04 +0200)] 
refclock_phc: open device for writing with extpps option

In version 6.15 the Linux kernel started checking write access on the
PHC file descriptor in the PTP_PIN_SETFUNC and PTP_EXTTS_REQUEST ioctls.
chronyd opened the PHC device as readonly, which caused the PHC refclock
driver configured with the extpps option to fail with the
"Could not enable external PHC timestamping" error message.

To ensure compatibility with new kernel versions, add flags to the
SYS_Linux_OpenPHC() function and open the device with the O_RDWR flag
when the extpps option is enabled.

10 months agotls: don't accept NULL ALPN name in TLS_CreateInstance()
Miroslav Lichvar [Wed, 6 Aug 2025 14:21:57 +0000 (16:21 +0200)] 
tls: don't accept NULL ALPN name in TLS_CreateInstance()

The TLS_CreateInstance() function handles a NULL alpn_name, but the
other session functions would crash if it was NULL. Change the function
to not handle the NULL for consistency and avoid potential confusion.

Fixes: 3e32e7e69412 ("tls: move gnutls code into tls_gnutls.c")
10 months agotls: fix server log messages to have client IP address
Miroslav Lichvar [Wed, 6 Aug 2025 13:43:41 +0000 (15:43 +0200)] 
tls: fix server log messages to have client IP address

Add an additional parameter to TLS_CreateInstance() to save the label of
the connection (server name on the client side and client IP
address:port on the server side) instead of the server name (which is
NULL on the server side) to fix the log messages.

Fixes: 3e32e7e69412 ("tls: move gnutls code into tls_gnutls.c")
10 months agotls: don't call gnutls_deinit() after failed gnutls_init()
Miroslav Lichvar [Wed, 6 Aug 2025 13:07:18 +0000 (15:07 +0200)] 
tls: don't call gnutls_deinit() after failed gnutls_init()

Don't assume gnutls_init() leaves the session pointer at NULL when it
returns with an error status. It might be a session that was already
allocated and then freed without resetting it to NULL after an error.

Fixes: 3e32e7e69412 ("tls: move gnutls code into tls_gnutls.c")
10 months agosources: add option to limit selection of unreachable sources
Miroslav Lichvar [Tue, 5 Aug 2025 14:08:40 +0000 (16:08 +0200)] 
sources: add option to limit selection of unreachable sources

Add maxunreach option to NTP sources and refclocks to specify the
maximum number of polls that the source can stay selected for
synchronization when it is unreachable (i.e. no valid sample was
received in the last 8 polls).

It is an additional requirement to having at least one sample more
recent than the oldest sample of reachable sources.

The default value is 100000. Setting the option to 0 disables selection
of unreachable sources, which matches RFC 5905.

10 months agoclient: add support for dropping root privileges
Miroslav Lichvar [Mon, 4 Aug 2025 14:34:52 +0000 (16:34 +0200)] 
client: add support for dropping root privileges

To minimize the impact of potential attacks targeting chronyc started
under root (e.g. performed by a local chronyd process running without
root privileges, a remote chronyd process, or a MITM attacker on the
network), add support for changing the effective UID/GID in chronyc
after start.

The user can be specified by the -u option, similarly to chronyd. The
default chronyc user can be changed by the --with-chronyc-user
configure option. The default value of the default chronyc user is
"root", i.e. chronyc doesn't try to change the identity by default.

The default chronyc user does not follow the default chronyd user
set by the configure --with-user option to avoid errors on systems where
chronyc is not allowed to change its UID/GID (e.g. by a SELinux policy).

10 months agotest: fix system tests to change also tempcomp owner
Miroslav Lichvar [Wed, 30 Jul 2025 12:57:01 +0000 (14:57 +0200)] 
test: fix system tests to change also tempcomp owner

10 months agosocket: rename sun variable to fix compilation on illumos
Miroslav Lichvar [Wed, 30 Jul 2025 12:23:45 +0000 (14:23 +0200)] 
socket: rename sun variable to fix compilation on illumos

"sun" is reserved on Solaris/illumos.

Fixes: 3dea7dd72373 ("socket: rework setting of struct sockaddr_un")
10 months agosocket: remove unused chmod() call
Miroslav Lichvar [Wed, 16 Jul 2025 14:19:18 +0000 (16:19 +0200)] 
socket: remove unused chmod() call

Drop the SCK_FLAG_ALL_PERMISSIONS support from the socket code.
chronyc is now calling chmod() on its socket itself in a hidden
directory to mitigate the unsafe operation.

10 months agoclient: mitigate unsafe permissions change on chronyc socket
Miroslav Lichvar [Wed, 16 Jul 2025 13:55:05 +0000 (15:55 +0200)] 
client: mitigate unsafe permissions change on chronyc socket

When chronyc running under root binds its Unix domain socket, it needs
to change the socket permissions in order for chronyd running without
root privileges to be able to send a response to the socket.

There is a race condition between the bind() and chmod() calls. If an
attacker was able to execute arbitrary code in the chronyd process, it
might be able to wait for chronyc to be executed under root, replace the
socket with a symlink between the two calls, and cause the privileged
chronyc process to change permissions of something else, possibly
leading to a privilege escalation.

There doesn't seem to be a safe and portable way to change the socket
permissions directly. Changing the process umask could be problematic in
future with threads.

Hide the socket in two levels of subdirectories (the lower one having
a randomly generated name and not visible to the chronyd process) to
make the socket path unpredictable, and force the bind() or chmod() call
to fail if the visible upper directory is replaced.

Reported-by: Matthias Gerstner <mgerstner@suse.de>
11 months agoutil: warn if UTI_OpenFile() is stuck in a loop
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>
11 months 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>
11 months 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

11 months 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>
11 months 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.

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

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

12 months 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.

12 months 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")
12 months 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.

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

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

12 months 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

12 months 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

12 months 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

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

12 months 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")
12 months 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.

12 months 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

12 months 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

12 months 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.

12 months 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.

12 months 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.

12 months 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