Skip to contentSkip to conversation

selftests: timers: skip raw_skew when adjtimex fails

PATCH Applied Daniel Syauqi 3 participants 4 messages Oct 7 – Nov 9

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: timers: skip raw_skew when adjtimex fails

raw_skew reads frequency and offset data from adjtimex() without checking whether either query succeeded. If a sandbox blocks the syscall, the test can use uninitialized data and wait two minutes before producing a misleading result.

Skip on either failure and report the syscall error. Preserve errno across the newline printed after the second query.

Fixes 51f91cbdf545 ("selftests/timers: Add clock skew estimation test from timetest suite")
Assisted-by LLM Codex

---
Tool assistance: OpenAI Codex helped identify the unchecked adjtimex() returns, draft the fix and changelog, and create failure-path tests. Prompt summary: Investigate the unchecked adjtimex() calls in raw_skew and prepare and test a narrow selftest fix. The affected content is raw_skew.c error handling and this changelog.

Tests: Built raw_skew with make. Forced EPERM at each adjtimex() call separately with LD_PRELOAD; both runs skipped with exit status 4. A normal raw_skew run passed, and targeted timer selftests had no failures. The full kernel test suite was not run.

 tools/testing/selftests/timers/raw_skew.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/timers/raw_skew.c +10 -2
index 0c87a8fb0..2ad5e2e35 100644
@@ -19,7 +19,9 @@
  *   GNU General Public License for more details.
  */
 
+#include <errno.h>
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <sys/time.h>
@@ -101,7 +103,8 @@ int main(int argc, char **argv)
 	}
 
 	tx1.modes = 0;
-	adjtimex(&tx1);
+	if (adjtimex(&tx1) < 0)
+		ksft_exit_skip("adjtimex failed: %s\n", strerror(errno));
 	get_monotonic_and_raw(&mon, &raw);
 	start = mon;
 	delta1 = diff_timespec(mon, raw);
@@ -116,7 +119,12 @@ int main(int argc, char **argv)
 	get_monotonic_and_raw(&mon, &raw);
 	end = mon;
 	tx2.modes = 0;
-	adjtimex(&tx2);
+	if (adjtimex(&tx2) < 0) {
+		int saved_errno = errno;
+
+		printf("\n");
+		ksft_exit_skip("adjtimex failed: %s\n", strerror(saved_errno));
+	}
 	delta2 = diff_timespec(mon, raw);
 
 	interval = diff_timespec(start, end);

base-commit: 602042bf29f6efde39cfb5fdd9289bf4854bc0c5

Signature · 1 line
2.47.3
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Daniel Syauqi

raw_skew reads frequency and offset data from adjtimex() without checking whether either query succeeded. If a sandbox blocks the syscall, the test can use uninitialized data and wait two minutes before producing a misleading result.

Quoted 6 lines

Skip on either failure and report the syscall error. Preserve errno across the newline printed after the second query.

Fixes 51f91cbdf545 ("selftests/timers: Add clock skew estimation test from timetest suite")
Assisted-by LLM Codex

Looks reasonable to me.

#2 lore raw

Hi,

Sorry for the separate message earlier, I missed the lists on my follow-up. Thank you for the review and Acked-by. Is anything else needed from me for this patch to be picked up?

Thanks,
Daniel

merge bot Applied
#3 lore raw

[tip: timers/core] selftests: timers: Skip raw_skew when adjtimex fails

In reply to Daniel Syauqi
The following commit has been merged into the timers/core branch of tip:

The following commit has been merged into the timers/core branch of tip:

Commit-ID:     ebc02b51eb7b4e1478b6973aed15f60882ef9cd4
Gitweb:        https://git.kernel.org/tip/ebc02b51eb7b4e1478b6973aed15f60882ef9cd4
Author:        Daniel Syauqi <[email protected]>
AuthorDate:    Wed, 07 Oct 2026 19:16:11 +08:00
Committer:     Thomas Gleixner <[email protected]>
CommitterDate: Mon, 09 Nov 2026 20:21:47 +01:00

selftests: timers: Skip raw_skew when adjtimex fails

raw_skew reads frequency and offset data from adjtimex() without checking whether either query succeeded. If a sandbox blocks the syscall, the test can use uninitialized data and wait two minutes before producing a misleading result.

Skip on either failure and report the syscall error. Preserve errno across the newline printed after the second query.

Fixes 51f91cbdf545 ("selftests/timers: Add clock skew estimation test from timetest suite")
Assisted-by LLM Codex
---
 tools/testing/selftests/timers/raw_skew.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
tools/testing/selftests/timers/raw_skew.c +10 -2
index dfca3e2..a61f6a0 100644
@@ -19,7 +19,9 @@
  *   GNU General Public License for more details.
  */
 
+#include <errno.h>
 #include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <sys/time.h>
@@ -102,7 +104,8 @@ int main(int argc, char **argv)
 	}
 
 	tx1.modes = 0;
-	adjtimex(&tx1);
+	if (adjtimex(&tx1) < 0)
+		ksft_exit_skip("adjtimex failed: %s\n", strerror(errno));
 	get_monotonic_and_raw(&mon, &raw);
 	start = mon;
 	delta1 = diff_timespec(mon, raw);
@@ -117,7 +120,12 @@ int main(int argc, char **argv)
 	get_monotonic_and_raw(&mon, &raw);
 	end = mon;
 	tx2.modes = 0;
-	adjtimex(&tx2);
+	if (adjtimex(&tx2) < 0) {
+		int saved_errno = errno;
+
+		printf("\n");
+		ksft_exit_skip("adjtimex failed: %s\n", strerror(saved_errno));
+	}
 	delta2 = diff_timespec(mon, raw);
 
 	interval = diff_timespec(start, end);