From 44bbfc3a761332e46724af409b7a6e584b4b02be Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jun 2019 15:41:50 +0200 Subject: test: update processing of packet log Two new fields have been added to the packet log, which broke some of the simulation tests. Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=62d6aed6a64b887c9e3b7f03d9e0db1deaa2696a Gbp-Pq: Name update_processing_of_packet_log.patch --- test/simulation/test.common | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simulation/test.common b/test/simulation/test.common index 951a794..8ed6ad9 100644 --- a/test/simulation/test.common +++ b/test/simulation/test.common @@ -391,9 +391,9 @@ check_packet_port() { for i in $(seq 1 $(get_chronyd_nodes)); do test_message 3 0 "node $i:" - grep -E -q " $port [0-9]+\$" tmp/log.packets && \ + grep -E -q "^([0-9e.+-]+ ){5}$port " tmp/log.packets && \ ! grep -E "^[0-9e.+-]+ $i " tmp/log.packets | \ - grep -E -q -v " $port [0-9]+\$" && \ + grep -E -q -v "^([0-9e.+-]+ ){5}$port " && \ test_ok || test_bad [ $? -eq 0 ] || ret=1 done -- cgit v1.2.3 From d31a2453bc19ca62717299e95376b56652f9473e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jun 2019 15:41:50 +0200 Subject: test: update processing of packet log Two new fields have been added to the packet log, which broke some of the simulation tests. Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=62d6aed6a64b887c9e3b7f03d9e0db1deaa2696a Gbp-Pq: Name update_processing_of_packet_log.patch --- test/simulation/test.common | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simulation/test.common b/test/simulation/test.common index 951a794..8ed6ad9 100644 --- a/test/simulation/test.common +++ b/test/simulation/test.common @@ -391,9 +391,9 @@ check_packet_port() { for i in $(seq 1 $(get_chronyd_nodes)); do test_message 3 0 "node $i:" - grep -E -q " $port [0-9]+\$" tmp/log.packets && \ + grep -E -q "^([0-9e.+-]+ ){5}$port " tmp/log.packets && \ ! grep -E "^[0-9e.+-]+ $i " tmp/log.packets | \ - grep -E -q -v " $port [0-9]+\$" && \ + grep -E -q -v "^([0-9e.+-]+ ){5}$port " && \ test_ok || test_bad [ $? -eq 0 ] || ret=1 done -- cgit v1.2.3 From 3b9f47061ae1310b4f04e4a81e466b5c68ee3986 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jun 2019 15:41:50 +0200 Subject: test: update processing of packet log Two new fields have been added to the packet log, which broke some of the simulation tests. Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=62d6aed6a64b887c9e3b7f03d9e0db1deaa2696a Gbp-Pq: Name update_processing_of_packet_log.patch --- test/simulation/test.common | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simulation/test.common b/test/simulation/test.common index 951a794..8ed6ad9 100644 --- a/test/simulation/test.common +++ b/test/simulation/test.common @@ -391,9 +391,9 @@ check_packet_port() { for i in $(seq 1 $(get_chronyd_nodes)); do test_message 3 0 "node $i:" - grep -E -q " $port [0-9]+\$" tmp/log.packets && \ + grep -E -q "^([0-9e.+-]+ ){5}$port " tmp/log.packets && \ ! grep -E "^[0-9e.+-]+ $i " tmp/log.packets | \ - grep -E -q -v " $port [0-9]+\$" && \ + grep -E -q -v "^([0-9e.+-]+ ){5}$port " && \ test_ok || test_bad [ $? -eq 0 ] || ret=1 done -- cgit v1.2.3 From f66bc754d201d965730c278d79d8d094270c0aea Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:40:44 +0100 Subject: rtc: simplify and move switch_interrupts() Gbp-Pq: Name rtc-simplify-and-move-switch_interrupts-function.patch --- rtc_linux.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index d4d9bd0..30833e5 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -527,6 +527,20 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) return RTC_ST_OK; } +/* ================================================== */ + +static void +switch_interrupts(int on_off) +{ + if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { + LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", + on_off ? "enable" : "disable", strerror(errno)); + return; + } + + if (on_off) + skip_interrupts = 1; +} /* ================================================== */ /* file_name is the name of the file where we save the RTC params @@ -603,29 +617,6 @@ RTC_Linux_Finalise(void) /* ================================================== */ -static void -switch_interrupts(int onoff) -{ - int status; - - if (onoff) { - status = ioctl(fd, RTC_UIE_ON, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "enable", strerror(errno)); - return; - } - skip_interrupts = 1; - } else { - status = ioctl(fd, RTC_UIE_OFF, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "disable", strerror(errno)); - return; - } - } -} - -/* ================================================== */ - static void measurement_timeout(void *any) { -- cgit v1.2.3 From 86e63ba6128e7ad7a072b6f7c9a8b671ef4200c1 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:30:42 +0100 Subject: rtc: don't finalize driver if initialization failed Gbp-Pq: Name rtc-do-not-finalize-driver-if-initialization-failed.patch --- rtc.c | 2 +- rtc_linux.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rtc.c b/rtc.c index 33d04bf..fa83173 100644 --- a/rtc.c +++ b/rtc.c @@ -160,7 +160,7 @@ RTC_Initialise(int initial_set) void RTC_Finalise(void) { - if (driver.fini) { + if (driver_initialised) { (driver.fini)(); } } diff --git a/rtc_linux.c b/rtc_linux.c index 30833e5..c1a705d 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -550,6 +550,17 @@ switch_interrupts(int on_off) int RTC_Linux_Initialise(void) { + /* Try to open the device */ + fd = open(CNF_GetRtcDevice(), O_RDWR); + if (fd < 0) { + LOG(LOGS_ERR, "Could not open RTC device %s : %s", + CNF_GetRtcDevice(), strerror(errno)); + return 0; + } + + /* Close on exec */ + UTI_FdSetCloexec(fd); + rtc_sec = MallocArray(time_t, MAX_SAMPLES); rtc_trim = MallocArray(double, MAX_SAMPLES); system_times = MallocArray(struct timespec, MAX_SAMPLES); @@ -560,18 +571,6 @@ RTC_Linux_Initialise(void) /* In case it didn't get done by pre-init */ coefs_file_name = CNF_GetRtcFile(); - /* Try to open device */ - - fd = open (CNF_GetRtcDevice(), O_RDWR); - if (fd < 0) { - LOG(LOGS_ERR, "Could not open RTC device %s : %s", - CNF_GetRtcDevice(), strerror(errno)); - return 0; - } - - /* Close on exec */ - UTI_FdSetCloexec(fd); - n_samples = 0; n_samples_since_regression = 0; n_runs = 0; -- cgit v1.2.3 From 9b5de603750d9a2e3a85092e29d3816f8a7aaefe Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:33:17 +0100 Subject: rtc: handle RTCs that don't support interrupts Some RTCs supported by the Linux kernel don't support the RTC_UIE_ON/OFF ioctls, which causes chronyd started with the -s option to get stuck in the initial RTC mode. After opening the RTC device in the initialization, return error if the ioctls are not supported to prevent the upper layer from calling the time_init() function and expecting it to finish. Gbp-Pq: Name rtc-handle-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index c1a705d..8b21394 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -529,17 +529,19 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) /* ================================================== */ -static void +static int switch_interrupts(int on_off) { if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", on_off ? "enable" : "disable", strerror(errno)); - return; + return 0; } if (on_off) skip_interrupts = 1; + + return 1; } /* ================================================== */ @@ -558,6 +560,12 @@ RTC_Linux_Initialise(void) return 0; } + /* Make sure the RTC supports interrupts */ + if (!switch_interrupts(0)) { + close(fd); + return 0; + } + /* Close on exec */ UTI_FdSetCloexec(fd); -- cgit v1.2.3 From 5545379812427992b38ef46ac72a332565a0212a Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:42:34 +0100 Subject: rtc: disable interrupts in finalization Don't leave interrupts enabled if chronyd is stopped when making an RTC measurement. Gbp-Pq: Name rtc-disable-interrupts-in-finalization.patch --- rtc_linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rtc_linux.c b/rtc_linux.c index 8b21394..7ec27c9 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -611,6 +611,7 @@ RTC_Linux_Finalise(void) /* Remove input file handler */ if (fd >= 0) { SCH_RemoveFileHandler(fd); + switch_interrupts(0); close(fd); /* Save the RTC data */ -- cgit v1.2.3 From 1585cb3c2848d639b692e8424287aa8bebfcbc28 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:40 +0100 Subject: rtc: extend check for RTCs that don't support interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several RTCs would only expose the broken behavior on enabling interrupts. The reason for that is that the kernel only returns the error if the state changes. Therefore the check has to probe switch_interrupts(1) as well. On platforms that work it will be switched on and off, while on those it never works it will just stay off. Clocks known to expose that behavior include, but are not limited to: PPC64# dmesg | grep -i rtc    [    0.241872] rtc-generic rtc-generic: registered as rtc0 [    0.270221] rtc-generic rtc-generic: setting system clock to ... ARM64# dmesg | grep -i rtc [    0.876198] rtc-efi rtc-efi: registered as rtc0 [    1.046869] rtc-efi rtc-efi: setting system clock to ... Signed-off-by: Christian Ehrhardt Gbp-Pq: Name rtc-extend-check-for-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtc_linux.c b/rtc_linux.c index 7ec27c9..3220fad 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -561,7 +561,7 @@ RTC_Linux_Initialise(void) } /* Make sure the RTC supports interrupts */ - if (!switch_interrupts(0)) { + if (!switch_interrupts(1) || !switch_interrupts(0)) { close(fd); return 0; } -- cgit v1.2.3 From eb3a6ea51832d13b5eb1032148d9f83ae6ebb9b9 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:39 +0100 Subject: test: accept test result if RTC can't enable RTC_UIE_ON The test might run on different platforms. If the platform happens to have a RTC that does exist but unable to have RTC_UIE_ON set the test will fail, while the chrony code is actually good. Examples of bad clocks are: - ppc64el: rtc-generic - arm64: rtc-efi To avoid that extend the log message check on 101-rtc to accept that condition as a valid test result as well. Signed-off-by: Christian Ehrhardt Gbp-Pq: Name test-accept-test-result-if-RTC-can-not-enable-RTC_UIE_ON.patch --- test/system/101-rtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/101-rtc b/test/system/101-rtc index fa9a70d..68bce68 100755 --- a/test/system/101-rtc +++ b/test/system/101-rtc @@ -14,6 +14,6 @@ echo "1 $(date +%s) 0.0 0.0" > "$TEST_DIR/rtcfile" start_chronyd || test_fail stop_chronyd || test_fail -check_chronyd_message_count "\(clock off from RTC\|RTC time before last\)" 1 1 || test_fail +check_chronyd_message_count "\(clock off from RTC\|RTC time before last\|Could not \(enable\|disable\) RTC interrupt\)" 1 1 || test_fail test_pass -- cgit v1.2.3 From 445e6a12c360c52ac1c0c46c89ab59d9d77c1195 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 2 Dec 2019 12:47:13 +0100 Subject: sys_linux: allow clock_adjtime in seccomp filter The adjtimex() function in glibc was switched to the clock_adjtime system call. Gbp-Pq: Name allow-clock_adjtime-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index 898dc7a..4a743ba 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -478,8 +478,8 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(clock_gettime), SCMP_SYS(gettimeofday), - SCMP_SYS(settimeofday), SCMP_SYS(time), + SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), SCMP_SYS(clock_gettime), + SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getpid), SCMP_SYS(getrlimit), SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigreturn), -- cgit v1.2.3 From 3d47992707e37c88c759dd58574acf33c790db34 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jun 2019 15:41:50 +0200 Subject: test: update processing of packet log Two new fields have been added to the packet log, which broke some of the simulation tests. Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=62d6aed6a64b887c9e3b7f03d9e0db1deaa2696a Gbp-Pq: Name update_processing_of_packet_log.patch --- test/simulation/test.common | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simulation/test.common b/test/simulation/test.common index 951a794..8ed6ad9 100644 --- a/test/simulation/test.common +++ b/test/simulation/test.common @@ -391,9 +391,9 @@ check_packet_port() { for i in $(seq 1 $(get_chronyd_nodes)); do test_message 3 0 "node $i:" - grep -E -q " $port [0-9]+\$" tmp/log.packets && \ + grep -E -q "^([0-9e.+-]+ ){5}$port " tmp/log.packets && \ ! grep -E "^[0-9e.+-]+ $i " tmp/log.packets | \ - grep -E -q -v " $port [0-9]+\$" && \ + grep -E -q -v "^([0-9e.+-]+ ){5}$port " && \ test_ok || test_bad [ $? -eq 0 ] || ret=1 done -- cgit v1.2.3 From e2f966603013af49cee134c77eccb8380e92d324 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:40:44 +0100 Subject: rtc: simplify and move switch_interrupts() Gbp-Pq: Name rtc-simplify-and-move-switch_interrupts-function.patch --- rtc_linux.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index d4d9bd0..30833e5 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -527,6 +527,20 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) return RTC_ST_OK; } +/* ================================================== */ + +static void +switch_interrupts(int on_off) +{ + if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { + LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", + on_off ? "enable" : "disable", strerror(errno)); + return; + } + + if (on_off) + skip_interrupts = 1; +} /* ================================================== */ /* file_name is the name of the file where we save the RTC params @@ -603,29 +617,6 @@ RTC_Linux_Finalise(void) /* ================================================== */ -static void -switch_interrupts(int onoff) -{ - int status; - - if (onoff) { - status = ioctl(fd, RTC_UIE_ON, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "enable", strerror(errno)); - return; - } - skip_interrupts = 1; - } else { - status = ioctl(fd, RTC_UIE_OFF, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "disable", strerror(errno)); - return; - } - } -} - -/* ================================================== */ - static void measurement_timeout(void *any) { -- cgit v1.2.3 From cc2140108ca0b1dbaa05f6caf45ec0c155311fff Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:30:42 +0100 Subject: rtc: don't finalize driver if initialization failed Gbp-Pq: Name rtc-do-not-finalize-driver-if-initialization-failed.patch --- rtc.c | 2 +- rtc_linux.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rtc.c b/rtc.c index 33d04bf..fa83173 100644 --- a/rtc.c +++ b/rtc.c @@ -160,7 +160,7 @@ RTC_Initialise(int initial_set) void RTC_Finalise(void) { - if (driver.fini) { + if (driver_initialised) { (driver.fini)(); } } diff --git a/rtc_linux.c b/rtc_linux.c index 30833e5..c1a705d 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -550,6 +550,17 @@ switch_interrupts(int on_off) int RTC_Linux_Initialise(void) { + /* Try to open the device */ + fd = open(CNF_GetRtcDevice(), O_RDWR); + if (fd < 0) { + LOG(LOGS_ERR, "Could not open RTC device %s : %s", + CNF_GetRtcDevice(), strerror(errno)); + return 0; + } + + /* Close on exec */ + UTI_FdSetCloexec(fd); + rtc_sec = MallocArray(time_t, MAX_SAMPLES); rtc_trim = MallocArray(double, MAX_SAMPLES); system_times = MallocArray(struct timespec, MAX_SAMPLES); @@ -560,18 +571,6 @@ RTC_Linux_Initialise(void) /* In case it didn't get done by pre-init */ coefs_file_name = CNF_GetRtcFile(); - /* Try to open device */ - - fd = open (CNF_GetRtcDevice(), O_RDWR); - if (fd < 0) { - LOG(LOGS_ERR, "Could not open RTC device %s : %s", - CNF_GetRtcDevice(), strerror(errno)); - return 0; - } - - /* Close on exec */ - UTI_FdSetCloexec(fd); - n_samples = 0; n_samples_since_regression = 0; n_runs = 0; -- cgit v1.2.3 From 145173f0fe7edcc0fb53b6d52e3e943f8ea0a6fb Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:33:17 +0100 Subject: rtc: handle RTCs that don't support interrupts Some RTCs supported by the Linux kernel don't support the RTC_UIE_ON/OFF ioctls, which causes chronyd started with the -s option to get stuck in the initial RTC mode. After opening the RTC device in the initialization, return error if the ioctls are not supported to prevent the upper layer from calling the time_init() function and expecting it to finish. Gbp-Pq: Name rtc-handle-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index c1a705d..8b21394 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -529,17 +529,19 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) /* ================================================== */ -static void +static int switch_interrupts(int on_off) { if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", on_off ? "enable" : "disable", strerror(errno)); - return; + return 0; } if (on_off) skip_interrupts = 1; + + return 1; } /* ================================================== */ @@ -558,6 +560,12 @@ RTC_Linux_Initialise(void) return 0; } + /* Make sure the RTC supports interrupts */ + if (!switch_interrupts(0)) { + close(fd); + return 0; + } + /* Close on exec */ UTI_FdSetCloexec(fd); -- cgit v1.2.3 From 359ad299e3c526a6583c95c1af938b1fac579c6b Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:42:34 +0100 Subject: rtc: disable interrupts in finalization Don't leave interrupts enabled if chronyd is stopped when making an RTC measurement. Gbp-Pq: Name rtc-disable-interrupts-in-finalization.patch --- rtc_linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rtc_linux.c b/rtc_linux.c index 8b21394..7ec27c9 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -611,6 +611,7 @@ RTC_Linux_Finalise(void) /* Remove input file handler */ if (fd >= 0) { SCH_RemoveFileHandler(fd); + switch_interrupts(0); close(fd); /* Save the RTC data */ -- cgit v1.2.3 From 4f3e06e7f821f70a0416bb4fed92cf3c9c81de85 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:40 +0100 Subject: rtc: extend check for RTCs that don't support interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several RTCs would only expose the broken behavior on enabling interrupts. The reason for that is that the kernel only returns the error if the state changes. Therefore the check has to probe switch_interrupts(1) as well. On platforms that work it will be switched on and off, while on those it never works it will just stay off. Clocks known to expose that behavior include, but are not limited to: PPC64# dmesg | grep -i rtc    [    0.241872] rtc-generic rtc-generic: registered as rtc0 [    0.270221] rtc-generic rtc-generic: setting system clock to ... ARM64# dmesg | grep -i rtc [    0.876198] rtc-efi rtc-efi: registered as rtc0 [    1.046869] rtc-efi rtc-efi: setting system clock to ... Signed-off-by: Christian Ehrhardt Gbp-Pq: Name rtc-extend-check-for-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtc_linux.c b/rtc_linux.c index 7ec27c9..3220fad 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -561,7 +561,7 @@ RTC_Linux_Initialise(void) } /* Make sure the RTC supports interrupts */ - if (!switch_interrupts(0)) { + if (!switch_interrupts(1) || !switch_interrupts(0)) { close(fd); return 0; } -- cgit v1.2.3 From f5b1677f5aea806344a8c3a135afa9c24f35ea7b Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:39 +0100 Subject: test: accept test result if RTC can't enable RTC_UIE_ON The test might run on different platforms. If the platform happens to have a RTC that does exist but unable to have RTC_UIE_ON set the test will fail, while the chrony code is actually good. Examples of bad clocks are: - ppc64el: rtc-generic - arm64: rtc-efi To avoid that extend the log message check on 101-rtc to accept that condition as a valid test result as well. Signed-off-by: Christian Ehrhardt Gbp-Pq: Name test-accept-test-result-if-RTC-can-not-enable-RTC_UIE_ON.patch --- test/system/101-rtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/101-rtc b/test/system/101-rtc index fa9a70d..68bce68 100755 --- a/test/system/101-rtc +++ b/test/system/101-rtc @@ -14,6 +14,6 @@ echo "1 $(date +%s) 0.0 0.0" > "$TEST_DIR/rtcfile" start_chronyd || test_fail stop_chronyd || test_fail -check_chronyd_message_count "\(clock off from RTC\|RTC time before last\)" 1 1 || test_fail +check_chronyd_message_count "\(clock off from RTC\|RTC time before last\|Could not \(enable\|disable\) RTC interrupt\)" 1 1 || test_fail test_pass -- cgit v1.2.3 From 025212d4fee67c77a8f7cf3a9b5f423850b553a2 Mon Sep 17 00:00:00 2001 From: Vincent Blut Date: Thu, 16 Jan 2020 17:04:35 +0100 Subject: sys_linux: allow renameat2 in seccomp filter This is needed for architectures that support neither rename() nor renameat() (e.g. riscv64) Gbp-Pq: Name allow-renameat2-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index 898dc7a..ffbc9dd 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -493,8 +493,8 @@ SYS_Linux_EnableSystemCallFilter(int level) SCMP_SYS(chown32), SCMP_SYS(faccessat), SCMP_SYS(fchmodat), SCMP_SYS(fchownat), SCMP_SYS(fstat), SCMP_SYS(fstat64), SCMP_SYS(getdents), SCMP_SYS(getdents64), SCMP_SYS(lseek), SCMP_SYS(newfstatat), SCMP_SYS(rename), SCMP_SYS(renameat), - SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), SCMP_SYS(statfs64), - SCMP_SYS(unlink), SCMP_SYS(unlinkat), + SCMP_SYS(renameat2), SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), + SCMP_SYS(statfs64), SCMP_SYS(unlink), SCMP_SYS(unlinkat), /* Socket */ SCMP_SYS(bind), SCMP_SYS(connect), SCMP_SYS(getsockname), SCMP_SYS(getsockopt), SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), SCMP_SYS(recvmsg), -- cgit v1.2.3 From d13ed613924ef496f52ca917eae8fe20684c4b83 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 2 Dec 2019 12:47:13 +0100 Subject: sys_linux: allow clock_adjtime in seccomp filter The adjtimex() function in glibc was switched to the clock_adjtime system call. Gbp-Pq: Name allow-clock_adjtime-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index ffbc9dd..ee7ddc1 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -478,8 +478,8 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(clock_gettime), SCMP_SYS(gettimeofday), - SCMP_SYS(settimeofday), SCMP_SYS(time), + SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), SCMP_SYS(clock_gettime), + SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getpid), SCMP_SYS(getrlimit), SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigreturn), -- cgit v1.2.3 From 7486eca1e3ea39ef0af3e950d504e8141e767c20 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jun 2019 15:41:50 +0200 Subject: test: update processing of packet log Two new fields have been added to the packet log, which broke some of the simulation tests. Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=62d6aed6a64b887c9e3b7f03d9e0db1deaa2696a Gbp-Pq: Name update_processing_of_packet_log.patch --- test/simulation/test.common | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simulation/test.common b/test/simulation/test.common index 951a794..8ed6ad9 100644 --- a/test/simulation/test.common +++ b/test/simulation/test.common @@ -391,9 +391,9 @@ check_packet_port() { for i in $(seq 1 $(get_chronyd_nodes)); do test_message 3 0 "node $i:" - grep -E -q " $port [0-9]+\$" tmp/log.packets && \ + grep -E -q "^([0-9e.+-]+ ){5}$port " tmp/log.packets && \ ! grep -E "^[0-9e.+-]+ $i " tmp/log.packets | \ - grep -E -q -v " $port [0-9]+\$" && \ + grep -E -q -v "^([0-9e.+-]+ ){5}$port " && \ test_ok || test_bad [ $? -eq 0 ] || ret=1 done -- cgit v1.2.3 From 7fd207b94282444ac710408365abded4eac6adaf Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:40:44 +0100 Subject: rtc: simplify and move switch_interrupts() Gbp-Pq: Name rtc-simplify-and-move-switch_interrupts-function.patch --- rtc_linux.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index d4d9bd0..30833e5 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -527,6 +527,20 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) return RTC_ST_OK; } +/* ================================================== */ + +static void +switch_interrupts(int on_off) +{ + if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { + LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", + on_off ? "enable" : "disable", strerror(errno)); + return; + } + + if (on_off) + skip_interrupts = 1; +} /* ================================================== */ /* file_name is the name of the file where we save the RTC params @@ -603,29 +617,6 @@ RTC_Linux_Finalise(void) /* ================================================== */ -static void -switch_interrupts(int onoff) -{ - int status; - - if (onoff) { - status = ioctl(fd, RTC_UIE_ON, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "enable", strerror(errno)); - return; - } - skip_interrupts = 1; - } else { - status = ioctl(fd, RTC_UIE_OFF, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "disable", strerror(errno)); - return; - } - } -} - -/* ================================================== */ - static void measurement_timeout(void *any) { -- cgit v1.2.3 From a0caa17e57a06e1a20daa9fd109986823d33fa2c Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:30:42 +0100 Subject: rtc: don't finalize driver if initialization failed Gbp-Pq: Name rtc-do-not-finalize-driver-if-initialization-failed.patch --- rtc.c | 2 +- rtc_linux.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rtc.c b/rtc.c index 33d04bf..fa83173 100644 --- a/rtc.c +++ b/rtc.c @@ -160,7 +160,7 @@ RTC_Initialise(int initial_set) void RTC_Finalise(void) { - if (driver.fini) { + if (driver_initialised) { (driver.fini)(); } } diff --git a/rtc_linux.c b/rtc_linux.c index 30833e5..c1a705d 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -550,6 +550,17 @@ switch_interrupts(int on_off) int RTC_Linux_Initialise(void) { + /* Try to open the device */ + fd = open(CNF_GetRtcDevice(), O_RDWR); + if (fd < 0) { + LOG(LOGS_ERR, "Could not open RTC device %s : %s", + CNF_GetRtcDevice(), strerror(errno)); + return 0; + } + + /* Close on exec */ + UTI_FdSetCloexec(fd); + rtc_sec = MallocArray(time_t, MAX_SAMPLES); rtc_trim = MallocArray(double, MAX_SAMPLES); system_times = MallocArray(struct timespec, MAX_SAMPLES); @@ -560,18 +571,6 @@ RTC_Linux_Initialise(void) /* In case it didn't get done by pre-init */ coefs_file_name = CNF_GetRtcFile(); - /* Try to open device */ - - fd = open (CNF_GetRtcDevice(), O_RDWR); - if (fd < 0) { - LOG(LOGS_ERR, "Could not open RTC device %s : %s", - CNF_GetRtcDevice(), strerror(errno)); - return 0; - } - - /* Close on exec */ - UTI_FdSetCloexec(fd); - n_samples = 0; n_samples_since_regression = 0; n_runs = 0; -- cgit v1.2.3 From 817d29420d94d956b10a2d31cfc91f0ee18adf2e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:33:17 +0100 Subject: rtc: handle RTCs that don't support interrupts Some RTCs supported by the Linux kernel don't support the RTC_UIE_ON/OFF ioctls, which causes chronyd started with the -s option to get stuck in the initial RTC mode. After opening the RTC device in the initialization, return error if the ioctls are not supported to prevent the upper layer from calling the time_init() function and expecting it to finish. Gbp-Pq: Name rtc-handle-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index c1a705d..8b21394 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -529,17 +529,19 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) /* ================================================== */ -static void +static int switch_interrupts(int on_off) { if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", on_off ? "enable" : "disable", strerror(errno)); - return; + return 0; } if (on_off) skip_interrupts = 1; + + return 1; } /* ================================================== */ @@ -558,6 +560,12 @@ RTC_Linux_Initialise(void) return 0; } + /* Make sure the RTC supports interrupts */ + if (!switch_interrupts(0)) { + close(fd); + return 0; + } + /* Close on exec */ UTI_FdSetCloexec(fd); -- cgit v1.2.3 From 5b6948c0bf14fcda499250da1f63403ffcd3c87e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:42:34 +0100 Subject: rtc: disable interrupts in finalization Don't leave interrupts enabled if chronyd is stopped when making an RTC measurement. Gbp-Pq: Name rtc-disable-interrupts-in-finalization.patch --- rtc_linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rtc_linux.c b/rtc_linux.c index 8b21394..7ec27c9 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -611,6 +611,7 @@ RTC_Linux_Finalise(void) /* Remove input file handler */ if (fd >= 0) { SCH_RemoveFileHandler(fd); + switch_interrupts(0); close(fd); /* Save the RTC data */ -- cgit v1.2.3 From ef445330c712564c68b10fdc730e54b6fedf3840 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:40 +0100 Subject: rtc: extend check for RTCs that don't support interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several RTCs would only expose the broken behavior on enabling interrupts. The reason for that is that the kernel only returns the error if the state changes. Therefore the check has to probe switch_interrupts(1) as well. On platforms that work it will be switched on and off, while on those it never works it will just stay off. Clocks known to expose that behavior include, but are not limited to: PPC64# dmesg | grep -i rtc    [    0.241872] rtc-generic rtc-generic: registered as rtc0 [    0.270221] rtc-generic rtc-generic: setting system clock to ... ARM64# dmesg | grep -i rtc [    0.876198] rtc-efi rtc-efi: registered as rtc0 [    1.046869] rtc-efi rtc-efi: setting system clock to ... Signed-off-by: Christian Ehrhardt Gbp-Pq: Name rtc-extend-check-for-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtc_linux.c b/rtc_linux.c index 7ec27c9..3220fad 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -561,7 +561,7 @@ RTC_Linux_Initialise(void) } /* Make sure the RTC supports interrupts */ - if (!switch_interrupts(0)) { + if (!switch_interrupts(1) || !switch_interrupts(0)) { close(fd); return 0; } -- cgit v1.2.3 From d07c50f170898d714415fcf355ba3bed23b633ad Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:39 +0100 Subject: test: accept test result if RTC can't enable RTC_UIE_ON The test might run on different platforms. If the platform happens to have a RTC that does exist but unable to have RTC_UIE_ON set the test will fail, while the chrony code is actually good. Examples of bad clocks are: - ppc64el: rtc-generic - arm64: rtc-efi To avoid that extend the log message check on 101-rtc to accept that condition as a valid test result as well. Signed-off-by: Christian Ehrhardt Gbp-Pq: Name test-accept-test-result-if-RTC-can-not-enable-RTC_UIE_ON.patch --- test/system/101-rtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/101-rtc b/test/system/101-rtc index fa9a70d..68bce68 100755 --- a/test/system/101-rtc +++ b/test/system/101-rtc @@ -14,6 +14,6 @@ echo "1 $(date +%s) 0.0 0.0" > "$TEST_DIR/rtcfile" start_chronyd || test_fail stop_chronyd || test_fail -check_chronyd_message_count "\(clock off from RTC\|RTC time before last\)" 1 1 || test_fail +check_chronyd_message_count "\(clock off from RTC\|RTC time before last\|Could not \(enable\|disable\) RTC interrupt\)" 1 1 || test_fail test_pass -- cgit v1.2.3 From 66260f6e750b919e8a1eb1c1811f678e1f4e4d28 Mon Sep 17 00:00:00 2001 From: Vincent Blut Date: Thu, 16 Jan 2020 17:04:35 +0100 Subject: sys_linux: allow renameat2 in seccomp filter This is needed for architectures that support neither rename() nor renameat() (e.g. riscv64) Gbp-Pq: Name allow-renameat2-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index 898dc7a..ffbc9dd 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -493,8 +493,8 @@ SYS_Linux_EnableSystemCallFilter(int level) SCMP_SYS(chown32), SCMP_SYS(faccessat), SCMP_SYS(fchmodat), SCMP_SYS(fchownat), SCMP_SYS(fstat), SCMP_SYS(fstat64), SCMP_SYS(getdents), SCMP_SYS(getdents64), SCMP_SYS(lseek), SCMP_SYS(newfstatat), SCMP_SYS(rename), SCMP_SYS(renameat), - SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), SCMP_SYS(statfs64), - SCMP_SYS(unlink), SCMP_SYS(unlinkat), + SCMP_SYS(renameat2), SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), + SCMP_SYS(statfs64), SCMP_SYS(unlink), SCMP_SYS(unlinkat), /* Socket */ SCMP_SYS(bind), SCMP_SYS(connect), SCMP_SYS(getsockname), SCMP_SYS(getsockopt), SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), SCMP_SYS(recvmsg), -- cgit v1.2.3 From 3f905d4b5543ff43dccde02368299361e25312b5 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 2 Dec 2019 12:47:13 +0100 Subject: sys_linux: allow clock_adjtime in seccomp filter The adjtimex() function in glibc was switched to the clock_adjtime system call. Gbp-Pq: Name allow-clock_adjtime-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index ffbc9dd..ee7ddc1 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -478,8 +478,8 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(clock_gettime), SCMP_SYS(gettimeofday), - SCMP_SYS(settimeofday), SCMP_SYS(time), + SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), SCMP_SYS(clock_gettime), + SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getpid), SCMP_SYS(getrlimit), SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigreturn), -- cgit v1.2.3 From f41a777a53542219611500d53ef4e9c63394922a Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jun 2019 15:41:50 +0200 Subject: test: update processing of packet log Two new fields have been added to the packet log, which broke some of the simulation tests. Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=62d6aed6a64b887c9e3b7f03d9e0db1deaa2696a Gbp-Pq: Name update_processing_of_packet_log.patch --- test/simulation/test.common | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simulation/test.common b/test/simulation/test.common index 951a794..8ed6ad9 100644 --- a/test/simulation/test.common +++ b/test/simulation/test.common @@ -391,9 +391,9 @@ check_packet_port() { for i in $(seq 1 $(get_chronyd_nodes)); do test_message 3 0 "node $i:" - grep -E -q " $port [0-9]+\$" tmp/log.packets && \ + grep -E -q "^([0-9e.+-]+ ){5}$port " tmp/log.packets && \ ! grep -E "^[0-9e.+-]+ $i " tmp/log.packets | \ - grep -E -q -v " $port [0-9]+\$" && \ + grep -E -q -v "^([0-9e.+-]+ ){5}$port " && \ test_ok || test_bad [ $? -eq 0 ] || ret=1 done -- cgit v1.2.3 From d7ff44d7feac74eef58fd2b89bb2531c0dd35087 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:40:44 +0100 Subject: rtc: simplify and move switch_interrupts() Gbp-Pq: Name rtc-simplify-and-move-switch_interrupts-function.patch --- rtc_linux.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index d4d9bd0..30833e5 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -527,6 +527,20 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) return RTC_ST_OK; } +/* ================================================== */ + +static void +switch_interrupts(int on_off) +{ + if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { + LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", + on_off ? "enable" : "disable", strerror(errno)); + return; + } + + if (on_off) + skip_interrupts = 1; +} /* ================================================== */ /* file_name is the name of the file where we save the RTC params @@ -603,29 +617,6 @@ RTC_Linux_Finalise(void) /* ================================================== */ -static void -switch_interrupts(int onoff) -{ - int status; - - if (onoff) { - status = ioctl(fd, RTC_UIE_ON, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "enable", strerror(errno)); - return; - } - skip_interrupts = 1; - } else { - status = ioctl(fd, RTC_UIE_OFF, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "disable", strerror(errno)); - return; - } - } -} - -/* ================================================== */ - static void measurement_timeout(void *any) { -- cgit v1.2.3 From 93e6ebb126d0e1b81914e350210e1b09c3e3f295 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:30:42 +0100 Subject: rtc: don't finalize driver if initialization failed Gbp-Pq: Name rtc-do-not-finalize-driver-if-initialization-failed.patch --- rtc.c | 2 +- rtc_linux.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rtc.c b/rtc.c index 33d04bf..fa83173 100644 --- a/rtc.c +++ b/rtc.c @@ -160,7 +160,7 @@ RTC_Initialise(int initial_set) void RTC_Finalise(void) { - if (driver.fini) { + if (driver_initialised) { (driver.fini)(); } } diff --git a/rtc_linux.c b/rtc_linux.c index 30833e5..c1a705d 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -550,6 +550,17 @@ switch_interrupts(int on_off) int RTC_Linux_Initialise(void) { + /* Try to open the device */ + fd = open(CNF_GetRtcDevice(), O_RDWR); + if (fd < 0) { + LOG(LOGS_ERR, "Could not open RTC device %s : %s", + CNF_GetRtcDevice(), strerror(errno)); + return 0; + } + + /* Close on exec */ + UTI_FdSetCloexec(fd); + rtc_sec = MallocArray(time_t, MAX_SAMPLES); rtc_trim = MallocArray(double, MAX_SAMPLES); system_times = MallocArray(struct timespec, MAX_SAMPLES); @@ -560,18 +571,6 @@ RTC_Linux_Initialise(void) /* In case it didn't get done by pre-init */ coefs_file_name = CNF_GetRtcFile(); - /* Try to open device */ - - fd = open (CNF_GetRtcDevice(), O_RDWR); - if (fd < 0) { - LOG(LOGS_ERR, "Could not open RTC device %s : %s", - CNF_GetRtcDevice(), strerror(errno)); - return 0; - } - - /* Close on exec */ - UTI_FdSetCloexec(fd); - n_samples = 0; n_samples_since_regression = 0; n_runs = 0; -- cgit v1.2.3 From 13da0b62b52f8bceafed70f7d52562c01614a989 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:33:17 +0100 Subject: rtc: handle RTCs that don't support interrupts Some RTCs supported by the Linux kernel don't support the RTC_UIE_ON/OFF ioctls, which causes chronyd started with the -s option to get stuck in the initial RTC mode. After opening the RTC device in the initialization, return error if the ioctls are not supported to prevent the upper layer from calling the time_init() function and expecting it to finish. Gbp-Pq: Name rtc-handle-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index c1a705d..8b21394 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -529,17 +529,19 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) /* ================================================== */ -static void +static int switch_interrupts(int on_off) { if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", on_off ? "enable" : "disable", strerror(errno)); - return; + return 0; } if (on_off) skip_interrupts = 1; + + return 1; } /* ================================================== */ @@ -558,6 +560,12 @@ RTC_Linux_Initialise(void) return 0; } + /* Make sure the RTC supports interrupts */ + if (!switch_interrupts(0)) { + close(fd); + return 0; + } + /* Close on exec */ UTI_FdSetCloexec(fd); -- cgit v1.2.3 From 2c9a18beb8d1fc261d99045500adf137b8ebcd3e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:42:34 +0100 Subject: rtc: disable interrupts in finalization Don't leave interrupts enabled if chronyd is stopped when making an RTC measurement. Gbp-Pq: Name rtc-disable-interrupts-in-finalization.patch --- rtc_linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rtc_linux.c b/rtc_linux.c index 8b21394..7ec27c9 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -611,6 +611,7 @@ RTC_Linux_Finalise(void) /* Remove input file handler */ if (fd >= 0) { SCH_RemoveFileHandler(fd); + switch_interrupts(0); close(fd); /* Save the RTC data */ -- cgit v1.2.3 From 2a5c3283114af06e2a4d4a1885bd98cf993b82c1 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:40 +0100 Subject: rtc: extend check for RTCs that don't support interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several RTCs would only expose the broken behavior on enabling interrupts. The reason for that is that the kernel only returns the error if the state changes. Therefore the check has to probe switch_interrupts(1) as well. On platforms that work it will be switched on and off, while on those it never works it will just stay off. Clocks known to expose that behavior include, but are not limited to: PPC64# dmesg | grep -i rtc    [    0.241872] rtc-generic rtc-generic: registered as rtc0 [    0.270221] rtc-generic rtc-generic: setting system clock to ... ARM64# dmesg | grep -i rtc [    0.876198] rtc-efi rtc-efi: registered as rtc0 [    1.046869] rtc-efi rtc-efi: setting system clock to ... Signed-off-by: Christian Ehrhardt Gbp-Pq: Name rtc-extend-check-for-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtc_linux.c b/rtc_linux.c index 7ec27c9..3220fad 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -561,7 +561,7 @@ RTC_Linux_Initialise(void) } /* Make sure the RTC supports interrupts */ - if (!switch_interrupts(0)) { + if (!switch_interrupts(1) || !switch_interrupts(0)) { close(fd); return 0; } -- cgit v1.2.3 From 5eb954cc4b8182426741292050e355677bcc621b Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:39 +0100 Subject: test: accept test result if RTC can't enable RTC_UIE_ON The test might run on different platforms. If the platform happens to have a RTC that does exist but unable to have RTC_UIE_ON set the test will fail, while the chrony code is actually good. Examples of bad clocks are: - ppc64el: rtc-generic - arm64: rtc-efi To avoid that extend the log message check on 101-rtc to accept that condition as a valid test result as well. Signed-off-by: Christian Ehrhardt Gbp-Pq: Name test-accept-test-result-if-RTC-can-not-enable-RTC_UIE_ON.patch --- test/system/101-rtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/101-rtc b/test/system/101-rtc index fa9a70d..68bce68 100755 --- a/test/system/101-rtc +++ b/test/system/101-rtc @@ -14,6 +14,6 @@ echo "1 $(date +%s) 0.0 0.0" > "$TEST_DIR/rtcfile" start_chronyd || test_fail stop_chronyd || test_fail -check_chronyd_message_count "\(clock off from RTC\|RTC time before last\)" 1 1 || test_fail +check_chronyd_message_count "\(clock off from RTC\|RTC time before last\|Could not \(enable\|disable\) RTC interrupt\)" 1 1 || test_fail test_pass -- cgit v1.2.3 From 0c9ea3e3dce1d6818b6e1bff6b57c1a93ed5b642 Mon Sep 17 00:00:00 2001 From: Vincent Blut Date: Thu, 16 Jan 2020 17:04:35 +0100 Subject: sys_linux: allow renameat2 in seccomp filter This is needed for architectures that support neither rename() nor renameat() (e.g. riscv64) Gbp-Pq: Name allow-renameat2-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index 898dc7a..ffbc9dd 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -493,8 +493,8 @@ SYS_Linux_EnableSystemCallFilter(int level) SCMP_SYS(chown32), SCMP_SYS(faccessat), SCMP_SYS(fchmodat), SCMP_SYS(fchownat), SCMP_SYS(fstat), SCMP_SYS(fstat64), SCMP_SYS(getdents), SCMP_SYS(getdents64), SCMP_SYS(lseek), SCMP_SYS(newfstatat), SCMP_SYS(rename), SCMP_SYS(renameat), - SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), SCMP_SYS(statfs64), - SCMP_SYS(unlink), SCMP_SYS(unlinkat), + SCMP_SYS(renameat2), SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), + SCMP_SYS(statfs64), SCMP_SYS(unlink), SCMP_SYS(unlinkat), /* Socket */ SCMP_SYS(bind), SCMP_SYS(connect), SCMP_SYS(getsockname), SCMP_SYS(getsockopt), SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), SCMP_SYS(recvmsg), -- cgit v1.2.3 From 5cdafedb62634223be0cacb3ca556cb16a40c6a1 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 2 Dec 2019 12:47:13 +0100 Subject: sys_linux: allow clock_adjtime in seccomp filter The adjtimex() function in glibc was switched to the clock_adjtime system call. Gbp-Pq: Name allow-clock_adjtime-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index ffbc9dd..ee7ddc1 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -478,8 +478,8 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(clock_gettime), SCMP_SYS(gettimeofday), - SCMP_SYS(settimeofday), SCMP_SYS(time), + SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), SCMP_SYS(clock_gettime), + SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getpid), SCMP_SYS(getrlimit), SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigreturn), -- cgit v1.2.3 From e5870485ae58b42093f43e10021fa1d7f9cf7494 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jun 2019 15:41:50 +0200 Subject: test: update processing of packet log Two new fields have been added to the packet log, which broke some of the simulation tests. Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=62d6aed6a64b887c9e3b7f03d9e0db1deaa2696a Gbp-Pq: Name update_processing_of_packet_log.patch --- test/simulation/test.common | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simulation/test.common b/test/simulation/test.common index 951a794..8ed6ad9 100644 --- a/test/simulation/test.common +++ b/test/simulation/test.common @@ -391,9 +391,9 @@ check_packet_port() { for i in $(seq 1 $(get_chronyd_nodes)); do test_message 3 0 "node $i:" - grep -E -q " $port [0-9]+\$" tmp/log.packets && \ + grep -E -q "^([0-9e.+-]+ ){5}$port " tmp/log.packets && \ ! grep -E "^[0-9e.+-]+ $i " tmp/log.packets | \ - grep -E -q -v " $port [0-9]+\$" && \ + grep -E -q -v "^([0-9e.+-]+ ){5}$port " && \ test_ok || test_bad [ $? -eq 0 ] || ret=1 done -- cgit v1.2.3 From 676e0fc1642fee103d62b0c326fa61173b7fb744 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:40:44 +0100 Subject: rtc: simplify and move switch_interrupts() Gbp-Pq: Name rtc-simplify-and-move-switch_interrupts-function.patch --- rtc_linux.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index d4d9bd0..30833e5 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -527,6 +527,20 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) return RTC_ST_OK; } +/* ================================================== */ + +static void +switch_interrupts(int on_off) +{ + if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { + LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", + on_off ? "enable" : "disable", strerror(errno)); + return; + } + + if (on_off) + skip_interrupts = 1; +} /* ================================================== */ /* file_name is the name of the file where we save the RTC params @@ -603,29 +617,6 @@ RTC_Linux_Finalise(void) /* ================================================== */ -static void -switch_interrupts(int onoff) -{ - int status; - - if (onoff) { - status = ioctl(fd, RTC_UIE_ON, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "enable", strerror(errno)); - return; - } - skip_interrupts = 1; - } else { - status = ioctl(fd, RTC_UIE_OFF, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "disable", strerror(errno)); - return; - } - } -} - -/* ================================================== */ - static void measurement_timeout(void *any) { -- cgit v1.2.3 From 0bcfc59bb84a63cfc454027d98fbd4fdb9658af6 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:30:42 +0100 Subject: rtc: don't finalize driver if initialization failed Gbp-Pq: Name rtc-do-not-finalize-driver-if-initialization-failed.patch --- rtc.c | 2 +- rtc_linux.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rtc.c b/rtc.c index 33d04bf..fa83173 100644 --- a/rtc.c +++ b/rtc.c @@ -160,7 +160,7 @@ RTC_Initialise(int initial_set) void RTC_Finalise(void) { - if (driver.fini) { + if (driver_initialised) { (driver.fini)(); } } diff --git a/rtc_linux.c b/rtc_linux.c index 30833e5..c1a705d 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -550,6 +550,17 @@ switch_interrupts(int on_off) int RTC_Linux_Initialise(void) { + /* Try to open the device */ + fd = open(CNF_GetRtcDevice(), O_RDWR); + if (fd < 0) { + LOG(LOGS_ERR, "Could not open RTC device %s : %s", + CNF_GetRtcDevice(), strerror(errno)); + return 0; + } + + /* Close on exec */ + UTI_FdSetCloexec(fd); + rtc_sec = MallocArray(time_t, MAX_SAMPLES); rtc_trim = MallocArray(double, MAX_SAMPLES); system_times = MallocArray(struct timespec, MAX_SAMPLES); @@ -560,18 +571,6 @@ RTC_Linux_Initialise(void) /* In case it didn't get done by pre-init */ coefs_file_name = CNF_GetRtcFile(); - /* Try to open device */ - - fd = open (CNF_GetRtcDevice(), O_RDWR); - if (fd < 0) { - LOG(LOGS_ERR, "Could not open RTC device %s : %s", - CNF_GetRtcDevice(), strerror(errno)); - return 0; - } - - /* Close on exec */ - UTI_FdSetCloexec(fd); - n_samples = 0; n_samples_since_regression = 0; n_runs = 0; -- cgit v1.2.3 From 803f856c5af0300a4bd5e100442ec7542435088e Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:33:17 +0100 Subject: rtc: handle RTCs that don't support interrupts Some RTCs supported by the Linux kernel don't support the RTC_UIE_ON/OFF ioctls, which causes chronyd started with the -s option to get stuck in the initial RTC mode. After opening the RTC device in the initialization, return error if the ioctls are not supported to prevent the upper layer from calling the time_init() function and expecting it to finish. Gbp-Pq: Name rtc-handle-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index c1a705d..8b21394 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -529,17 +529,19 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) /* ================================================== */ -static void +static int switch_interrupts(int on_off) { if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", on_off ? "enable" : "disable", strerror(errno)); - return; + return 0; } if (on_off) skip_interrupts = 1; + + return 1; } /* ================================================== */ @@ -558,6 +560,12 @@ RTC_Linux_Initialise(void) return 0; } + /* Make sure the RTC supports interrupts */ + if (!switch_interrupts(0)) { + close(fd); + return 0; + } + /* Close on exec */ UTI_FdSetCloexec(fd); -- cgit v1.2.3 From 2c2cbef8935f5b30e44d986d5b3fa74b46af3a06 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:42:34 +0100 Subject: rtc: disable interrupts in finalization Don't leave interrupts enabled if chronyd is stopped when making an RTC measurement. Gbp-Pq: Name rtc-disable-interrupts-in-finalization.patch --- rtc_linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rtc_linux.c b/rtc_linux.c index 8b21394..7ec27c9 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -611,6 +611,7 @@ RTC_Linux_Finalise(void) /* Remove input file handler */ if (fd >= 0) { SCH_RemoveFileHandler(fd); + switch_interrupts(0); close(fd); /* Save the RTC data */ -- cgit v1.2.3 From 5e1af24a62252a08770a89fb172c43a5ff7d6089 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:40 +0100 Subject: rtc: extend check for RTCs that don't support interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several RTCs would only expose the broken behavior on enabling interrupts. The reason for that is that the kernel only returns the error if the state changes. Therefore the check has to probe switch_interrupts(1) as well. On platforms that work it will be switched on and off, while on those it never works it will just stay off. Clocks known to expose that behavior include, but are not limited to: PPC64# dmesg | grep -i rtc    [    0.241872] rtc-generic rtc-generic: registered as rtc0 [    0.270221] rtc-generic rtc-generic: setting system clock to ... ARM64# dmesg | grep -i rtc [    0.876198] rtc-efi rtc-efi: registered as rtc0 [    1.046869] rtc-efi rtc-efi: setting system clock to ... Signed-off-by: Christian Ehrhardt Gbp-Pq: Name rtc-extend-check-for-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtc_linux.c b/rtc_linux.c index 7ec27c9..3220fad 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -561,7 +561,7 @@ RTC_Linux_Initialise(void) } /* Make sure the RTC supports interrupts */ - if (!switch_interrupts(0)) { + if (!switch_interrupts(1) || !switch_interrupts(0)) { close(fd); return 0; } -- cgit v1.2.3 From 234358e0d64290bb5a3f8eaffb0a484b0f28c316 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:39 +0100 Subject: test: accept test result if RTC can't enable RTC_UIE_ON The test might run on different platforms. If the platform happens to have a RTC that does exist but unable to have RTC_UIE_ON set the test will fail, while the chrony code is actually good. Examples of bad clocks are: - ppc64el: rtc-generic - arm64: rtc-efi To avoid that extend the log message check on 101-rtc to accept that condition as a valid test result as well. Signed-off-by: Christian Ehrhardt Gbp-Pq: Name test-accept-test-result-if-RTC-can-not-enable-RTC_UIE_ON.patch --- test/system/101-rtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/101-rtc b/test/system/101-rtc index fa9a70d..68bce68 100755 --- a/test/system/101-rtc +++ b/test/system/101-rtc @@ -14,6 +14,6 @@ echo "1 $(date +%s) 0.0 0.0" > "$TEST_DIR/rtcfile" start_chronyd || test_fail stop_chronyd || test_fail -check_chronyd_message_count "\(clock off from RTC\|RTC time before last\)" 1 1 || test_fail +check_chronyd_message_count "\(clock off from RTC\|RTC time before last\|Could not \(enable\|disable\) RTC interrupt\)" 1 1 || test_fail test_pass -- cgit v1.2.3 From ad2b1605261d779dbf40b7043bac040e9a743e0d Mon Sep 17 00:00:00 2001 From: Vincent Blut Date: Tue, 19 May 2020 16:42:18 +0200 Subject: allow some *time64 syscalls in seccomp filter Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/chrony/+bug/1878005 Forwarded: https://www.mail-archive.com/chrony-dev@chrony.tuxfamily.org/msg02172.html Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=7a7295992f76def739f0110f1e8f1346ff3a032e Last-Update: 2020-05-18 Allowing these system calls is required for 32-bit architectures with new system calls using 64-bit time_t. Last-Update: 2020-05-18 Gbp-Pq: Name allow-some-*time64-syscalls-in-seccomp-filter.patch --- sys_linux.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index ee7ddc1..931dd95 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -478,7 +478,14 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), SCMP_SYS(clock_gettime), + SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), +#ifdef __NR_clock_adjtime64 + SCMP_SYS(clock_adjtime64), +#endif + SCMP_SYS(clock_gettime), +#ifdef __NR_clock_gettime64 + SCMP_SYS(clock_gettime64), +#endif SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getpid), @@ -497,14 +504,29 @@ SYS_Linux_EnableSystemCallFilter(int level) SCMP_SYS(statfs64), SCMP_SYS(unlink), SCMP_SYS(unlinkat), /* Socket */ SCMP_SYS(bind), SCMP_SYS(connect), SCMP_SYS(getsockname), SCMP_SYS(getsockopt), - SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), SCMP_SYS(recvmsg), + SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), +#ifdef __NR_recvmmsg_time64 + SCMP_SYS(recvmmsg_time64), +#endif + SCMP_SYS(recvmsg), SCMP_SYS(send), SCMP_SYS(sendmmsg), SCMP_SYS(sendmsg), SCMP_SYS(sendto), /* TODO: check socketcall arguments */ SCMP_SYS(socketcall), /* General I/O */ SCMP_SYS(_newselect), SCMP_SYS(close), SCMP_SYS(open), SCMP_SYS(openat), SCMP_SYS(pipe), - SCMP_SYS(pipe2), SCMP_SYS(poll), SCMP_SYS(ppoll), SCMP_SYS(pselect6), SCMP_SYS(read), - SCMP_SYS(futex), SCMP_SYS(select), SCMP_SYS(set_robust_list), SCMP_SYS(write), + SCMP_SYS(pipe2), SCMP_SYS(poll), SCMP_SYS(ppoll), +#ifdef __NR_ppoll_time64 + SCMP_SYS(ppoll_time64), +#endif + SCMP_SYS(pselect6), +#ifdef __NR_pselect6_time64 + SCMP_SYS(pselect6_time64), +#endif + SCMP_SYS(read), SCMP_SYS(futex), +#ifdef __NR_futex_time64 + SCMP_SYS(futex_time64), +#endif + SCMP_SYS(select), SCMP_SYS(set_robust_list), SCMP_SYS(write), /* Miscellaneous */ SCMP_SYS(getrandom), SCMP_SYS(sysinfo), SCMP_SYS(uname), }; -- cgit v1.2.3 From bd16a78b97c6cd9538ac951a88f447308eac7dc2 Mon Sep 17 00:00:00 2001 From: Vincent Blut Date: Thu, 16 Jan 2020 17:04:35 +0100 Subject: sys_linux: allow renameat2 in seccomp filter This is needed for architectures that support neither rename() nor renameat() (e.g. riscv64) Gbp-Pq: Name allow-renameat2-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index 898dc7a..ffbc9dd 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -493,8 +493,8 @@ SYS_Linux_EnableSystemCallFilter(int level) SCMP_SYS(chown32), SCMP_SYS(faccessat), SCMP_SYS(fchmodat), SCMP_SYS(fchownat), SCMP_SYS(fstat), SCMP_SYS(fstat64), SCMP_SYS(getdents), SCMP_SYS(getdents64), SCMP_SYS(lseek), SCMP_SYS(newfstatat), SCMP_SYS(rename), SCMP_SYS(renameat), - SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), SCMP_SYS(statfs64), - SCMP_SYS(unlink), SCMP_SYS(unlinkat), + SCMP_SYS(renameat2), SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), + SCMP_SYS(statfs64), SCMP_SYS(unlink), SCMP_SYS(unlinkat), /* Socket */ SCMP_SYS(bind), SCMP_SYS(connect), SCMP_SYS(getsockname), SCMP_SYS(getsockopt), SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), SCMP_SYS(recvmsg), -- cgit v1.2.3 From 0a492d6d9b298269a641603fc430487c955add27 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 2 Dec 2019 12:47:13 +0100 Subject: sys_linux: allow clock_adjtime in seccomp filter The adjtimex() function in glibc was switched to the clock_adjtime system call. Gbp-Pq: Name allow-clock_adjtime-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index ffbc9dd..ee7ddc1 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -478,8 +478,8 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(clock_gettime), SCMP_SYS(gettimeofday), - SCMP_SYS(settimeofday), SCMP_SYS(time), + SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), SCMP_SYS(clock_gettime), + SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getpid), SCMP_SYS(getrlimit), SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigreturn), -- cgit v1.2.3 From 7af939955fa2d3e4e86ddda359afc8fed3f51b72 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jun 2019 15:41:50 +0200 Subject: test: update processing of packet log Two new fields have been added to the packet log, which broke some of the simulation tests. Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=62d6aed6a64b887c9e3b7f03d9e0db1deaa2696a Gbp-Pq: Name update_processing_of_packet_log.patch --- test/simulation/test.common | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simulation/test.common b/test/simulation/test.common index 951a794..8ed6ad9 100644 --- a/test/simulation/test.common +++ b/test/simulation/test.common @@ -391,9 +391,9 @@ check_packet_port() { for i in $(seq 1 $(get_chronyd_nodes)); do test_message 3 0 "node $i:" - grep -E -q " $port [0-9]+\$" tmp/log.packets && \ + grep -E -q "^([0-9e.+-]+ ){5}$port " tmp/log.packets && \ ! grep -E "^[0-9e.+-]+ $i " tmp/log.packets | \ - grep -E -q -v " $port [0-9]+\$" && \ + grep -E -q -v "^([0-9e.+-]+ ){5}$port " && \ test_ok || test_bad [ $? -eq 0 ] || ret=1 done -- cgit v1.2.3 From 773362c5f07ffd5f8eab018cce076ce24e61b261 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:40:44 +0100 Subject: rtc: simplify and move switch_interrupts() Gbp-Pq: Name rtc-simplify-and-move-switch_interrupts-function.patch --- rtc_linux.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index d4d9bd0..30833e5 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -527,6 +527,20 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) return RTC_ST_OK; } +/* ================================================== */ + +static void +switch_interrupts(int on_off) +{ + if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { + LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", + on_off ? "enable" : "disable", strerror(errno)); + return; + } + + if (on_off) + skip_interrupts = 1; +} /* ================================================== */ /* file_name is the name of the file where we save the RTC params @@ -603,29 +617,6 @@ RTC_Linux_Finalise(void) /* ================================================== */ -static void -switch_interrupts(int onoff) -{ - int status; - - if (onoff) { - status = ioctl(fd, RTC_UIE_ON, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "enable", strerror(errno)); - return; - } - skip_interrupts = 1; - } else { - status = ioctl(fd, RTC_UIE_OFF, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "disable", strerror(errno)); - return; - } - } -} - -/* ================================================== */ - static void measurement_timeout(void *any) { -- cgit v1.2.3 From 1e2687c9892b75536dec3f0556beb65503e3635d Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:30:42 +0100 Subject: rtc: don't finalize driver if initialization failed Gbp-Pq: Name rtc-do-not-finalize-driver-if-initialization-failed.patch --- rtc.c | 2 +- rtc_linux.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rtc.c b/rtc.c index 33d04bf..fa83173 100644 --- a/rtc.c +++ b/rtc.c @@ -160,7 +160,7 @@ RTC_Initialise(int initial_set) void RTC_Finalise(void) { - if (driver.fini) { + if (driver_initialised) { (driver.fini)(); } } diff --git a/rtc_linux.c b/rtc_linux.c index 30833e5..c1a705d 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -550,6 +550,17 @@ switch_interrupts(int on_off) int RTC_Linux_Initialise(void) { + /* Try to open the device */ + fd = open(CNF_GetRtcDevice(), O_RDWR); + if (fd < 0) { + LOG(LOGS_ERR, "Could not open RTC device %s : %s", + CNF_GetRtcDevice(), strerror(errno)); + return 0; + } + + /* Close on exec */ + UTI_FdSetCloexec(fd); + rtc_sec = MallocArray(time_t, MAX_SAMPLES); rtc_trim = MallocArray(double, MAX_SAMPLES); system_times = MallocArray(struct timespec, MAX_SAMPLES); @@ -560,18 +571,6 @@ RTC_Linux_Initialise(void) /* In case it didn't get done by pre-init */ coefs_file_name = CNF_GetRtcFile(); - /* Try to open device */ - - fd = open (CNF_GetRtcDevice(), O_RDWR); - if (fd < 0) { - LOG(LOGS_ERR, "Could not open RTC device %s : %s", - CNF_GetRtcDevice(), strerror(errno)); - return 0; - } - - /* Close on exec */ - UTI_FdSetCloexec(fd); - n_samples = 0; n_samples_since_regression = 0; n_runs = 0; -- cgit v1.2.3 From 979e056fce3dc21d2933e6396cdeb5503c628b0d Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:33:17 +0100 Subject: rtc: handle RTCs that don't support interrupts Some RTCs supported by the Linux kernel don't support the RTC_UIE_ON/OFF ioctls, which causes chronyd started with the -s option to get stuck in the initial RTC mode. After opening the RTC device in the initialization, return error if the ioctls are not supported to prevent the upper layer from calling the time_init() function and expecting it to finish. Gbp-Pq: Name rtc-handle-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index c1a705d..8b21394 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -529,17 +529,19 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) /* ================================================== */ -static void +static int switch_interrupts(int on_off) { if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", on_off ? "enable" : "disable", strerror(errno)); - return; + return 0; } if (on_off) skip_interrupts = 1; + + return 1; } /* ================================================== */ @@ -558,6 +560,12 @@ RTC_Linux_Initialise(void) return 0; } + /* Make sure the RTC supports interrupts */ + if (!switch_interrupts(0)) { + close(fd); + return 0; + } + /* Close on exec */ UTI_FdSetCloexec(fd); -- cgit v1.2.3 From 3e128f9b669b598099536bc375ce443122bc0926 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:42:34 +0100 Subject: rtc: disable interrupts in finalization Don't leave interrupts enabled if chronyd is stopped when making an RTC measurement. Gbp-Pq: Name rtc-disable-interrupts-in-finalization.patch --- rtc_linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rtc_linux.c b/rtc_linux.c index 8b21394..7ec27c9 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -611,6 +611,7 @@ RTC_Linux_Finalise(void) /* Remove input file handler */ if (fd >= 0) { SCH_RemoveFileHandler(fd); + switch_interrupts(0); close(fd); /* Save the RTC data */ -- cgit v1.2.3 From ecc9bbd66d94257564f56039d09589834618a5c8 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:40 +0100 Subject: rtc: extend check for RTCs that don't support interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several RTCs would only expose the broken behavior on enabling interrupts. The reason for that is that the kernel only returns the error if the state changes. Therefore the check has to probe switch_interrupts(1) as well. On platforms that work it will be switched on and off, while on those it never works it will just stay off. Clocks known to expose that behavior include, but are not limited to: PPC64# dmesg | grep -i rtc    [    0.241872] rtc-generic rtc-generic: registered as rtc0 [    0.270221] rtc-generic rtc-generic: setting system clock to ... ARM64# dmesg | grep -i rtc [    0.876198] rtc-efi rtc-efi: registered as rtc0 [    1.046869] rtc-efi rtc-efi: setting system clock to ... Signed-off-by: Christian Ehrhardt Gbp-Pq: Name rtc-extend-check-for-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtc_linux.c b/rtc_linux.c index 7ec27c9..3220fad 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -561,7 +561,7 @@ RTC_Linux_Initialise(void) } /* Make sure the RTC supports interrupts */ - if (!switch_interrupts(0)) { + if (!switch_interrupts(1) || !switch_interrupts(0)) { close(fd); return 0; } -- cgit v1.2.3 From fd5d3387fad02a9439066a4bfffd7ce29f4a6dd8 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:39 +0100 Subject: test: accept test result if RTC can't enable RTC_UIE_ON The test might run on different platforms. If the platform happens to have a RTC that does exist but unable to have RTC_UIE_ON set the test will fail, while the chrony code is actually good. Examples of bad clocks are: - ppc64el: rtc-generic - arm64: rtc-efi To avoid that extend the log message check on 101-rtc to accept that condition as a valid test result as well. Signed-off-by: Christian Ehrhardt Gbp-Pq: Name test-accept-test-result-if-RTC-can-not-enable-RTC_UIE_ON.patch --- test/system/101-rtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/101-rtc b/test/system/101-rtc index fa9a70d..68bce68 100755 --- a/test/system/101-rtc +++ b/test/system/101-rtc @@ -14,6 +14,6 @@ echo "1 $(date +%s) 0.0 0.0" > "$TEST_DIR/rtcfile" start_chronyd || test_fail stop_chronyd || test_fail -check_chronyd_message_count "\(clock off from RTC\|RTC time before last\)" 1 1 || test_fail +check_chronyd_message_count "\(clock off from RTC\|RTC time before last\|Could not \(enable\|disable\) RTC interrupt\)" 1 1 || test_fail test_pass -- cgit v1.2.3 From 98e96b55cc097d93a487319eef5d346021a2f9a1 Mon Sep 17 00:00:00 2001 From: Vincent Blut Date: Thu, 20 Aug 2020 14:07:22 +0200 Subject: allow some *time64 syscalls in seccomp filter Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/chrony/+bug/1878005 Forwarded: https://www.mail-archive.com/chrony-dev@chrony.tuxfamily.org/msg02172.html Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=7a7295992f76def739f0110f1e8f1346ff3a032e Last-Update: 2020-05-18 Allowing these system calls is required for 32-bit architectures with new system calls using 64-bit time_t. Last-Update: 2020-05-18 Gbp-Pq: Name allow-some-*time64-syscalls-in-seccomp-filter.patch --- sys_linux.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index ee7ddc1..931dd95 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -478,7 +478,14 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), SCMP_SYS(clock_gettime), + SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), +#ifdef __NR_clock_adjtime64 + SCMP_SYS(clock_adjtime64), +#endif + SCMP_SYS(clock_gettime), +#ifdef __NR_clock_gettime64 + SCMP_SYS(clock_gettime64), +#endif SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getpid), @@ -497,14 +504,29 @@ SYS_Linux_EnableSystemCallFilter(int level) SCMP_SYS(statfs64), SCMP_SYS(unlink), SCMP_SYS(unlinkat), /* Socket */ SCMP_SYS(bind), SCMP_SYS(connect), SCMP_SYS(getsockname), SCMP_SYS(getsockopt), - SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), SCMP_SYS(recvmsg), + SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), +#ifdef __NR_recvmmsg_time64 + SCMP_SYS(recvmmsg_time64), +#endif + SCMP_SYS(recvmsg), SCMP_SYS(send), SCMP_SYS(sendmmsg), SCMP_SYS(sendmsg), SCMP_SYS(sendto), /* TODO: check socketcall arguments */ SCMP_SYS(socketcall), /* General I/O */ SCMP_SYS(_newselect), SCMP_SYS(close), SCMP_SYS(open), SCMP_SYS(openat), SCMP_SYS(pipe), - SCMP_SYS(pipe2), SCMP_SYS(poll), SCMP_SYS(ppoll), SCMP_SYS(pselect6), SCMP_SYS(read), - SCMP_SYS(futex), SCMP_SYS(select), SCMP_SYS(set_robust_list), SCMP_SYS(write), + SCMP_SYS(pipe2), SCMP_SYS(poll), SCMP_SYS(ppoll), +#ifdef __NR_ppoll_time64 + SCMP_SYS(ppoll_time64), +#endif + SCMP_SYS(pselect6), +#ifdef __NR_pselect6_time64 + SCMP_SYS(pselect6_time64), +#endif + SCMP_SYS(read), SCMP_SYS(futex), +#ifdef __NR_futex_time64 + SCMP_SYS(futex_time64), +#endif + SCMP_SYS(select), SCMP_SYS(set_robust_list), SCMP_SYS(write), /* Miscellaneous */ SCMP_SYS(getrandom), SCMP_SYS(sysinfo), SCMP_SYS(uname), }; -- cgit v1.2.3 From 73679851780ce6cbae2b039d2eeee3fa5de0b099 Mon Sep 17 00:00:00 2001 From: Vincent Blut Date: Thu, 16 Jan 2020 17:04:35 +0100 Subject: sys_linux: allow renameat2 in seccomp filter This is needed for architectures that support neither rename() nor renameat() (e.g. riscv64) Gbp-Pq: Name allow-renameat2-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index 898dc7a..ffbc9dd 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -493,8 +493,8 @@ SYS_Linux_EnableSystemCallFilter(int level) SCMP_SYS(chown32), SCMP_SYS(faccessat), SCMP_SYS(fchmodat), SCMP_SYS(fchownat), SCMP_SYS(fstat), SCMP_SYS(fstat64), SCMP_SYS(getdents), SCMP_SYS(getdents64), SCMP_SYS(lseek), SCMP_SYS(newfstatat), SCMP_SYS(rename), SCMP_SYS(renameat), - SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), SCMP_SYS(statfs64), - SCMP_SYS(unlink), SCMP_SYS(unlinkat), + SCMP_SYS(renameat2), SCMP_SYS(stat), SCMP_SYS(stat64), SCMP_SYS(statfs), + SCMP_SYS(statfs64), SCMP_SYS(unlink), SCMP_SYS(unlinkat), /* Socket */ SCMP_SYS(bind), SCMP_SYS(connect), SCMP_SYS(getsockname), SCMP_SYS(getsockopt), SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), SCMP_SYS(recvmsg), -- cgit v1.2.3 From 18729e12ace62b79d6598edb4b740d371349a8fe Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 2 Dec 2019 12:47:13 +0100 Subject: sys_linux: allow clock_adjtime in seccomp filter The adjtimex() function in glibc was switched to the clock_adjtime system call. Gbp-Pq: Name allow-clock_adjtime-in-seccomp-filter.patch --- sys_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index ffbc9dd..ee7ddc1 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -478,8 +478,8 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(clock_gettime), SCMP_SYS(gettimeofday), - SCMP_SYS(settimeofday), SCMP_SYS(time), + SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), SCMP_SYS(clock_gettime), + SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getpid), SCMP_SYS(getrlimit), SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigreturn), -- cgit v1.2.3 From 5773c81bc01f4038a2087be9e7c907f6a6aa3b6a Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 18 Jun 2019 15:41:50 +0200 Subject: test: update processing of packet log Two new fields have been added to the packet log, which broke some of the simulation tests. Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=62d6aed6a64b887c9e3b7f03d9e0db1deaa2696a Gbp-Pq: Name update_processing_of_packet_log.patch --- test/simulation/test.common | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/simulation/test.common b/test/simulation/test.common index 951a794..8ed6ad9 100644 --- a/test/simulation/test.common +++ b/test/simulation/test.common @@ -391,9 +391,9 @@ check_packet_port() { for i in $(seq 1 $(get_chronyd_nodes)); do test_message 3 0 "node $i:" - grep -E -q " $port [0-9]+\$" tmp/log.packets && \ + grep -E -q "^([0-9e.+-]+ ){5}$port " tmp/log.packets && \ ! grep -E "^[0-9e.+-]+ $i " tmp/log.packets | \ - grep -E -q -v " $port [0-9]+\$" && \ + grep -E -q -v "^([0-9e.+-]+ ){5}$port " && \ test_ok || test_bad [ $? -eq 0 ] || ret=1 done -- cgit v1.2.3 From 13c8cbb750d1d041ed554fbddf9ff677901bd708 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:40:44 +0100 Subject: rtc: simplify and move switch_interrupts() Gbp-Pq: Name rtc-simplify-and-move-switch_interrupts-function.patch --- rtc_linux.c | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index d4d9bd0..30833e5 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -527,6 +527,20 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) return RTC_ST_OK; } +/* ================================================== */ + +static void +switch_interrupts(int on_off) +{ + if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { + LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", + on_off ? "enable" : "disable", strerror(errno)); + return; + } + + if (on_off) + skip_interrupts = 1; +} /* ================================================== */ /* file_name is the name of the file where we save the RTC params @@ -603,29 +617,6 @@ RTC_Linux_Finalise(void) /* ================================================== */ -static void -switch_interrupts(int onoff) -{ - int status; - - if (onoff) { - status = ioctl(fd, RTC_UIE_ON, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "enable", strerror(errno)); - return; - } - skip_interrupts = 1; - } else { - status = ioctl(fd, RTC_UIE_OFF, 0); - if (status < 0) { - LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", "disable", strerror(errno)); - return; - } - } -} - -/* ================================================== */ - static void measurement_timeout(void *any) { -- cgit v1.2.3 From 0e9c58cb6e717c19e39bda91021cea80e453d275 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:30:42 +0100 Subject: rtc: don't finalize driver if initialization failed Gbp-Pq: Name rtc-do-not-finalize-driver-if-initialization-failed.patch --- rtc.c | 2 +- rtc_linux.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/rtc.c b/rtc.c index 33d04bf..fa83173 100644 --- a/rtc.c +++ b/rtc.c @@ -160,7 +160,7 @@ RTC_Initialise(int initial_set) void RTC_Finalise(void) { - if (driver.fini) { + if (driver_initialised) { (driver.fini)(); } } diff --git a/rtc_linux.c b/rtc_linux.c index 30833e5..c1a705d 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -550,6 +550,17 @@ switch_interrupts(int on_off) int RTC_Linux_Initialise(void) { + /* Try to open the device */ + fd = open(CNF_GetRtcDevice(), O_RDWR); + if (fd < 0) { + LOG(LOGS_ERR, "Could not open RTC device %s : %s", + CNF_GetRtcDevice(), strerror(errno)); + return 0; + } + + /* Close on exec */ + UTI_FdSetCloexec(fd); + rtc_sec = MallocArray(time_t, MAX_SAMPLES); rtc_trim = MallocArray(double, MAX_SAMPLES); system_times = MallocArray(struct timespec, MAX_SAMPLES); @@ -560,18 +571,6 @@ RTC_Linux_Initialise(void) /* In case it didn't get done by pre-init */ coefs_file_name = CNF_GetRtcFile(); - /* Try to open device */ - - fd = open (CNF_GetRtcDevice(), O_RDWR); - if (fd < 0) { - LOG(LOGS_ERR, "Could not open RTC device %s : %s", - CNF_GetRtcDevice(), strerror(errno)); - return 0; - } - - /* Close on exec */ - UTI_FdSetCloexec(fd); - n_samples = 0; n_samples_since_regression = 0; n_runs = 0; -- cgit v1.2.3 From 8c2fda5816fadd78e981665e9437552199d5319f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:33:17 +0100 Subject: rtc: handle RTCs that don't support interrupts Some RTCs supported by the Linux kernel don't support the RTC_UIE_ON/OFF ioctls, which causes chronyd started with the -s option to get stuck in the initial RTC mode. After opening the RTC device in the initialization, return error if the ioctls are not supported to prevent the upper layer from calling the time_init() function and expecting it to finish. Gbp-Pq: Name rtc-handle-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/rtc_linux.c b/rtc_linux.c index c1a705d..8b21394 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -529,17 +529,19 @@ write_coefs_to_file(int valid,time_t ref_time,double offset,double rate) /* ================================================== */ -static void +static int switch_interrupts(int on_off) { if (ioctl(fd, on_off ? RTC_UIE_ON : RTC_UIE_OFF, 0) < 0) { LOG(LOGS_ERR, "Could not %s RTC interrupt : %s", on_off ? "enable" : "disable", strerror(errno)); - return; + return 0; } if (on_off) skip_interrupts = 1; + + return 1; } /* ================================================== */ @@ -558,6 +560,12 @@ RTC_Linux_Initialise(void) return 0; } + /* Make sure the RTC supports interrupts */ + if (!switch_interrupts(0)) { + close(fd); + return 0; + } + /* Close on exec */ UTI_FdSetCloexec(fd); -- cgit v1.2.3 From cf224248b47dee8fe24ba334c72ecba3f0fcaa30 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Tue, 10 Dec 2019 17:42:34 +0100 Subject: rtc: disable interrupts in finalization Don't leave interrupts enabled if chronyd is stopped when making an RTC measurement. Gbp-Pq: Name rtc-disable-interrupts-in-finalization.patch --- rtc_linux.c | 1 + 1 file changed, 1 insertion(+) diff --git a/rtc_linux.c b/rtc_linux.c index 8b21394..7ec27c9 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -611,6 +611,7 @@ RTC_Linux_Finalise(void) /* Remove input file handler */ if (fd >= 0) { SCH_RemoveFileHandler(fd); + switch_interrupts(0); close(fd); /* Save the RTC data */ -- cgit v1.2.3 From 0f2f380b92c9c4100359395436b389763dbdc31a Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:40 +0100 Subject: rtc: extend check for RTCs that don't support interrupts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Several RTCs would only expose the broken behavior on enabling interrupts. The reason for that is that the kernel only returns the error if the state changes. Therefore the check has to probe switch_interrupts(1) as well. On platforms that work it will be switched on and off, while on those it never works it will just stay off. Clocks known to expose that behavior include, but are not limited to: PPC64# dmesg | grep -i rtc    [    0.241872] rtc-generic rtc-generic: registered as rtc0 [    0.270221] rtc-generic rtc-generic: setting system clock to ... ARM64# dmesg | grep -i rtc [    0.876198] rtc-efi rtc-efi: registered as rtc0 [    1.046869] rtc-efi rtc-efi: setting system clock to ... Signed-off-by: Christian Ehrhardt Gbp-Pq: Name rtc-extend-check-for-RTCs-that-do-not-support-interrupts.patch --- rtc_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtc_linux.c b/rtc_linux.c index 7ec27c9..3220fad 100644 --- a/rtc_linux.c +++ b/rtc_linux.c @@ -561,7 +561,7 @@ RTC_Linux_Initialise(void) } /* Make sure the RTC supports interrupts */ - if (!switch_interrupts(0)) { + if (!switch_interrupts(1) || !switch_interrupts(0)) { close(fd); return 0; } -- cgit v1.2.3 From 6b1fdb146f5ddc94663996e95310260934f5a6e8 Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Thu, 12 Dec 2019 12:06:39 +0100 Subject: test: accept test result if RTC can't enable RTC_UIE_ON The test might run on different platforms. If the platform happens to have a RTC that does exist but unable to have RTC_UIE_ON set the test will fail, while the chrony code is actually good. Examples of bad clocks are: - ppc64el: rtc-generic - arm64: rtc-efi To avoid that extend the log message check on 101-rtc to accept that condition as a valid test result as well. Signed-off-by: Christian Ehrhardt Gbp-Pq: Name test-accept-test-result-if-RTC-can-not-enable-RTC_UIE_ON.patch --- test/system/101-rtc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/system/101-rtc b/test/system/101-rtc index fa9a70d..68bce68 100755 --- a/test/system/101-rtc +++ b/test/system/101-rtc @@ -14,6 +14,6 @@ echo "1 $(date +%s) 0.0 0.0" > "$TEST_DIR/rtcfile" start_chronyd || test_fail stop_chronyd || test_fail -check_chronyd_message_count "\(clock off from RTC\|RTC time before last\)" 1 1 || test_fail +check_chronyd_message_count "\(clock off from RTC\|RTC time before last\|Could not \(enable\|disable\) RTC interrupt\)" 1 1 || test_fail test_pass -- cgit v1.2.3 From 0aad9f271c9eb1b66f12af8072c920f8c438f134 Mon Sep 17 00:00:00 2001 From: Vincent Blut Date: Wed, 16 Sep 2020 12:32:23 +0200 Subject: allow some *time64 syscalls in seccomp filter Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/chrony/+bug/1878005 Forwarded: https://www.mail-archive.com/chrony-dev@chrony.tuxfamily.org/msg02172.html Applied-Upstream: https://git.tuxfamily.org/chrony/chrony.git/commit/?id=7a7295992f76def739f0110f1e8f1346ff3a032e Last-Update: 2020-05-18 Allowing these system calls is required for 32-bit architectures with new system calls using 64-bit time_t. Last-Update: 2020-05-18 Gbp-Pq: Name allow-some-*time64-syscalls-in-seccomp-filter.patch --- sys_linux.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/sys_linux.c b/sys_linux.c index ee7ddc1..931dd95 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -478,7 +478,14 @@ SYS_Linux_EnableSystemCallFilter(int level) { const int syscalls[] = { /* Clock */ - SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), SCMP_SYS(clock_gettime), + SCMP_SYS(adjtimex), SCMP_SYS(clock_adjtime), +#ifdef __NR_clock_adjtime64 + SCMP_SYS(clock_adjtime64), +#endif + SCMP_SYS(clock_gettime), +#ifdef __NR_clock_gettime64 + SCMP_SYS(clock_gettime64), +#endif SCMP_SYS(gettimeofday), SCMP_SYS(settimeofday), SCMP_SYS(time), /* Process */ SCMP_SYS(clone), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(getpid), @@ -497,14 +504,29 @@ SYS_Linux_EnableSystemCallFilter(int level) SCMP_SYS(statfs64), SCMP_SYS(unlink), SCMP_SYS(unlinkat), /* Socket */ SCMP_SYS(bind), SCMP_SYS(connect), SCMP_SYS(getsockname), SCMP_SYS(getsockopt), - SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), SCMP_SYS(recvmsg), + SCMP_SYS(recv), SCMP_SYS(recvfrom), SCMP_SYS(recvmmsg), +#ifdef __NR_recvmmsg_time64 + SCMP_SYS(recvmmsg_time64), +#endif + SCMP_SYS(recvmsg), SCMP_SYS(send), SCMP_SYS(sendmmsg), SCMP_SYS(sendmsg), SCMP_SYS(sendto), /* TODO: check socketcall arguments */ SCMP_SYS(socketcall), /* General I/O */ SCMP_SYS(_newselect), SCMP_SYS(close), SCMP_SYS(open), SCMP_SYS(openat), SCMP_SYS(pipe), - SCMP_SYS(pipe2), SCMP_SYS(poll), SCMP_SYS(ppoll), SCMP_SYS(pselect6), SCMP_SYS(read), - SCMP_SYS(futex), SCMP_SYS(select), SCMP_SYS(set_robust_list), SCMP_SYS(write), + SCMP_SYS(pipe2), SCMP_SYS(poll), SCMP_SYS(ppoll), +#ifdef __NR_ppoll_time64 + SCMP_SYS(ppoll_time64), +#endif + SCMP_SYS(pselect6), +#ifdef __NR_pselect6_time64 + SCMP_SYS(pselect6_time64), +#endif + SCMP_SYS(read), SCMP_SYS(futex), +#ifdef __NR_futex_time64 + SCMP_SYS(futex_time64), +#endif + SCMP_SYS(select), SCMP_SYS(set_robust_list), SCMP_SYS(write), /* Miscellaneous */ SCMP_SYS(getrandom), SCMP_SYS(sysinfo), SCMP_SYS(uname), }; -- cgit v1.2.3