Skip to content

[Security] Stop the FIDO2 setup staging its authfile at a predictable /tmp path - #7904

Merged
dhh merged 7 commits into
omacom:quattrofrom
mdisec:security-fido2-authfile-tmp-symlink
Aug 25, 2026
Merged

dhh merged 7 commits into
omacom:quattrofrom
mdisec:security-fido2-authfile-tmp-symlink

Conversation

@mdisec

@mdisec mdisec commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the FIDO2 authentication mapping so it is never writable by the user it authenticates, never staged through a caller-owned pathname that root later reopens, and safely repairs mappings created by
earlier Omarchy versions.

The previous setup did this:

pamu2fcfg >/tmp/fido2
sudo mv /tmp/fido2 /etc/fido2/fido2

Because pamu2fcfg runs unprivileged, the staged file belonged to the invoking user. mv preserved that ownership, leaving /etc/fido2/fido2 writable by the account whose sudo and polkit authentication it
controls. Any process running as that user could append its own credential and then satisfy the pam_u2f entry without knowing the password.

This ownership defect requires no second account, race, symlink, or unusual sysctl configuration.

Why replacing the inode matters

Changing ownership or permissions in place is insufficient. Permission is checked when a file is opened, so a process that opened the legacy user-owned mapping for writing before chown or chmod retains a
writable descriptor afterward.

The migration therefore creates a fresh root-owned copy and atomically renames it over the path. Existing descriptors remain attached to the old inode, which PAM no longer reads.

Enrollment changes

omarchy-setup-security-fido2 now:

  • Creates a unique staging file as root beside the final authfile.
  • Pipes pamu2fcfg output directly into that root-owned file, so root never reopens a caller-owned pathname.
  • Uses pipefail and rejects failed or empty enrollment output.
  • Publishes the completed mapping with an atomic mv -Tf.
  • Cleans the exact staging file after every failure.
  • Refuses symlinks, directories, devices, and other non-regular authfile states.
  • Creates /etc/fido2 as root:root mode 0755.
  • Installs the mapping as root:root mode 0644.

Mode 0644 is intentional. pam_u2f may open even an absolute authfile as the authenticating user when openasuser is configured. The mapping contains credential identifiers and public keys, while the
authenticator retains the private key. Integrity requires root-only writes; compatibility requires authenticated users to be able to read it.

Migration

The migration:

  • Exits without sudo when no FIDO2 mapping exists.
  • Uses the fixed /etc/fido2/fido2 path rather than a caller-controlled environment override.
  • Refuses to follow or automatically rewrite symlink and non-regular states.
  • Repairs incorrect owner, group, or mode.
  • Creates a unique root-owned sibling for each run, avoiding collisions between per-user migrations.
  • Replaces the inode atomically.
  • Cleans interrupted or failed staging operations.

A suspicious symlink is reported and left for manual removal and re-enrollment. Automatically following or deleting it could either expose its target or lock out someone whose password is disabled.

Threat-model clarification

On a stock Arch installation, fs.protected_symlinks=1 and the sticky /tmp directory block the cross-UID symlink redirect described in the original version of this PR.

The primary vulnerability is the user-owned authfile, which affects every installation created by the old setup. Same-UID pathname replacement also remains relevant even with mktemp: another process
running as that user can observe and replace a named temporary file before root reopens it. This implementation avoids that class by sending enrollment output through a pipe into a root-created file.

Removal

omarchy-remove-security-fido2 now also detects a dangling or non-directory /etc/fido2 symlink. Removing it with rm -rf removes the link itself without following its target.

Credit and relationship to #7703

Credit to @calebdw for independently identifying the same ownership defect in #7703 and, importantly, recognizing that the migration must replace the inode rather than merely chown it in place.

The two PRs cannot both merge unchanged because they rewrite the same setup path and add overlapping migrations.

