[Linuxptp-devel] [PATCHv2 RFC 0/6] Support for dropping root privileges

2021-07-13 Thread Miroslav Lichvar
v2: - keep more capabilities (raw sockets, timestamping configuration) - copy ownership of server UDS - follow location of server UDS for client sockets - support operation with NTPSHM servo - move default UDS addresses to /var/run/linuxptp This patchset implements a support for dropping all root

[Linuxptp-devel] [PATCHv2 RFC 4/6] pmc: Add support for dropping root privileges.

2021-07-13 Thread Miroslav Lichvar
Drop root before binding the UDS socket and change the default UDS address to follow to location of the server UDS. Signed-off-by: Miroslav Lichvar --- pmc.8| 13 +++-- pmc.c| 10 -- pmc_common.c | 32 3 files changed, 51

[Linuxptp-devel] [PATCHv2 RFC 6/6] config: move default UDS addresses to /var/run/linuxptp.

2021-07-13 Thread Miroslav Lichvar
/var/run cannot be used by non-root users to bind and unlink sockets. Move the default server UDS addresses to /var/run/linuxptp, which will be created by ptp4l the first time it runs. Signed-off-by: Miroslav Lichvar --- config.c| 4 ++-- configs/default.cfg | 4 ++-- phc2sys.8

[Linuxptp-devel] [PATCHv2 RFC 5/6] phc2sys: Add support for dropping root privileges.

2021-07-13 Thread Miroslav Lichvar
In the static mode, drop the privileges after opening the clocks. In the automatic mode, drop the privileges before opening the UDS port, which is required to get the list of interfaces, but is the part of the operation that needs to be protected most. The non-root user must have permissions to

[Linuxptp-devel] [PATCHv2 RFC 2/6] uds: Copy ownership of server socket.

2021-07-13 Thread Miroslav Lichvar
To not require pmc and phc2sys to run under the same user as ptp4l, change the ownership of their socket to the server socket, so it can send a response to their socket. Signed-off-by: Miroslav Lichvar --- uds.c | 9 + 1 file changed, 9 insertions(+) diff --git a/uds.c b/uds.c index

[Linuxptp-devel] [PATCHv2 RFC 1/6] util: Add functions for dropping root privileges.

2021-07-13 Thread Miroslav Lichvar
Add a function to switch the process UID/GID to a specified user in order to drop the root privileges, but keep the capabilities needed to adjust the clock, enable HW timestamping, bind to privileged ports and raw sockets, using the libcap library. Add a function to create a directory for a UDS

[Linuxptp-devel] [PATCH] config: Add workaround for glibc getopt_long().

2021-07-13 Thread Miroslav Lichvar
getopt_long() in glibc allows shortened long option names, e.g. ptp4l --domain works as --domainNumber. When the match is ambiguous, e.g. --fault matches --fault_badpeernet_interval and --fault_reset_interval, it is supposed to return an error, but that works only if their struct option have