Commit graph

116 commits

Author SHA1 Message Date
Miroslav Lichvar
4ceb9e4cd0 sys_linux: allow fcntl(F_SETFL) in seccomp filter
This fixes commit 76bed76289.
2018-08-03 17:21:02 +02:00
Miroslav Lichvar
bf7aa52394 sys_linux: fix building with old libcap versions
The cap_get_bound() function and CAP_IS_SUPPORTED macro were added in
libcap-2.21. Check if the macro is defined before use.

The sys/capability.h header from libcap-2.16 and earlier disables the
linux/types.h header, which breaks the linux/ptp_clock.h header. Change
the order to include sys/capability.h as the last system header.
2018-04-05 16:18:23 +02:00
Miroslav Lichvar
19f3ab2225 ntp: fix handling of socket errors with error queue
In the next Linux version the recvmmsg() system call will be probably
fixed to not return socket errors (e.g. due to ICMP) when reading from
the error queue.

The NTP I/O code assumed this was the correct behavior. When the system
call is fixed, a socket error on a client socket will cause chronyd to
enter a busy loop consuming the CPU until the receive timeout is reached
(8 seconds by default).

Use getsockopt(SO_ERROR) to clear the socket error when reading from the
error queue failed.
2018-04-04 09:18:44 +02:00
Christian Ehrhardt
02098ed830 sys_linux: report if CAP_SYS_TIME is not present
Instead of having adjtimex just fail with a permission issue
improve the error messaging by warning for the lack of
CAP_SYS_TIME on SYS_Linux_Initialise.

Message will look like (instead of only the latter message):
 CAP_SYS_TIME not present
 adjtimex(0x8001) failed : Operation not permitted

Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
2018-03-14 16:14:56 +01:00
Miroslav Lichvar
e8096330be sys_linux: don't keep CAP_SYS_TIME with -x option
When dropping the root privileges, don't try to keep the CAP_SYS_TIME
capability if the -x option was enabled. This allows chronyd to be
started without the capability (e.g. in containers) and also drop the
root privileges.
2018-02-05 14:05:19 +01:00
Miroslav Lichvar
c9f50fc686 update copyright years 2017-08-28 14:38:23 +02:00
Miroslav Lichvar
3d08815efb sys_linux: fix building with older kernel headers
Programming pins for external PHC timestamping was added in Linux 3.15,
but the PHC subsystem is older than that. Compile the programming code
only when the ioctl is defined.
2017-08-15 13:39:39 +02:00
Miroslav Lichvar
f734bd1a7c sys_linux: allow getrandom in seccomp filter
This fixes commit c5735ebfe9.
2017-07-25 17:40:35 +02:00
Miroslav Lichvar
4ba92bb6d6 sys_linux: add support for external PHC timestamping 2017-05-26 13:33:53 +02:00
Miroslav Lichvar
653d70ec4e sys_linux: allow sysinfo in seccomp filter
It may be used by glob() in latest glibc.
2017-04-19 14:38:51 +02:00
Miroslav Lichvar
abb09418b1 sys_linux: don't drop PHC samples with zero delay
When processing data from the PTP_SYS_OFFSET ioctl, the sample is
dropped when an interval between two consecutive readings of the system
clock is negative or zero, assuming the clock has been stepped between
the two readings.