This PR carries that core insight forward while addressing additional issues in the current #7703 implementation:

  • Its enrollment still stages through a user-owned mktemp file that root later reopens. A same-UID process can replace that file after enrollment.
  • Its migration can follow a malicious legacy authfile symlink as root.
  • Its migration exposes a privileged source and destination through OMARCHY_FIDO2_AUTHFILE.
  • Its fixed .new staging name can collide between concurrent per-user migrations.
  • It lacks empty-output, non-regular destination, atomic publication, and failure-cleanup coverage.
  • It does not cover the FIDO2 removal path.

For those reasons, #7703 should receive credit for the independent finding and fresh-inode repair, but should not be merged alongside or instead of this implementation unchanged.

Testing

  • ./test/cli — 116 assertions
  • bash test/shell.d/security-fido2-test.sh — 5 focused setup assertions
  • bash test/shell.d/security-fido2-migration-test.sh — 17 focused migration assertions
  • Both FIDO2 tests repeated in a rootless UID-mapped namespace
  • bash -n on all changed shell files
  • git diff --check

The focused tests cover successful enrollment, empty and failed pamu2fcfg output, chmod and rename failures, cleanup, fresh-inode replacement, malformed staging output, migration metadata checks, and symlink/non-regular states.

Copilot AI balanced review requested due to automatic review settings August 23, 2026 15:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Hardens FIDO2 enrollment and migration against insecure temporary files, symlinks, and user-owned authentication files.

Changes:

  • Securely stages and installs FIDO2 credentials.
  • Repairs legacy authfile ownership and permissions.
  • Adds shell coverage for secure enrollment.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 2 comments.

File Description
bin/omarchy-setup-security-fido2 Uses secure temporary staging and root-owned installation.
bin/omarchy-remove-security-fido2 Removes dangling FIDO2 directory symlinks.
migrations/1787494718.sh Repairs legacy authfile ownership and permissions.
test/shell.d/security-fido2-test.sh Tests secure enrollment staging and installation.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread migrations/1787494718.sh Outdated
Comment on lines +36 to +37
sudo chown root:root "$authfile"
sudo chmod 600 "$authfile"
Comment thread migrations/1787494718.sh
if [[ -L $authfile ]]; then
echo " $authfile is a symlink, not a regular file."
echo " Leaving it alone. If you did not create it, remove it and re-run Setup > Security > Fido2."
exit 0
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed this closely — Opus 5 for the first pass, with Codex at xhigh reasoning as an independent second opinion. Two defects found and fixed on your branch; one thing deliberately left for a maintainer decision; and one collision you should know about. Thanks for the writeup — the pam_u2f ownership analysis in it is right, and it's what made this worth landing.

Pushed

Both commits landed under @dhh's account rather than this one, because that is where the push credential sat — read that as where the bytes came from, not as a maintainer signing off on the change.

[55ad177] install without -T. install SRC DEST treats an existing directory at DEST as a destination directory: it drops the credential inside as /etc/fido2/fido2/tmp.XXXX, exits 0, and setup prints "FIDO2 device registered successfully" while PAM keeps reading a path that is not a file. -T makes that an error. Your already-registered check had the same blind spot from the other side — -f follows symlinks and is false for a directory, so it read a symlinked authfile as a registration and tried to register over a directory — so the guard now refuses any existing non-regular path with the same advice you wrote.

[d759911] The migration chowned in place. This is the one that matters. Permission is checked at open(2), not at write(2), so a descriptor the registering user opened on the authfile while it was still theirs stays writable through chown and chmod alike, and pam_u2f resolves /etc/fido2/fido2 to that same inode. The repair left exactly the state it exists to end — and then wrote its completion marker, so it never came back. It now installs a fresh root-owned copy and renames it over the path, which leaves any such descriptor writing to a file nothing reads. #7703 reached this independently; credit there.

Two test changes went with those. Your cleanup unlinked every staged path outside the scratch directory, taking the path from the script under test and already resolved through any symlink — against a script staging through one, that would have named a file of the user's and deleted it. It now unlinks only a file its own stub wrote into. And the /etc/fido2/fido2 early exit meant the whole file passed without exercising a single assertion on any machine that uses FIDO2; that branch now asserts what the host state actually promises — a regular authfile is still recognised and left alone, anything else is refused.

The migration had no test at all, so it has one now. It drives a scratch copy with the one path literal retargeted rather than reading the path from the environment: this migration hands install and mv to root, and an operand the caller can choose is a privileged write to anywhere. The copy is only as honest as the substitution, so the test fails if the migration stops naming the path exactly once.

Not pushed — your call, and the maintainer's

Mode 600 vs 644. pam_u2f drops to the authenticating uid before opening even an absolute authfile when openasuser is set, and it loads /etc/security/pam_u2f.conf by default whenever that file exists (pam-u2f.c:210-215, cfg.c:216 at the 1.4.0 tag Arch ships). Root-owned 600 is then unreadable where your user-owned file worked. Under sufficient that degrades to the password prompt, so it locks out only someone who has locked their password — narrow, but it is the one thing this PR takes away, and #7703 uses 644 for what looks like this reason. Changing it is one character and a judgement call about what that file is worth protecting from a read, so I left it alone rather than deciding it for you.

On the threat model

The /tmp symlink chain in the description does not complete on a stock Arch install. fs.protected_symlinks=1 ships in systemd's 50-default.conf, /tmp is a root-owned sticky 1777 tmpfs, and the victim's own unprivileged > redirect through another user's symlink there returns EACCES — so pamu2fcfg never runs and the sudo mv is never reached. I confirmed that on a private tmpfs with two uids: the link's owner writes through it fine, a second uid is refused, and the same write succeeds once the directory is not sticky. Your mv analysis is right — it does move the link itself, same filesystem and across — but for a different uid the redirect fails first. The same-uid case is real, and so is everything in "The half that needs no attacker", which needs no attacker, no race and no sysctl assumption: that is the finding this PR rests on, and it would read stronger led by it. Relatedly, the new -L guards defend a state no unprivileged account can create, since /etc and /etc/fido2 are both root-owned — worth keeping as cheap hardening, not worth describing as an exploit path.

Your Ctrl-C claim checks out, incidentally — I doubted it, reproduced it against a real terminal, and bash does run the EXIT trap before dying on SIGINT. No file is stranded.

Collision

#7703 fixes the same two defects — install -o root -g root for mv, mktemp for /tmp/fido2, plus a repair migration — and was opened two days earlier. Both PRs rewrite the same hunk of bin/omarchy-setup-security-fido2, so they cannot both merge. Neither covers everything: yours has the empty-pamu2fcfg guard, the omarchy-remove-security-fido2 fix, install -d on the directory and a test for the setup script; #7703 has the mode question above and had the inode-replacing repair from the start. Which one lands is the maintainer's call, not mine, and I have not touched that PR.

What was checked

./test/cli (116 assertions), both FIDO2 shell test files, and the setup test driven against four host states — no authfile, a regular one, a directory and a symlink — so every branch of it ran somewhere. The migration test was also run in a uid-mapped namespace to reach the settled-authfile case that a normal unprivileged run skips. Every assertion I added was checked against a mutation that defeats it, including a repair with the right install call, mode, content and cleanup that writes through the old inode — only the inode assertion catches that one. All of it ran in a sandbox with no network, no home directory and no credentials reachable, not on a disposable VM; the graphical suite was not run and is not affected.

Codex reviewed the original PR and then reviewed my changes, both at xhigh. On the first pass it contributed the missing -T, the openasuser regression and the unbounded rm -f in the test. On the second it caught two real problems in my own fixes: I had first made the migration read its path from OMARCHY_FIDO2_AUTHFILE, which hands a root install and mv an operand the environment chooses, and my test's sudo stub executed real commands without checking their operands. Both are gone — the stub now refuses anything whose operands sit outside its scratch directory, so the file is safe to run as root. I rejected one of its findings on the first pass: it said the EXIT trap survives Ctrl-C where I had measured otherwise, and on re-testing with a real pty it was right and I was wrong.

Waiting on a maintainer for the choice between this and #7703, and on you for the 600/644 question.

