diff --git a/bin/omarchy-apply-lock b/bin/omarchy-apply-lock index 77132d873f97..f41fce2bb865 100755 --- a/bin/omarchy-apply-lock +++ b/bin/omarchy-apply-lock @@ -41,6 +41,13 @@ EOF resume_hook_src="$OMARCHY_PATH/default/systemd/system-sleep/fprintd-resume" resume_hook_dst=/usr/lib/systemd/system-sleep/fprintd-resume +# The hook restarts fprintd while sessions are frozen, and a wedged fprintd +# ignores SIGTERM, so cap the stop timeout to keep the recovery off the thaw. +# It travels with the hook for the same reason the hook travels with the PAM +# file: the pair is only correct together. +stop_timeout_src="$OMARCHY_PATH/default/systemd/system/fprintd.service.d/stop-timeout.conf" +stop_timeout_dst=/etc/systemd/system/fprintd.service.d/stop-timeout.conf + # One " - #N: finger" line per enrolled print; a user without any gets "has no # fingers enrolled" instead, which must not count. if omarchy-cmd-present fprintd-list && fprintd-list "$target_user" 2>/dev/null | grep -q ' - #'; then @@ -51,8 +58,11 @@ auth required pam_fprintd.so account include system-local-login EOF as_root install -Dm755 -o root -g root "$resume_hook_src" "$resume_hook_dst" + as_root install -Dm644 -o root -g root "$stop_timeout_src" "$stop_timeout_dst" + as_root systemctl daemon-reload else - as_root rm -f /etc/pam.d/omarchy-lock-fingerprint "$resume_hook_dst" + as_root rm -f /etc/pam.d/omarchy-lock-fingerprint "$resume_hook_dst" "$stop_timeout_dst" + as_root systemctl daemon-reload fi # omarchy-shell can't reach a running shell during chroot install. The echo diff --git a/bin/omarchy-remove-security-fingerprint b/bin/omarchy-remove-security-fingerprint index d2b53a8fb7a2..9358c39c2c86 100755 --- a/bin/omarchy-remove-security-fingerprint +++ b/bin/omarchy-remove-security-fingerprint @@ -32,6 +32,13 @@ remove_resume_hook() { echo "Removing fingerprint resume hook..." sudo rm -f /usr/lib/systemd/system-sleep/fprintd-resume fi + + if [[ -f /etc/systemd/system/fprintd.service.d/stop-timeout.conf ]]; then + echo "Removing fprintd stop timeout..." + sudo rm -f /etc/systemd/system/fprintd.service.d/stop-timeout.conf + sudo rmdir --ignore-fail-on-non-empty /etc/systemd/system/fprintd.service.d + sudo systemctl daemon-reload + fi } diff --git a/bin/omarchy-setup-security-fingerprint b/bin/omarchy-setup-security-fingerprint index 60a963c9a62d..2528545c2f8b 100755 --- a/bin/omarchy-setup-security-fingerprint +++ b/bin/omarchy-setup-security-fingerprint @@ -71,6 +71,11 @@ install_resume_hook() { # ownership and whatever mode the tree happens to have. echo "Installing fingerprint resume hook..." sudo install -Dm755 -o root -g root "$OMARCHY_PATH/default/systemd/system-sleep/fprintd-resume" /usr/lib/systemd/system-sleep/fprintd-resume + + # The hook's restart runs while sessions are frozen and a wedged fprintd does + # not answer SIGTERM, so cap the stop timeout; see the drop-in for numbers. + sudo install -Dm644 -o root -g root "$OMARCHY_PATH/default/systemd/system/fprintd.service.d/stop-timeout.conf" /etc/systemd/system/fprintd.service.d/stop-timeout.conf + sudo systemctl daemon-reload } diff --git a/default/systemd/system/fprintd.service.d/stop-timeout.conf b/default/systemd/system/fprintd.service.d/stop-timeout.conf new file mode 100644 index 000000000000..f62000315f0c --- /dev/null +++ b/default/systemd/system/fprintd.service.d/stop-timeout.conf @@ -0,0 +1,11 @@ +[Service] +# The resume hook restarts fprintd synchronously, while user sessions are still +# frozen, so whatever the stop costs is added to the thaw. A healthy daemon -- +# even one holding a claim -- stops in about 2ms, but a wedged one does not +# answer SIGTERM at all and has to be killed: measured at 5.08s and 5.02s +# against Omarchy's DefaultTimeoutStopSec=5s. That is the case the hook exists +# for, so without a cap the recovery is slower than the failure it repairs. +# +# 3s is well clear of a healthy stop and still leaves the hook's 10s bound room +# for the start that follows. +TimeoutStopSec=3s diff --git a/migrations/1787505445.sh b/migrations/1787505445.sh index 5ec583380e33..1ec84bce9a3d 100644 --- a/migrations/1787505445.sh +++ b/migrations/1787505445.sh @@ -7,12 +7,26 @@ echo "Install the fingerprint resume hook on existing fingerprint setups" hook_src="${OMARCHY_FPRINTD_RESUME_SRC:-$OMARCHY_PATH/default/systemd/system-sleep/fprintd-resume}" hook_dst="${OMARCHY_FPRINTD_RESUME_DST:-/usr/lib/systemd/system-sleep/fprintd-resume}" +timeout_src="${OMARCHY_FPRINTD_STOP_TIMEOUT_SRC:-$OMARCHY_PATH/default/systemd/system/fprintd.service.d/stop-timeout.conf}" +timeout_dst="${OMARCHY_FPRINTD_STOP_TIMEOUT_DST:-/etc/systemd/system/fprintd.service.d/stop-timeout.conf}" lock_pam="${OMARCHY_LOCK_FINGERPRINT_PAM:-/etc/pam.d/omarchy-lock-fingerprint}" -# Only where fingerprint is configured, and only when the hook is absent -- an -# existing copy may be newer or hand-edited, so leave it alone. install -Dm755 -# sets the executable bit explicitly, which systemd-sleep requires to run it. -[[ -f $lock_pam && -f $hook_src && ! -e $hook_dst ]] || exit 0 +# Only where fingerprint is configured. +[[ -f $lock_pam ]] || exit 0 -echo "Installing the fprintd resume hook" -sudo install -Dm755 "$hook_src" "$hook_dst" +# Each half is guarded on its own: a machine that already took the hook still +# needs the cap. Only install what is absent -- an existing copy may be newer +# or hand-edited, so leave it alone. install -Dm755 sets the executable bit +# explicitly, which systemd-sleep requires to run the hook. +if [[ -f $hook_src && ! -e $hook_dst ]]; then + echo "Installing the fprintd resume hook" + sudo install -Dm755 "$hook_src" "$hook_dst" +fi + +# The hook restarts fprintd while sessions are frozen, and a wedged fprintd +# ignores SIGTERM, so without this cap the recovery costs more than the bug. +if [[ -f $timeout_src && ! -e $timeout_dst ]]; then + echo "Capping the fprintd stop timeout" + sudo install -Dm644 "$timeout_src" "$timeout_dst" + sudo systemctl daemon-reload +fi diff --git a/test/shell.d/fprintd-resume-migration-test.sh b/test/shell.d/fprintd-resume-migration-test.sh index 35ea999cabaa..c086ae257eef 100755 --- a/test/shell.d/fprintd-resume-migration-test.sh +++ b/test/shell.d/fprintd-resume-migration-test.sh @@ -20,17 +20,28 @@ exec "$@" STUB chmod +x "$stub_bin/sudo" +# The migration reloads systemd after dropping the cap in. Record the call +# instead of reloading the machine running the test. +cat >"$stub_bin/systemctl" <>"$TMPDIR/systemctl.log" +STUB +chmod +x "$stub_bin/systemctl" + src="$TMPDIR/fprintd-resume" printf '#!/bin/bash\n' >"$src" chmod +x "$src" dst="$TMPDIR/system-sleep/fprintd-resume" +timeout_dst="$TMPDIR/fprintd.service.d/stop-timeout.conf" lock_pam="$TMPDIR/omarchy-lock-fingerprint" # omarchy-migrate runs each migration with `bash -euo pipefail`; match it. run_migration() { PATH="$stub_bin:$PATH" \ + OMARCHY_PATH="$ROOT" \ OMARCHY_FPRINTD_RESUME_SRC="$src" \ OMARCHY_FPRINTD_RESUME_DST="$dst" \ + OMARCHY_FPRINTD_STOP_TIMEOUT_DST="$timeout_dst" \ OMARCHY_LOCK_FINGERPRINT_PAM="$lock_pam" \ bash -euo pipefail "$migration" >/dev/null || fail "migration exits clean" @@ -39,11 +50,13 @@ run_migration() { # The migration exits clean when its source is missing, so a hook moved # without updating it would silently install nothing and mark itself done. # Run once against the real default source under the repo to pin that path. -rm -rf "$TMPDIR/system-sleep" +rm -rf "$TMPDIR/system-sleep" "$TMPDIR/fprintd.service.d" : >"$lock_pam" +: >"$TMPDIR/systemctl.log" PATH="$stub_bin:$PATH" \ OMARCHY_PATH="$ROOT" \ OMARCHY_FPRINTD_RESUME_DST="$dst" \ + OMARCHY_FPRINTD_STOP_TIMEOUT_DST="$timeout_dst" \ OMARCHY_LOCK_FINGERPRINT_PAM="$lock_pam" \ bash -euo pipefail "$migration" >/dev/null || fail "migration exits clean from its default source" @@ -51,6 +64,18 @@ PATH="$stub_bin:$PATH" \ cmp -s "$dst" "$ROOT/default/systemd/system-sleep/fprintd-resume" || fail "migration installs the shipped hook from its default source" pass "migration installs the shipped hook from its default source" +# The cap has the same failure mode as the hook: moved without updating the +# migration, it would silently install nothing and still mark itself done. +[[ -f $timeout_dst ]] || + fail "migration finds the stop timeout at its default source path" "dst: $(stat -c '%A' "$timeout_dst" 2>/dev/null || echo missing)" +cmp -s "$timeout_dst" "$ROOT/default/systemd/system/fprintd.service.d/stop-timeout.conf" || + fail "migration installs the shipped stop timeout from its default source" +[[ $(stat -c '%a' "$timeout_dst") == 644 ]] || + fail "migration installs the stop timeout world-readable, not executable" "mode: $(stat -c '%a' "$timeout_dst")" +grep -qx 'daemon-reload' "$TMPDIR/systemctl.log" || + fail "migration reloads systemd so the cap takes effect" "systemctl: $(<"$TMPDIR/systemctl.log")" +pass "migration installs the shipped stop timeout and reloads systemd" + # A machine with fingerprint configured but no hook yet gets it, executable. : >"$lock_pam" rm -rf "$TMPDIR/system-sleep" @@ -60,13 +85,32 @@ pass "migration installs the hook, executable" # Running twice must not fail (the hook now exists) and must not touch it. printf 'sentinel\n' >>"$dst" +printf 'sentinel\n' >>"$timeout_dst" +: >"$TMPDIR/systemctl.log" run_migration grep -q sentinel "$dst" || fail "migration leaves an existing hook alone" pass "migration leaves an existing hook alone" +grep -q sentinel "$timeout_dst" || fail "migration leaves an existing stop timeout alone" +[[ ! -s $TMPDIR/systemctl.log ]] || + fail "migration does not reload systemd when it changed nothing" "systemctl: $(<"$TMPDIR/systemctl.log")" +pass "migration leaves an existing stop timeout alone" + +# The whole reason each half is guarded separately: a machine that took the +# hook on an earlier run still has no cap, and must get one. +rm -f "$timeout_dst" +: >"$TMPDIR/systemctl.log" +run_migration +[[ -f $timeout_dst ]] || fail "migration adds the cap to a machine that already has the hook" +grep -q sentinel "$dst" || fail "migration adds the cap without disturbing the hook" +grep -qx 'daemon-reload' "$TMPDIR/systemctl.log" || + fail "migration reloads systemd after adding the cap" "systemctl: $(<"$TMPDIR/systemctl.log")" +pass "migration adds the cap to a machine that already has the hook" + # No fingerprint configured -> nothing to fix, so nothing is installed. rm -f "$lock_pam" -rm -rf "$TMPDIR/system-sleep" +rm -rf "$TMPDIR/system-sleep" "$TMPDIR/fprintd.service.d" run_migration [[ ! -e $dst ]] || fail "migration skips machines without fingerprint configured" +[[ ! -e $timeout_dst ]] || fail "migration skips the cap without fingerprint configured" pass "migration skips machines without fingerprint configured"