Repository navigation
Description
Finding (verified 2026-11-13, Scheduled Suggestions pass on issue #8324)
nixos/services/power-guard/power-guard.py executes an environment-derived command string through a shell, as root:
- Line 22 (module docstring): "Runs as root in production (systemd unit from the NixOS flake)."
- Line 94:
SLEEP_CMD = os.environ.get("POWER_GUARD_SLEEP_CMD", "systemctl hybrid-sleep") - Line 231 (in
main(), after a confirmed critical state):subprocess.run(SLEEP_CMD, shell=True)
The systemd unit in nixos/services/power-guard/default.nix sets no environment, so today the variable is only a test/manual hook (test_power_guard.py line 179 sets POWER_GUARD_SLEEP_CMD=f"touch {self.marker}"). The env source is therefore service/root-controlled, not remote input — this is a hardening item, not a live exploit path. It still matters:
- A root daemon should not need a shell to run a two-word command;
shell=Trueturns any future wiring of this variable to a less-trusted source (a NixOS option, a drop-in, a test harness running unprivileged input) into root shell execution with no further code change. - Shell parsing of the override is a surprise surface: quoting/metacharacters in an otherwise legitimate multi-word command change its meaning silently.
Suggested fix shape
- Parse once at startup with
shlex.split, validate the result is a non-empty argv, and runsubprocess.run(argv)with no shell — mirroring the file's existing fail-closed-at-startup treatment of timing overrides (timing_from_env, lines 71-83). - Update the test hook usage in
test_power_guard.py(line 179) accordingly;touch <marker>still works as an argv form. - Alternatively, if shell semantics are intentionally kept for the test hook, restrict the production default path to a fixed argv and document why the hook is trusted.
Related but distinct existing items (different defects in the same file, checked before filing): issue #8182 (release() forgets a still-running systemd-inhibit child) and issue #6534 (dead systemd-inhibit child never noticed). Neither covers the shell=True sleep command.
Found by: repo-worker-code-d, lane code-d, fleet queue fallback mode (queue backend down), suggestions pass for issue #8324. Evidence read from main via the GitHub API on 2026-11-13.
Activity
dezren39 commentedon Nov 17, 2026
🤖 Agent note · triaged
Triage verdict: the issue arrived triaged (kind/security, task/small-fix, priority/normal, effort/s, area/nixos, app/power-guard — all set by its filer, a fleet lane's verified 2026-11-13 finding). This triage confirms it fresh and routes the fix.
Fresh evidence (2026-11-17): issue #9602 OPEN, no hard stops, zero comments. The defect is still live on current main:
SLEEP_CMD = os.environ.get("POWER_GUARD_SLEEP_CMD", "systemctl hybrid-sleep")atnixos/services/power-guard/power-guard.py:95andsubprocess.run(SLEEP_CMD, shell=True)at line 411 (line numbers drifted from the issue's 94/231; same code). Test hook attest_power_guard.py:181.First concrete step for task 20432: parse
SLEEP_CMDonce at startup withshlex.split, validate non-empty argv (fail closed liketiming_from_env), runsubprocess.run(argv)with no shell, and update the test hook to argv form. Acceptance check: power-guard test suite green and noshell=Trueremaining on the sleep-command path. Hardening, not a live exploit path — the PR should say so plainly.dezren39 commentedon Nov 18, 2026
🤖 Agent note · done
This task was claimed and immediately revalidated. Fresh GitHub state showed the issue CLOSED and PR #11461 MERGED at
2121e7abed18b4ee22227e581cb9cf29cdb7c233; no parallel implementation was started.