mdisec and others added 4 commits August 24, 2026 13:47
… /tmp path

pamu2fcfg wrote to /tmp/fido2 and the registration was then moved into place
with `sudo mv`. Any other local user can pre-create /tmp/fido2, and rename(2)
does not dereference the final component, so the privileged move installed the
attacker's symlink itself as pam_u2f's global authfile -- a file consulted by
`sufficient` lines in /etc/pam.d/sudo and /etc/pam.d/polkit-1.

The same move also carried the staged file's ownership into /etc, so on every
install to date /etc/fido2/fido2 is owned by the invoking user at mode 0644.
That needs no attacker: anything running as that uid can add its own credential
and satisfy the machine's sudo prompt without root.

Stage under mktemp and hand the bytes to `install` instead, so the authfile is
always a fresh root-owned regular file rather than an inode a non-root user
still controls. Guard the already-registered check with -L, which -f would
otherwise follow, and reject a symlinked /etc/fido2 in the remove path for the
same reason. A migration takes ownership of authfiles left behind by the old
code; it reports a symlink rather than repairing one, since chown would follow
it and removing it would strip sudo from anyone whose only credential is the
token.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012e6WagC5iUigCGoK1tQeFz
`install SRC DEST` without -T treats an existing directory at DEST as a
destination directory: it drops the credential inside as
/etc/fido2/fido2/tmp.XXXX, exits 0, and setup reports a successful registration
while PAM goes on reading a path that is not a file. -T makes that an error.

The already-registered check has the same blind spot from the other side. -f
follows symlinks, so it reads a symlinked authfile as a registration and leaves
it in place, and is false for a directory, so it tries to register over one.
Only a regular file is a pam_u2f authfile; anything else is now refused with the
same advice to remove it and set FIDO2 up again.

The test deleted every staged path that fell outside its scratch directory,
taking the path from the script under test and already resolved through any
symlink -- so a script staging through one would have named a file of the user's
and had it unlinked. It now unlinks only a file its own stub wrote into.

On a machine that already has /etc/fido2/fido2 the staging assertions cannot run
at all, and the file used to pass without exercising one of them. That branch now
asserts what the host state promises instead: a regular authfile still has to be
recognised as a registration and left alone, and anything else has to be refused.

Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>
Permission is checked at open(2), not at write(2), so a descriptor the
registering user opened on the authfile while it was still theirs stays writable
through chown and chmod alike. pam_u2f resolves /etc/fido2/fido2 to that same
inode, so the repair left the account it authenticates able to append a
credential it controls -- the exact state the migration exists to end, now
recorded as migrated and never revisited.

Installing a fresh root-owned copy and renaming it over the path leaves any such
descriptor writing to a file nothing reads. Credit to omacom#7703, which reached the
same conclusion independently. An interrupted run heals: the staged copy is
root-owned 600 and inert, no marker is written, and the next run replaces it.

A directory or device at the authfile path is no more ours to rewrite than a
symlink is, and chmod 600 on a directory would only make it untraversable, so
both are now reported rather than repaired.

The repair had no test, because it names an absolute path no unprivileged suite
can write. It is exercised through a scratch copy with that one literal
retargeted, rather than by reading the path from the environment: the migration
hands `install` and `mv` root, and an operand the caller can choose is a
privileged write to anywhere. The copy is only as honest as the substitution, so
the test fails if the migration stops naming the path exactly once.

Covered: the no-op on a machine that never registered a key, which must not cost
a password prompt; the repair itself; the new inode; the absence of a staged copy
afterwards; a second account finding it done; and the symlink and non-regular
cases. Each assertion was checked against a mutation that defeats it -- notably a
repair with the right install call, mode, content and cleanup that writes through
the old inode, which only the inode assertion catches.

Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>
@mdisec
mdisec force-pushed the security-fido2-authfile-tmp-symlink branch from d759911 to 11b87bd Compare August 24, 2026 12:48
dhh and others added 3 commits August 25, 2026 09:50
install -d follows a symlink at /etc/fido2 and applies the mode and ownership to whatever it points at, so the credential would be staged and published inside the link target and that directory silently reopened to root:root 755. The leaf guard above it only covered fido2 itself, and this is the same threat omarchy-remove-security-fido2 already names on its side.

