Skip to content

Publish the debug and upload logs owner-only, and never through a /tmp symlink - #14078

Open
Davedes83 wants to merge 4 commits into
omacom:quattrofrom
Davedes83:fix/debug-and-upload-log-tmp-symlink
Open

Davedes83 wants to merge 4 commits into
omacom:quattrofrom
Davedes83:fix/debug-and-upload-log-tmp-symlink

Conversation

@Davedes83

@Davedes83 Davedes83 commented Oct 2, 2026 •

Copy link
Copy Markdown

Summary

omarchy debug published its log to a fixed name in world-writable /tmp with a plain redirection:

LOG_FILE="/tmp/omarchy-debug.log"
cat > "$LOG_FILE" <<EOF

Three things were wrong with that, in descending order of how much they matter in practice:

  1. The log was world-readable. The redirection created it mode 0644, and it carries the hostname, the full
    hardware inventory, every explicitly installed package and journalctl -b -p 4..1 for the boot, so every local
    uid could read all of that until the next reboot. fs.protected_regular does not cover this — it restricts
    opening for writing, not reads.

  2. The name is fixed and shared, and a redirection follows it. Whatever another local process left at that
    name was written through, so running omarchy debug truncated and replaced whatever it pointed at, in any
    file the invoking user can write:

    $ ln -s ~/.bashrc /tmp/omarchy-debug.log      # any other local uid can do this
    $ omarchy debug --no-sudo --print
    $ head -3 ~/.bashrc
    Date: Fri Oct  2 21:44:11 CEST 2026
    Hostname: wibble
    Omarchy Package: omarchy 4.0.4-1

    On a default install this is not reachable across a uid boundary: fs.protected_symlinks=1 blocks one uid
    following another's symlink in a sticky directory, and the demonstration above plants the link as the same
    uid that then runs omarchy debug. It is included as the invariant to hold, not as a live exploit. A
    maintainer declined this family of change on 2026-10-04 in Stage diagnostics logs privately instead of at fixed /tmp paths #7995 and [Security] omarchy debug and omarchy upload log stage root-collected diagnostics at predictable /tmp paths #8367, and I am not re-opening that —
    what I am asking for is the housekeeping those discussions called reasonable but not urgent.

  3. The log stayed behind. Nothing removed it between runs.

omarchy upload-log had the same shape in two files (/tmp/upload-log.txt, /tmp/system-info.txt) and is the
only Omarchy script that stages host-identifying data in /tmp. It has no caller in the tree at the moment, so
it is fixed here rather than left to be wired up later.

Change

Stage each log in a private mktemp file in the destination's directory, then publish it with mv -fT. The
rename replaces the name instead of following it, and keeping the staging file in the same filesystem matters:
cross-device mv falls back to a copy that reopens the destination the unsafe way. The published log is 0600,
since what it holds is the machine's identity.

/tmp is sticky, so the rename fails with EPERM when the published name is already owned by another uid — a
stale log left by a different account on a shared machine. The code falls back to the staged file and says so on
stderr, rather than exiting with no log at all, which would be worse than what the pre-fix script did: it always
produced one, even when it followed a symlink.

bin/omarchy-debug keeps its documented /tmp/omarchy-debug.log path — agents/skills/omarchy/SKILL.md,
agents/skills/omarchy/contributing.md and agents/skills/diagnose-crash/reporting.md all name it — so this is
a same-path fix, not a move. @jandrusk has a per-user directory approach open in #14479; I am deliberately leaving
it out of this branch rather than landing three overlapping fixes, but I would fold it in if that is the
preferred direction.

Tests

test/shell.d/debug-log-test.sh, 16 assertions:

  • a symlink planted at the log name is not written through (the canary file is byte-identical afterwards)
  • the symlink is replaced by a regular file carrying the diagnostics
  • --print still emits the log
  • the published log is owner-only
  • no staging file is left behind
  • omarchy debug still exits 0 and still produces a log when the rename is refused, and says where the log
    went instead
  • omarchy upload-log leaves /tmp/upload-log.txt and /tmp/system-info.txt untouched, collects into private
    temporaries, removes them, and still uploads and reports the URL
  • the file curl was actually handed existed, carried the diagnostics, was 0600 while it sat in /tmp, and
    was not one of the two fixed names

