Skip to content

Harden ownership of installed sleep hooks - #10425

Merged
ryanrhughes merged 2 commits into
omacom:quattrofrom
acrogenesis:security/root-owned-sleep-hooks
Sep 6, 2026
Merged

ryanrhughes merged 2 commits into
omacom:quattrofrom
acrogenesis:security/root-owned-sleep-hooks

Conversation

@acrogenesis

@acrogenesis acrogenesis commented Sep 6, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Publish the keyboard-backlight and hybrid-GPU sleep hooks through hidden root-owned staging inodes, prepared with their final mode before atomic replacement.
  • Apply the same ownership boundary to the supergfxd service drop-in installed by the hybrid-GPU toggle.
  • Repair unsafe existing copies without trusting their current contents or reusing attacker-writable inodes.
  • Persist the required systemd daemon reload before replacing an unsafe drop-in, and retry it until successful.
  • Refresh exact released hook artifacts while preserving safe administrator-managed files and symlink chains, including dangling targets below protected directories.
  • Resolve the complete lexical suffix of dangling links before deciding that a future target remains under root control.
  • Keep partial hibernation and hybrid-GPU setup retryable after publication failures.
  • Carry Integrated-mode intent across sleep with a root-controlled runtime marker, including the temporary hibernate transition through Vfio.
  • Confirm asynchronous supergfxctl transitions before continuing or consuming restore intent.
  • Use systemd's phase-specific sleep action so both hooks handle suspend-then-hibernate correctly.

Why

The setup commands used cp -p from $OMARCHY_PATH into privileged systemd locations. When run from a user-owned source tree, that preserved the desktop user's ownership on files later consumed as root. Merely changing ownership in place would still trust potentially modified contents and would not invalidate a writer's already-open file descriptor, so the repair publishes a new root-owned inode instead.

The migration leaves an entry unchanged when its complete path and symlink resolution chain are root-controlled and neither group nor other users can write it. Ordinary absent targets beneath a searchable root-controlled parent need no elevation; metadata hidden beneath a root-only hierarchy is inspected with privilege. If the privileged probe can search the protected parent and the target is absent, the dangling administrator symlink is preserved rather than mistaken for unsafe content. Encountering a missing component does not end validation: the remaining lexical suffix is normalized, and real metadata checks resume if .. escapes the missing subtree. Exact current and fingerprinted legacy installer artifacts are replaced directly. Unknown unsafe files and symlinks are first copied under root-only /var/lib/omarchy/migrations/1788662350-system-sleep/, outside systemd's active paths, and their active locations are then repaired.

The released keyboard hook was normally copied from the root-owned package tree as mode 0644. Because the current hook also gains compound-sleep phase handling here, its contents no longer match that released copy. The migration fingerprints the exact released bytes and replaces them with the current executable hook, even if the old copy is otherwise root-controlled or was manually made executable. Safe noncanonical administrator hooks remain untouched.

Replacing the supergfxd drop-in and reloading systemd are treated as one repair. A fixed root-owned marker is created before replacement and removed only after daemon-reload succeeds, so a failed or interrupted run cannot later complete while systemd retains stale configuration in memory.

The executable force-igpu hook records a root-controlled runtime marker during pre-sleep only when the cycle begins in configured Integrated mode. Post-sleep consumes that marker instead of consulting the mutable supergfxd mode. This keeps Hybrid and unconfigured machines inert while allowing hibernate to switch temporarily to persisted Vfio mode and still restore Integrated afterward.

supergfxctl 5.2.7 completes staged mode changes asynchronously after accepting a request. The hook therefore polls supergfxctl -g with a bounded timeout after each request and advances only after observing the requested committed mode. Integrated restore intent is removed only after that confirmation; a failed or timed-out transition retains the marker for a later retry.

For suspend-then-hibernate, systemd keeps the overall operation in the hook argument while exposing each suspend or hibernate phase through SYSTEMD_SLEEP_ACTION. Both hooks now use that phase-specific value, with the argument as a compatibility fallback, so the dGPU detaches and the keyboard backlight turns off before the compound operation enters hibernation.

This intent model lets the migration install a trusted executable hook without depending on a transient supergfxctl query, and lets the toggle publish both supporting files before switching both configuration values in one rewrite. Failed setup therefore leaves the previous GPU mode intact and is safe to retry.

The keyboard hook is published before the resume configuration marker. If publication fails, a normal rerun reaches the failed step instead of exiting as already configured.

Testing

  • bash test/shell.d/system-sleep-ownership-migration-test.sh
  • hostile-TMPDIR invocation of the focused migration test
  • bash test/shell.d/unowned-system-paths-test.sh
  • bash test/shell.d/hybrid-gpu-test.sh
  • ./test/cli
  • Bash syntax and whitespace checks
  • ./test/shell reaches and passes every changed-area test; eight unrelated baseline/environment test files still fail.

Coverage includes retained-writer inode replacement, exact current and released 0644 artifact activation, refresh of recognized legacy bytes already at the final mode, unknown-content quarantine, idempotency, persisted daemon-reload failure and interruption recovery, non-root-group administrator files, protected and dangling symlink chains, full dangling-link suffix normalization, protected dangling targets, direct and indirect user-controlled symlinks, daemon-unavailable GPU repair, Hybrid and missing-config inert behavior, delayed asynchronous GPU transitions, failed Integrated restoration with retained intent and successful retry, direct suspend and hibernate behavior, both suspend-then-hibernate phases, realistic Vfio persistence followed by confirmed Integrated restoration, keyboard-backlight handling during compound hibernation, failure-safe setup ordering, and non-default TMPDIR portability.

@acrogenesis
acrogenesis force-pushed the security/root-owned-sleep-hooks branch 6 times, most recently from 3c8de3f to 34b6fbc Compare September 6, 2026 20:06
Publish privileged sleep-hook and hybrid-GPU files through root-owned replacement inodes, repair unsafe existing copies while preserving administrator customizations, and keep partial hibernation setup retryable.

Reported-by: Roger Piñol <rogerpicar@gmail.com>
@acrogenesis
acrogenesis force-pushed the security/root-owned-sleep-hooks branch from 34b6fbc to feb0557 Compare September 6, 2026 20:36
@acrogenesis
acrogenesis marked this pull request as ready for review September 6, 2026 20:50
@acrogenesis

acrogenesis commented Sep 6, 2026 •

Copy link
Copy Markdown
Member Author

Duplicate and supersession audit

This PR supersedes the sleep-hook installation and executable-mode work in:

It also incorporates the system-sleep packaging documentation correction proposed in #7720.

#4793 partially overlaps the force-igpu behavior, but its separate NVIDIA service changes are outside this PR and should be evaluated independently.

The caller-controlled source-root work in #9317 and #9471, and the cardwire redesign in #9332, are related but distinct and are not claimed as superseded here.

@ryanrhughes
ryanrhughes merged commit c82a083 into omacom:quattro Sep 6, 2026
ryanrhughes added a commit that referenced this pull request Sep 8, 2026
…hooks

Harden ownership of installed sleep hooks

(cherry picked from commit c82a083)
(cherry picked from commit 3b5f4446f6022ad056fc06d320d157075841cde7)
ryanrhughes added a commit that referenced this pull request Sep 8, 2026
…hooks

Harden ownership of installed sleep hooks

(cherry picked from commit c82a083)
(cherry picked from commit 3b5f4446f6022ad056fc06d320d157075841cde7)
@acrogenesis
acrogenesis deleted the security/root-owned-sleep-hooks branch September 16, 2026 20:01
@emirb emirb added this to the 4.5 milestone Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants