From c779bcf5219b08dcc3beb11535c345a95a88f826 Mon Sep 17 00:00:00 2001 From: spydisec <9101327+spydisec@users.noreply.github.com> Date: Wed, 11 Nov 2026 22:54:59 +0000 Subject: [PATCH] fix: wait a second before verify writes its test event verify.sh took the start time with date, wrote the canary file right away, and searched for the event with ausearch -ts . The kernel stamps an audit event with a clock that runs a few ms behind the one date reads. When the start time fell just after a second boundary, the event carried the second before it, ausearch skipped it, and verify failed after 10 seconds. An install then rolled back although the rules worked. Measured on Rocky Linux 10.2: in 4000 writes the event time was earlier than the date taken before the write every time, by up to 2.3 ms, and 4 events were in the earlier second. verify.sh now waits one second between the start time and the write. It also takes the date and the time with one date call, so they can't be from two sides of midnight. Fixes #86 Co-Authored-By: Claude Fable 5.2 --- scripts/verify.sh | 13 +++++++++---- tests/bats/verify.bats | 11 +++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/scripts/verify.sh b/scripts/verify.sh index 41e50a5..db7b189 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -150,10 +150,15 @@ verify_canary_check() { esac # ausearch reads stdin when it isn't a terminal, so --input-logs makes it read the audit logs. # ausearch -ts takes the date and the time as two arguments. It parses the date with the C - # locale's %x, which has a two-digit year. The event time is never before this second. - verify_date=$(date '+%m/%d/%y') - verify_time=$(date '+%H:%M:%S') - verify_start="$verify_date $verify_time" + # locale's %x, which has a two-digit year. One date call gives both, so they are from the same + # moment. + verify_start=$(date '+%m/%d/%y %H:%M:%S') + verify_date=${verify_start% *} + verify_time=${verify_start#* } + # The kernel stamps an event with a clock that runs a few ms behind the one date reads. So an + # event written right after the start time can carry the second before it, and ausearch -ts + # would skip it. Waiting one second puts the event after the start time. + [ "$verify_poll" -eq 0 ] || sleep 1 if ! printf 'canary %s\n' "$verify_start" >"$verify_canary" 2>/dev/null; then verify_report canary fail "cannot write $verify_canary" return diff --git a/tests/bats/verify.bats b/tests/bats/verify.bats index 32691f5..ee7ebe6 100644 --- a/tests/bats/verify.bats +++ b/tests/bats/verify.bats @@ -213,3 +213,14 @@ lost 0' [ "$status" -eq 0 ] [[ "$output" == *"check=failure_mode result=warn"* ]] } + +@test "verify waits a second after it takes the start time, before it writes the canary" { + write_state + # The kernel's event clock runs a few ms behind date, so an event written right after the + # start time can carry the second before it, and ausearch -ts would then skip it. + export AKIT_VERIFY_POLL=1 + akit_stub sleep '{ [ -e "$AKIT_ROOT/etc/auditd-kit/canary" ] && echo after || echo before; } >>"$AKIT_ROOT/sleeps"' + run sh "$verify" + [ "$status" -eq 0 ] + [ "$(sed -n 1p "$AKIT_ROOT/sleeps")" = before ] +}