Collection is stubbed, so the test needs no sudo, no network and nothing installed beyond coreutils. The
refused-rename test stubs mv to fail rather than creating a file owned by a second uid, so it runs without
root: that covers the fallback path, not the kernel's actual EPERM.

The new test fails against the unpatched scripts:

not ok - omarchy debug does not write through a symlink another local process planted
canary now reads: Date: [stub date]
Hostname: [stub hostname]
...

Full suite, test/shell (291 files) and test/cli: no new failures. 10 test/shell files and 1 test/cli
assertion fail identically on a clean quattro checkout — config-test, kernel-headers-migration-test,
launch-browser-test, network-captive-portal-test, omarchy-kernel-migration-test,
passwordless-grant-lifecycle-test, screenshot-sanity-test, snapper-test, unowned-system-paths-test,
video-background-test, and vscode generated theme references current theme file. Verified by re-running each
against the pre-fix scripts.

Note on severity

This is a robustness and housekeeping change, and it should be reviewed as one. The disclosure in the first
bullet above is real on a multi-user machine, but the other party is another local uid: a stock Omarchy install
has a single human account in wheel, and the sysctls block the cross-user symlink follow in the second
bullet. I would not claim this as a privilege escalation.

The unprivileged services on the box do share the host /tmp — only 39 of 382 shipped .service units set
PrivateTmp=yes — so a name left there by another process is reachable. What the sysctls prevent is the
follow, not the plant.

Two related things I did not touch, in case you want them handled separately:

  • bin/omarchy-update:88 writes /tmp/omarchy-update.log through script, which opens the typescript with
    O_CREAT|O_TRUNC and so follows a symlink too. Different sink, and it sits close to in-flight update work.
  • bin/omarchy-update-analyze-logs:5 reads that same fixed path.

`omarchy debug` published to a fixed name in world-writable /tmp with a
plain redirection, so a symlink another local process left there was
written through: running `omarchy debug` truncated and replaced whatever
it pointed at, in any file the invoking user could write. The log the
redirection created was world-readable, and carries the hostname, the
hardware inventory, every explicitly installed package and this boot's
journal.

`omarchy upload-log` had the same shape in two files, and is the only
Omarchy script that stages host-identifying data in /tmp.

Stage each log in a private file in the same directory and publish it
with a rename, which replaces the name instead of following it, and
publish it owner-only. The staging file stays in the destination's
filesystem so mv renames rather than falling back to a copy that would
open the destination the unsafe way.
@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[High impact] The PR appears safe to merge; no new actionable issues were found.

Summary

The PR creates private log files before publishing or uploading them.

  • omarchy-debug replaces the fixed name with a rename and keeps the private file if that rename fails.
  • omarchy-upload-log uses private temporary files and removes them after the upload.
  • The tests check symlink safety, file permissions, upload contents, cleanup, and refused renames.
  • Davedes83 explicitly chose the alternate debug path when the fixed name cannot be replaced.

Reviews (5) · Last reviewed commit: "Fall back to the staged log when the ren..." · Reviewed by Greptile

Comment thread test/shell.d/debug-log-test.sh Resolved
Comment thread bin/omarchy-upload-log Resolved
Comment thread test/shell.d/debug-log-test.sh Resolved
… test

Greptile found three problems with the previous commit:

- omarchy-upload-log installed its cleanup trap only after both mktemp calls,
  so a second failure -- /tmp filling up between them -- exited with the first
  file still in place. Remove it on the failure path.

- The test's cleanup removed every file matching the staging prefixes and
  deleted the legacy fixed paths outright, so a helper running at the same time
  could lose its working file and any pre-existing log was destroyed. Copy the
  fixed paths aside and restore them, and remove only the staging files the run
  itself created.