With a real PHC the interval is normally expected to be at least a
microsecond, but with a virtual PHC and a low-resolution system clock
it's possible to get two readings with the same system time. Modify the
check to drop only samples with a negative delay.
2017-04-19 13:03:10 +02:00
Miroslav Lichvar
768bce799b sys_linux: allow getpid in seccomp filter
It seems to be used by syslog() in latest glibc.
2017-03-13 14:42:44 +01:00
Miroslav Lichvar
f282856c72 logging: remove facility parameter
It was never used for anything and messages in debug output already
include filenames, which can be easily grepped if there is a need
to see log messages only from a particular file.
2017-03-10 16:51:03 +01:00
Miroslav Lichvar
a4e3f83611 update copyright years 2017-01-24 15:01:38 +01:00
Miroslav Lichvar
31b6a14444 sys_linux: add support for PTP_SYS_OFFSET_PRECISE
This is for hardware that can precisely cross timestamp the PHC with the
system clock.
2017-01-23 15:58:55 +01:00
Miroslav Lichvar
b70f0b674f ntp: move PHC-specific code to sys_linux
This will allow sharing of the code with the PHC refclock driver.
2017-01-23 15:58:55 +01:00
Miroslav Lichvar
9ba8a33966 sys_linux: allow openat in seccomp filter 2016-12-06 16:56:38 +01:00
Miroslav Lichvar
518837e17a sys_linux: allow ioctls used with HW timestamping in seccomp filter 2016-11-23 09:24:05 +01:00
Miroslav Lichvar
997406fe47 ntp: add support for software timestamping on Linux
Enable SCM_TIMESTAMPING control messages and the socket's error queue in
order to receive our transmitted packets with a more accurate transmit
timestamp. Add a new file for Linux-specific NTP I/O and implement
processing of these messages there.
2016-11-10 15:26:56 +01:00
Miroslav Lichvar
a8c6bea2d5 sys_linux: add function for checking kernel version 2016-11-10 15:26:55 +01:00
Miroslav Lichvar
411f4697ca sys_linux: allow getdents in seccomp filter
This is needed for glob(), which is used with the include and dumpdir
directives.
2016-09-26 12:40:43 +02:00
Miroslav Lichvar
7a1ebc3467 ntp: add support for SO_TIMESTAMPNS socket option
Enable the SO_TIMESTAMPNS option to get kernel timestamps in nanosecond
resolution.
2016-08-19 13:55:20 +02:00
Miroslav Lichvar
8d89610ff6 local: add support for clock_gettime()
Use clock_gettime() to read the system clock in nanosecond resolution.
2016-08-19 13:54:58 +02:00
Miroslav Lichvar
e306199588 ntp: add support for recvmmsg()
This is used to read multiple packets with one system call. It should
work on Linux and NetBSD.
2016-08-11 10:45:48 +02:00
Miroslav Lichvar
5645e57ce0 sys_linux: include <termios.h> for TCGETS 2016-03-29 10:06:21 +02:00
Miroslav Lichvar
54c8732c46 sys_linux: use privops helper when running with seccomp filter
Enable the PRV_Name2IPAddress() function with seccomp support and start
the helper process before loading the seccomp filter (but after dropping
root privileges). This will move the getaddrinfo() call outside the
seccomp filter and should make it more reliable as the list of required
system calls won't depend on what glibc NSS modules are used on the
system.
2016-01-14 14:45:48 +01:00
Miroslav Lichvar
0a10df1cf5 sys_linux: keep CAP_NET_BIND_SERVICE only if NTP port can be opened
If port is set to 0 in the config file, the server port cannot be opened
and there is no point in keeping the binding capability.
2015-12-10 16:30:38 +01:00
Miroslav Lichvar
3cf6acdf24 util: add function for dropping root privileges
Share the code for dropping supplementary groups and setting effective,
saved, and real user UID/GID between system drivers.
2015-12-10 15:25:56 +01:00
Miroslav Lichvar
4e32de09a2 sys_linux: allow mremap in seccomp filter 2015-12-07 11:35:27 +01:00
Miroslav Lichvar
f21e5f6cc5 sys_linux: allow ioctl(TCGETS) in seccomp filter
This seems to be needed to allow fopen() called on /dev/urandom to check
if it's a terminal.
2015-11-18 12:49:11 +01:00
Miroslav Lichvar
bdb1650ed8 sys_linux: allow more syscalls in seccomp filter
These seem to be needed by getaddrinfo() in default NSS configuration
on recent Fedora.
2015-11-04 15:17:16 +01:00
Miroslav Lichvar
9e8b4bae11 sys_linux: abort when loading seccomp rules fails 2015-10-05 09:56:58 +02:00
Miroslav Lichvar
3396778061 update copyright years 2015-10-01 18:07:10 +02:00
Miroslav Lichvar
d6fdae5f1d sys_generic: allow fast slewing with system driver
The system drivers may implement their own slewing which the generic
driver can use to slew faster than the maximum frequency the driver is
allowed to set directly.
2015-09-23 11:19:09 +02:00
Miroslav Lichvar
1b2510e4b2 sys_linux: use timex driver
Remove functions that are included in the new timex driver. Keep only
functions that have extended functionality, i.e. read and set the
frequency using the timex tick field and apply step offset with
ADJ_SETOFFSET.