mktemp's output is an operand for a privileged tee, chmod, mv and rm. The migration validates it before any of them run; the setup did not, so take only the name it asked for there too.

The suite was guarded on the host's own /etc/fido2/fido2 and exited early when one existed, which meant the staging assertions asserted nothing on exactly the machines that use FIDO2. Drive a retargeted copy the way the migration suite already does, so every branch is a fixture and all of them run everywhere.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
omarchy-migrate writes the per-user completion marker on any zero exit, so the two states this migration cannot repair got one line in the update terminal and were then silenced for good: no login notice, no re-run, the migration recorded as done having repaired nothing. Those are precisely the machines where the authfile may already be under someone else's control, so raise them through omarchy-notification-send as well, where they outlive the scrollback. Delivery is best-effort: a machine with no user bus or no notification server must not abort the migration and take every later one with it.

The early exit had the same shape of problem. It read the authfile unprivileged, and the old setup created /etc/fido2 with `sudo mkdir -p`, which took the union of the caller's umask and sudoers' 0022 — so registering under `umask 077` left the directory mode 0700 with the user-owned authfile still inside. Absence and "cannot look" are the same answer to those tests, and the migration exited 0 and marked itself complete. Ask root whether a registration is actually behind an untraversable directory before reopening it, so an aborted setup that left an empty directory, or one an administrator keeps private, does not have its mode widened and its group and special bits discarded for a repair it does not need. A machine that never set FIDO2 up has no directory here and still reaches exit 0 without a password prompt.

The notification assertion checks argument shape rather than a substring of the command line. The glyph is a private-use codepoint, and losing it shifts every argument left: -g swallows the headline, the body becomes the title, and the message goes out with no description — which a substring match reads as a pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>
The -d to -e || -L change is load-bearing for the threat its own comment names — a dangling link at /etc/fido2 that -d reads as absent, left for the next setup to install an authfile through — and it was the one part of this work with no test behind it. Name the directory once so the suite can retarget a copy, the same seam the setup and migration suites use, and assert both halves: the link goes, and the directory it pointed at does not.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed this and pushed three commits. Everything below was verified against the source before it was acted on, and every fix is proven by breaking it on purpose and watching its test fail. The second opinion came from Codex at xhigh, and it found a real bug in my own first attempt at these fixes.

What I pushed

Guard the FIDO2 directory and the stage path the setup writes through. The leaf guard covered fido2 but not /etc/fido2 itself, and sudo install -d -m 755 -o root -g root follows a symlink there. I confirmed on coreutils 9.11 that install -d -m 755 against a symlink-to-directory exits 0, leaves the link in place, and takes the target from 700 to 755 — so the credential would have been staged and published inside the link target, with that directory silently reopened to root:root 755. That is the same threat omarchy-remove-security-fido2:27-29 already names on its side, so the PR was closing it on removal and leaving it open on setup. The same commit validates sudo mktemp's output before it reaches sudo tee, sudo chmod, sudo mv -Tf and the trap's sudo rm -f — the migration already did this with safe_stage_path, the setup did not, and the setup is the one that also hands the string to a privileged rm.

That commit also had to fix the suite before either change could be tested at all: it was guarded on the host's real /etc/fido2/fido2 and exited 0 after two assertions when one existed, so the headline staging coverage asserted nothing on exactly the machines that actually use FIDO2. It now drives a sed-retargeted copy of the setup, the same seam your migration suite already uses, so every branch is a fixture and all of them run everywhere.