- The upload assertions only checked that the old symlinks survived, so a
  missing or world-readable upload would still have passed. Have the curl stub
  report on the file it was handed and assert that it existed, carried the
  diagnostics, was owner-only while it sat in /tmp, and was no longer one of
  the fixed names.

Co-Authored-By: Davedes83 <me@email.com>
@Davedes83

Copy link
Copy Markdown
Author

All three addressed in 41b2da4c. Thanks — the leak was the real one.

P1 — tests delete unrelated logs. Real, and worse than I first wrote. cleanup was
rm -f /tmp/omarchy-debug.*, which matches anything with that prefix, and it deleted
/tmp/upload-log.txt and /tmp/system-info.txt outright rather than saving them.

The test now copies all three fixed paths aside before it starts and restores them on the way
out. For the randomly-named staging files it snapshots which ones match the prefixes before
the run and removes only the difference afterwards, so a helper running concurrently keeps its
own working file.

Verified by pre-seeding four artifacts — a real omarchy-debug.log, a real upload-log.txt, a
real system-info.txt, and a decoy omarchy-debug.deadbeef standing in for another process's
staging file — running the suite, and confirming all four come back byte-identical.

P2 — failed uploads leave files. Correct, and my git checkout during fail-before testing
had briefly reverted the fix before I caught it, so this one had gone unverified. Now
TEMP_LOG=$(mktemp …) || { rm -f "$SYSTEM_INFO"; exit 1; }.

Confirmed with a mktemp stub that succeeds once and then fails, simulating /tmp filling up
between the two calls: pre-fix leaves /tmp/omarchy-system-info.XXXX behind, post-fix leaves
nothing.

P2 — upload test ignores the file. Agreed, that assertion was hollow. The curl stub now
parses the file=@ argument and writes a report the test reads, so four new assertions look at
the file that was actually uploaded: it existed at upload time, carried the diagnostics, was
0600 while it sat in /tmp, and was not one of the two fixed names.

Note the mode check is now done inside the stub, at upload time — checking afterwards was never
possible because the script's own trap removes the file before the test can look at it.

Suite is 13 assertions, passes on the fix and fails on the unpatched scripts. Full test/shell
still 291 files with the same 10 pre-existing failures, no new ones.

Greptile was right that the previous cleanup could still delete a helper's
working file: snapshotting the staging names before the run only protects
files that already existed, so a helper that started after the snapshot lost
its file to the diff.

Replace the scan with an mktemp stub that records every path it hands out.
The test now removes, and asserts on, exactly those paths, so it can neither
touch a concurrent helper's file nor a stale one from an earlier run.

Verified by running the suite against a background process creating 400
staging-named files in /tmp throughout: all 400 survive.
@Davedes83

Copy link
Copy Markdown
Author

Greptile was right that the P1 fix was incomplete — it only protected files that existed
before the snapshot, so a helper that started after it still lost its working file to the diff.
Fixed in 06ed1a3a.

The scan of /tmp is gone entirely. An mktemp stub delegates to the real /usr/bin/mktemp and
records every path it hands out, so the test knows exactly which files the helpers created.
Cleanup removes only those paths, and the "no staging file left behind" assertion now walks that
same list instead of globbing. It cannot reach a concurrent helper's file, a stale one from an
earlier run, or anything else in /tmp.

Verified by running the suite against a background process that created 400 staging-named files in
/tmp throughout the run:

concurrent helper files: survived=400  deleted-by-test=0

And with the fixed paths plus a decoy pre-seeded before the run, all four come back
byte-identical.

One note on my own testing, since it bit me twice: git checkout HEAD~1 -- is not the pre-fix
tree here — that commit already carries the fix. The true pre-fix revision is HEAD~2
(STAGED_LOG=0, mktemp=0 in both scripts), and the suite fails against it and passes against
the fix. Worth stating because my first fail-before run silently tested the wrong revision and
appeared to pass.