Merge the code from wrap_adjtimex.c that is still needed with
sys_linux.c and remove the file.
2015-09-17 15:52:49 +02:00
Miroslav Lichvar
f102acd423 sys_linux: allow uname in seccomp filter
It may be called from res_init() apparently.
2015-09-14 16:53:25 +02:00
Miroslav Lichvar
1619453b2b sys_linux: allow setting IP_FREEBIND option in seccomp filter
This is needed when chronyd is started with no allow directive, but the
NTP server socket is opened by the allow command later.
2015-09-09 17:19:07 +02:00
Miroslav Lichvar
434faeecb8 sys_linux: add support for seccomp filters
The Linux secure computing (seccomp) facility allows a process to
install a filter in the kernel that will allow only specific system
calls to be made. The process is killed when trying to make other system
calls. This is useful to reduce the kernel attack surface and possibly
prevent kernel exploits when the process is compromised.

Use the libseccomp library to add rules and load the filter into the
kernel. Keep a list of system calls that are always allowed after
chronyd is initialized. Restrict arguments that may be passed to the
socket(), setsockopt(), fcntl(), and ioctl() system calls. Arguments
to socketcall(), which is used on some architectures as a multiplexer
instead of separate socket system calls, are not restricted for now.
The mailonchange directive is not allowed as it calls sendmail.

Calls made by the libraries that chronyd is using have to be covered
too. It's difficult to determine which system calls they need as it may
change after an upgrade and it may depend on their configuration (e.g.
resolver in libc). There are also differences between architectures. It
can all break very easily and is therefore disabled by default. It can
be enabled with the new -F option.

This is based on a patch from Andrew Griffiths <agriffit@redhat.com>.
2015-09-04 17:56:51 +02:00
Miroslav Lichvar
770db1fe02 sys_linux: always call TMX_SetLeap() in set_leap()
The optimization avoiding unnecessary setting of the kernel leap status
can cause a problem when something outside chronyd sets the status to
the new expected value. There will be no TMX_SetLeap() call which would
update the saved status and the kernel status will be overwritten with
the old (incorrect) value in a later TMX_*() call.

Always call TMX_SetLeap() to save the new value and for the log message
selection just check if a leap second has been applied.
2015-08-27 13:26:12 +02:00
Miroslav Lichvar
e56154a687 sys_linux: remove unused variables 2015-08-24 13:25:39 +02:00
Miroslav Lichvar
6402350c83 sys: move getpwnam() call to main.c
Pass uid/gid instead of user name to the root dropping function.
2015-08-10 16:06:39 +02:00
Miroslav Lichvar
15932c9d7b sys: add new log message for kernel status reset after leap second
When a leap second is applied by the kernel, it doesn't actually clear
the STA_INS|STA_DEL bits from the status word, but the state returned
by ntp_adjtime()/adjtimex() is TIME_WAIT until the application clears
the bits.

Add "System clock status reset after leap second" log message for this
case.
2015-07-27 12:35:21 +02:00
Miroslav Lichvar
f6a9c5c1b7 sys: allow drivers to fail when applying step offset
Different systems may consider different time values to be valid.
Don't exit on settimeofday()/adjtimex() error in case the check in
UTI_IsTimeOffsetSane() isn't restrictive enough.
2015-04-07 15:23:47 +02:00
Miroslav Lichvar
c68a92ba80 sys: avoid syslog message when leap bits are not changed
After leap second the kernel removes STA_INS and STA_DEL bits from the
adjtimex status automatically, don't report a change when clearing the
bits.
2015-03-25 15:32:05 +01:00
Miroslav Lichvar
40bbe2539b sys: keep cap_net_bind_service capability
This will be needed to allow opening of NTP server socket after root
privileges are dropped.
2015-01-06 15:28:22 +01:00
Miroslav Lichvar
c4d57f0e3d sys: remove shift_hz
It's not used for anything since commit e147f2f1.
2014-12-10 15:58:27 +01:00
Miroslav Lichvar
eadabfe890 sys: remove TMX_ReadCurrentParams 2014-12-10 15:58:27 +01:00
Miroslav Lichvar
02cbe5e1ad sys: add sync status setting to generic and Linux driver
Set the adjtimex status, esterror and maxerror fields to the values
provided by the reference module.
2014-12-10 15:58:13 +01:00
Miroslav Lichvar
2645e632a8 sys: fix formatting in sys_linux.c 2014-12-10 15:35:56 +01:00
Miroslav Lichvar
e14a03a172 local: add new driver call to set synchronization status
This will be used to set the kernel adjtimex() variables to allow other
applications running on the system to know if the system clock is
synchronized and the estimated error and the maximum error.
2014-12-10 15:35:56 +01:00