Stop the FIDO2 migration recording a repair it never made. bin/omarchy-migrate:91-96 writes the per-user completion marker on any zero exit, so the symlink and non-regular branches printed one line into the update terminal and were then silenced for good — no login notice, no re-run, the migration recorded as complete having repaired nothing, on precisely the machines where the authfile may already be under someone else's control. Those now also go out through omarchy-notification-send, best-effort so a machine with no user bus does not abort the migration and take every later one with it. The early exit had the same shape of problem: it read the authfile unprivileged, and the old sudo mkdir -p /etc/fido2 took the union of the caller's umask and sudoers' 0022, so anyone registering under umask 077 left the directory at 0700 with their user-owned authfile still inside. Absence and "cannot look" are the same answer to [[ -e ]] — I verified that — and the migration exited 0 and marked itself done.

Cover the FIDO2 removal's symlink guard. The -d to -e || -L change is load-bearing for the threat its own comment names, and it was the one part of this work with no test behind it while the PR added 800-odd lines of coverage for the other two files.

What I did not change: the 600 to 644 relaxation is right

I went in expecting to argue with this one and came out agreeing with you. Upstream util.c:715 warns only on group/other-writable and its own message names 0644 as the reference mode, and the file holds a username, keyhandle and public key rather than a secret. And while pam-u2f.c:194 skips resolve_authfile_path() for an absolute authfile= — so Omarchy's own PAM lines never get the automatic privilege drop — pam-u2f.c:210-211 still drops privileges whenever cfg->openasuser is set, and cfg.c:211 loads /etc/security/pam_u2f.conf before the PAM arguments are applied. An administrator with openasuser in that file has pam_u2f read the authfile as the authenticating user, where root:600 would lock them out. Codex reached the same conclusion from the same source. Keep 644.

Tests

Run on a disposable worker VM, never on the machine holding credentials: 39 assertions across the three FIDO2 suites, all green, plus bin-style-test.sh. Nine mutations, each breaking exactly one fix, and every one of them failed the suite that is supposed to catch it.

What the second opinion added

Codex at xhigh caught a real defect in my own fix. The notification glyph is a private-use codepoint that my edit silently dropped, which shifts every argument one place left: -g swallows the headline, the body becomes the title, and the message goes out with no description. My test passed anyway, because it matched a substring of the flattened command line — exactly the kind of vacuous pass I had just spent two commits removing elsewhere. The assertion now checks argument shape instead. It also showed that my inaccessible-directory predicate was broader than its own rationale: an aborted setup that left an empty 0700 directory, or one an administrator keeps deliberately private, would have been escalated for and widened to 755 for a repair it did not need. The migration now asks root whether a registration is actually behind the directory before touching its mode. Both are folded into the pushed commits, and Codex is co-authored on the one that carries them.

I rejected nothing of substance from it. Its one remaining note — that the sudo test -s arm in the setup stub is dead, since production uses bash's [[ -s $stage ]] — is correct, and I left it alone rather than tidying your harness around it.

One thing left for the maintainer, not for you

The settled-state check validates the authfile but not its parent directory, so if /etc/fido2 were ever user-owned, a root:root 644 authfile inside it reads as settled while that user can still unlink and replace it. It needs pre-existing root misconfiguration and nothing in Omarchy creates that state, so it is not a regression in this PR — but how far the migration should go there is a judgement call rather than something to patch quietly, so I left it.