Suite is now 14 assertions. Full test/shell still 291 files, same 10 pre-existing failures, no
new ones.

@jandrusk

jandrusk commented Oct 6, 2026

Copy link
Copy Markdown

Thanks for the thorough tests. Two things worth knowing before review:

  1. Precedent: Stage diagnostics logs privately instead of at fixed /tmp paths #7995 and [Security] omarchy debug and omarchy upload log stage root-collected diagnostics at predictable /tmp paths #8367 covered the same /tmp/omarchy-debug.log / upload-log paths and were closed on 10-04. The maintainer's reasoning was that it isn't a vulnerability for Omarchy's single-user desktop setup. If you want this considered, it may land better framed as robustness (owner-only log, no stale files) than as a security fix.
  2. Functional nit: /tmp is sticky, so mv -fT fails with EPERM when /tmp/omarchy-debug.log already exists and belongs to another uid. That includes a stale log from a different user on a shared machine. omarchy debug then exits 1 with no log at all. Falling back to the private staged file keeps the command working:
if ! mv -fT "$STAGED_LOG" "$LOG_FILE" 2>/dev/null; then
  LOG_FILE=$STAGED_LOG
  trap - EXIT
  echo "Note: $LOG_FILE is used instead of /tmp/omarchy-debug.log" >&2
fi

@omarchybot

Copy link
Copy Markdown
Collaborator

Read, not yet run: the classification of this pull request is unsettled, so no class label went on and nothing was tested on a worker.

Two models classified it separately and disagreed. Codex Medium read it as a bug fix, going by the description. I (Claude Opus 5.5) read it as an enhancement, because the maintainer declined this family of changes on 2026-10-04 when closing #7995, #8367 and #12109, which covered the same /tmp/omarchy-debug.log and upload-log paths: on a default install fs.protected_symlinks and fs.protected_regular already block the cross-user symlink redirect, and the demonstration above plants the symlink as the same user who runs omarchy debug, which crosses no boundary. What is left, an owner-only log and staging files removed on exit, is the housekeeping that decision called reasonable but not a security priority.

Not checked: @jandrusk's point that mv -fT into sticky /tmp fails with EPERM when another uid already owns /tmp/omarchy-debug.log, leaving omarchy debug with no log. That would matter if this is taken as housekeeping.

Waiting on the maintainer to decide whether this is wanted given that earlier decision.

@Davedes83

Copy link
Copy Markdown
Author

On the classification question -- both readings are fair, and I'm not going to argue the second one away. I did check the underlying claim rather than take it on trust:

  • fs.protected_symlinks=1 and fs.protected_regular=1 are both set on a default install, so the cross-user symlink follow in my demonstration is blocked. The demonstration plants the link as the same uid that then runs omarchy debug, so as written it crosses no boundary. Treating this as a security fix was wrong.
  • The rest of the setup does hold, for what it's worth: only 39 of the 382 shipped .service units set PrivateTmp=yes, so most unprivileged services do share the host /tmp and can leave a name there. The sysctls block the follow, not the plant.

What survives that is the half protected_regular does not cover. It restricts opening for writing; it does nothing about reads. The old 0644 log let any other local uid read the hostname, the full hardware inventory, every explicitly installed package and this boot's journalctl -b -p 4..1, and stayed that way until the next reboot. Publishing 0600 fixes that, and I'd rather lead with it -- an owner-only log is a one-word diff that needs no severity argument at all.

So I'm treating this as one robustness change: don't write through a name you don't own, don't leave the result readable, don't leave the staging file behind. Happy to re-title it that way if that's what lands. I don't want to re-open #7995 or #8367.

On @jandrusk's EPERM point -- correct, and thank you, because it's a regression I introduced rather than a pre-existing wart. mv -fT into a sticky /tmp fails when the published name is owned by another uid, and the code as it stood exited 1 with no log at all, which is worse than what it replaced: the pre-fix script always produced one, even when it followed a symlink. Fixed in d0906fb with the fallback you proposed, plus a test that stubs mv to refuse so it runs without a second uid. Suite is 17 assertions.

On #14109 and #14479: happy to fold in @jandrusk's per-user directory and drop the mktemp-in-/tmp staging if that's the direction you want -- I'd rather one change than three overlapping ones. The reason I kept staging in /tmp rather than moving is that bin/omarchy-debug documents /tmp/omarchy-debug.log in three places and the crash diagnostics instructions point people at it. A per-user directory keeps it in XDG_RUNTIME_DIR, which is 0700 and per-login, and I'd want that as a separate, visible change rather than a silent behaviour change bundled in here.

Still not touched, and I agree with leaving them: bin/omarchy-update:88 writes /tmp/omarchy-update.log through script, which opens the typescript with O_CREAT|O_TRUNC, and bin/omarchy-update-analyze-logs:5 reads that same fixed path.

@Davedes83 Davedes83 changed the title Stop the debug and upload logs following a symlink in /tmp Publish the debug and upload logs owner-only, and never through a /tmp symlink Oct 15, 2026
/tmp is sticky, so mv -fT fails with EPERM when the published name is
already owned by another uid -- a stale log from a different account on a
shared machine. The previous commit exited 1 in that case, leaving no log
at all, which is worse than the behaviour it replaced: the old script
always produced one, even when it followed a symlink.

Keep the staged file as the log instead, say on stderr where it went, and
drop the exit trap so the file survives as the published log.

The test stubs mv to refuse rather than creating a second-uid-owned file,
so it runs without root. The fallback deliberately survives the run, so it
is removed before the "leaves no staging file behind" assertion, which
would otherwise read it as a leftover.

Suite is 16 assertions, passes on the fix and fails against the unpatched
script. Full test/shell still 291 files with the same 10 pre-existing
failures.

Co-Authored-By: Davedes83 <me@email.com>
@Davedes83
Davedes83 force-pushed the fix/debug-and-upload-log-tmp-symlink branch from d0906fb to ae6c3da Compare October 15, 2026 16:56
@Davedes83

Copy link
Copy Markdown
Author

Correction: the suite is 16 assertions, not the 17 I said above and in the commit message.

I miscounted when adding the refused-rename test -- it contributes two pass calls, not three. The check that the fallback log carries the diagnostics is folded into "omarchy debug says where the log went instead" rather than being its own assertion. d0906fb was reworded in ae6c3da.

Nothing else changes: the fallback and its behaviour are as described.

@omarchybot

Copy link
Copy Markdown
Collaborator

Looked at again because the head moved to ae6c3dad. It has been read, not run. The classification is still unsettled, so it has no class label and nothing was tested on a worker.

Two models classified this head separately and still disagree. Codex Medium reads it as a bug fix. I (Claude Opus 5.5) read it as an enhancement. In the 2026-10-04 decision closing #7995, #8367 and #12109, the maintainer said the default fs.protected_symlinks and fs.protected_regular already block the cross-user redirect, and declined this family of changes as a security priority, while noting that private staging and cleanup "can be reasonable housekeeping". The description now frames it the same way, so what is left is a deliberate behaviour change (an owner-only log, staged by rename, cleaned up on exit) rather than a defect on quattro.

Since the last comment, the EPERM case that @jandrusk raised has been handled. From reading bin/omarchy-debug: when mv -fT is refused, the script keeps the 0600 staged file as the log, clears the cleanup trap so the file survives, and says on stderr where the log is. A refused rename therefore no longer leaves omarchy debug without a log. The new test covers this by stubbing mv, not with a second uid.

#14479 is also open and changes the same two scripts in a different way, moving the logs to a per-user runtime directory. The two will conflict. Choosing between them, or taking neither, is the maintainer's decision.

This is waiting on the maintainer to decide whether this housekeeping is wanted, given that earlier decision, and if so, which of #14078 and #14479.

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