@dhh
dhh merged commit 23dab9e into omacom:quattro Aug 25, 2026
omarchybot pushed a commit that referenced this pull request Aug 25, 2026
… /tmp path (backport of #7904)

Backport of the FIDO2 authfile fix (PR #7904 by @mdisec, merged to quattro as
23dab9e) onto the v4-0-1 release branch.

pamu2fcfg wrote to /tmp/fido2 and the registration was then moved into place
with sudo mv. Any other local user can pre-create /tmp/fido2, and rename(2) does
not dereference the final component, so the privileged move installed the
attacker's symlink itself as pam_u2f's global authfile -- a file consulted by
sufficient lines in /etc/pam.d/sudo and /etc/pam.d/polkit-1.

The same move also carried the staged file's ownership into /etc, so on every
install to date /etc/fido2/fido2 is owned by the invoking user at mode 0644.
That needs no attacker, no race and no second account: anything running as that
uid can append its own credential and satisfy the machine's sudo prompt without
knowing the password.

The setup now creates a unique staging file as root beside the final authfile
and pipes pamu2fcfg into it, so root never reopens a caller-owned pathname,
rejects failed or empty enrollment output, publishes with an atomic mv -Tf,
cleans the exact staging file after every failure, refuses non-regular authfile
states, and installs root:root 0644. A migration repairs machines set up by
earlier versions by replacing the inode rather than chowning in place: a process
that already holds a writable descriptor on the legacy user-owned mapping keeps
it, so the repair has to leave that inode behind where PAM no longer reads it.

Clean cherry-pick: all six files are byte-identical to quattro, so merging
v4-0-1 into quattro resolves without a conflict. The migration's timestamp
(1787494718) is older than others already on this branch, which is harmless:
omarchy-migrate marks each migration by filename rather than tracking a
watermark, so this one runs on every machine that has not run this exact file.

test/shell passes: 195 files, including the three this adds -- the setup's
staging and failure paths, the migration's repair and unrepairable states, and
the removal's symlink handling. test/cli passes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_018DEMYa9UWtroz93DhMTtcV
@omarchybot omarchybot mentioned this pull request Aug 25, 2026
nick1udwig pushed a commit to nick1udwig/omarchy that referenced this pull request Sep 9, 2026
… /tmp path (omacom#7904)

* [Security] Stop the FIDO2 setup staging its authfile at a predictable /tmp path

pamu2fcfg wrote to /tmp/fido2 and the registration was then moved into place
with `sudo mv`. Any other local user can pre-create /tmp/fido2, and rename(2)
does not dereference the final component, so the privileged move installed the
attacker's symlink itself as pam_u2f's global authfile -- a file consulted by
`sufficient` lines in /etc/pam.d/sudo and /etc/pam.d/polkit-1.

The same move also carried the staged file's ownership into /etc, so on every
install to date /etc/fido2/fido2 is owned by the invoking user at mode 0644.
That needs no attacker: anything running as that uid can add its own credential
and satisfy the machine's sudo prompt without root.

Stage under mktemp and hand the bytes to `install` instead, so the authfile is
always a fresh root-owned regular file rather than an inode a non-root user
still controls. Guard the already-registered check with -L, which -f would
otherwise follow, and reject a symlinked /etc/fido2 in the remove path for the
same reason. A migration takes ownership of authfiles left behind by the old
code; it reports a symlink rather than repairing one, since chown would follow
it and removing it would strip sudo from anyone whose only credential is the
token.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012e6WagC5iUigCGoK1tQeFz

* Install the FIDO2 authfile with -T and refuse a non-regular path

`install SRC DEST` without -T treats an existing directory at DEST as a
destination directory: it drops the credential inside as
/etc/fido2/fido2/tmp.XXXX, exits 0, and setup reports a successful registration
while PAM goes on reading a path that is not a file. -T makes that an error.

The already-registered check has the same blind spot from the other side. -f
follows symlinks, so it reads a symlinked authfile as a registration and leaves
it in place, and is false for a directory, so it tries to register over one.
Only a regular file is a pam_u2f authfile; anything else is now refused with the
same advice to remove it and set FIDO2 up again.

The test deleted every staged path that fell outside its scratch directory,
taking the path from the script under test and already resolved through any
symlink -- so a script staging through one would have named a file of the user's
and had it unlinked. It now unlinks only a file its own stub wrote into.

On a machine that already has /etc/fido2/fido2 the staging assertions cannot run
at all, and the file used to pass without exercising one of them. That branch now
asserts what the host state promises instead: a regular authfile still has to be
recognised as a registration and left alone, and anything else has to be refused.

Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>

* Replace the FIDO2 authfile inode rather than chowning it in place

Permission is checked at open(2), not at write(2), so a descriptor the
registering user opened on the authfile while it was still theirs stays writable
through chown and chmod alike. pam_u2f resolves /etc/fido2/fido2 to that same
inode, so the repair left the account it authenticates able to append a
credential it controls -- the exact state the migration exists to end, now
recorded as migrated and never revisited.

Installing a fresh root-owned copy and renaming it over the path leaves any such
descriptor writing to a file nothing reads. Credit to omacom#7703, which reached the
same conclusion independently. An interrupted run heals: the staged copy is
root-owned 600 and inert, no marker is written, and the next run replaces it.

A directory or device at the authfile path is no more ours to rewrite than a
symlink is, and chmod 600 on a directory would only make it untraversable, so
both are now reported rather than repaired.

The repair had no test, because it names an absolute path no unprivileged suite
can write. It is exercised through a scratch copy with that one literal
retargeted, rather than by reading the path from the environment: the migration
hands `install` and `mv` root, and an operand the caller can choose is a
privileged write to anywhere. The copy is only as honest as the substitution, so
the test fails if the migration stops naming the path exactly once.

Covered: the no-op on a machine that never registered a key, which must not cost
a password prompt; the repair itself; the new inode; the absence of a staged copy
afterwards; a second account finding it done; and the symlink and non-regular
cases. Each assertion was checked against a mutation that defeats it -- notably a
repair with the right install call, mode, content and cleanup that writes through
the old inode, which only the inode assertion catches.

Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>

* Finish hardening FIDO2 authfile installation

* Guard the FIDO2 directory and the stage path the setup writes through

install -d follows a symlink at /etc/fido2 and applies the mode and ownership to whatever it points at, so the credential would be staged and published inside the link target and that directory silently reopened to root:root 755. The leaf guard above it only covered fido2 itself, and this is the same threat omarchy-remove-security-fido2 already names on its side.

mktemp's output is an operand for a privileged tee, chmod, mv and rm. The migration validates it before any of them run; the setup did not, so take only the name it asked for there too.

The suite was guarded on the host's own /etc/fido2/fido2 and exited early when one existed, which meant the staging assertions asserted nothing on exactly the machines that use FIDO2. Drive a retargeted copy the way the migration suite already does, so every branch is a fixture and all of them run everywhere.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* Stop the FIDO2 migration recording a repair it never made

omarchy-migrate writes the per-user completion marker on any zero exit, so the two states this migration cannot repair got one line in the update terminal and were then silenced for good: no login notice, no re-run, the migration recorded as done having repaired nothing. Those are precisely the machines where the authfile may already be under someone else's control, so raise them through omarchy-notification-send as well, where they outlive the scrollback. Delivery is best-effort: a machine with no user bus or no notification server must not abort the migration and take every later one with it.

The early exit had the same shape of problem. It read the authfile unprivileged, and the old setup created /etc/fido2 with `sudo mkdir -p`, which took the union of the caller's umask and sudoers' 0022 — so registering under `umask 077` left the directory mode 0700 with the user-owned authfile still inside. Absence and "cannot look" are the same answer to those tests, and the migration exited 0 and marked itself complete. Ask root whether a registration is actually behind an untraversable directory before reopening it, so an aborted setup that left an empty directory, or one an administrator keeps private, does not have its mode widened and its group and special bits discarded for a repair it does not need. A machine that never set FIDO2 up has no directory here and still reaches exit 0 without a password prompt.

The notification assertion checks argument shape rather than a substring of the command line. The glyph is a private-use codepoint, and losing it shifts every argument left: -g swallows the headline, the body becomes the title, and the message goes out with no description — which a substring match reads as a pass.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Codex XHigh <[email protected]>

* Cover the FIDO2 removal's symlink guard

The -d to -e || -L change is load-bearing for the threat its own comment names — a dangling link at /etc/fido2 that -d reads as absent, left for the next setup to install an authfile through — and it was the one part of this work with no test behind it. Name the directory once so the suite can retarget a copy, the same seam the setup and migration suites use, and assert both halves: the link goes, and the directory it pointed at does not.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: David Heinemeier Hansson <[email protected]>
Co-authored-by: Codex XHigh <[email protected]>
@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.

5 participants