Repository navigation
fix(helper): write logs and debug images as the user, not root - #196
Merged
Merged
Conversation
phucvinh57
force-pushed
the
fix/helper-symlink-chown
branch
2 times, most recently
from
October 31, 2026 19:22
5c7eb97 to
2ebf206
Compare
phucvinh57
force-pushed
the
fix/helper-symlink-chown
branch
2 times, most recently
from
October 31, 2026 19:26
69c5325 to
673ca63
Compare
1 of 7 tasks
phucvinh57
marked this pull request as ready for review
October 31, 2026 19:39
With debug on, the root-run helper created ~/.local/share/.../logs/<day>.log and then chown()ed it to the user. chown() follows symlinks, so a symlink planted in the user-writable log or debug dir could make root hand ownership of another file to the user. Debug face images had the same problem, and mkdir used 0777. Add ScopedFsUser (per-thread setfsuid/setfsgid). While it is held the kernel drops root's file capabilities, so every path component is checked with the user's permissions and new files are owned by the user. Use it for setupConfig, the log sink and saveFailedFace; remove fixOwnership; create data dirs 0700; refuse unknown users instead of falling back to $HOME or /. The helper drops root's supplementary groups before auth so they don't apply under the guard. fs_user_test plants symlinks and checks writes are denied. It needs root (CI runs it with sudo; locally: unshare --map-root-user --map-auto).
phucvinh57
force-pushed
the
fix/helper-symlink-chown
branch
from
October 31, 2026 20:03
673ca63 to
2ffdd64
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security fix. With debug on, the root-run helper created the log file in a user-writable dir and then
chown()ed it to the user.chown()follows symlinks, so a symlink placed in that dir could make root change ownership of a file outside it. Debug face images had the same problem, and dirs were created 0777. File writes into user dirs now run with the user's filesystem identity, so the kernel checks them with the user's permissions. Part of the stacked audit PRs starting at #193 (audit).Closes: N/A / Discussion: N/A
Changes
ScopedFsUser(per-threadsetfsuid/setfsgid). While held, the kernel drops root's file capabilities, so every path component is checked as the user and new files are owned by the user.setupConfigruns under it;fixOwnershipremoved; data dirs created 0700; unknown users are refused instead of falling back to$HOMEor/.ScopedFsUser. Before auth the helper drops root's supplementary groups; if that fails it exits 1 (PAM_AUTH_ERR, fail closed).saveFailedFacewrites debug images underScopedFsUser.fs_usertest plants symlinks and checks writes are denied. Needs root: ctest skips it as non-root; CI runs it withsudo.Verification
Manual testing:
.deb/.rpm/AUR/source)Not tested: real PAM login/sudo in a VM.
Review report
AI review: 0 important, 1 nit, 2 pre-existing. Nit (comment placement) fixed. Security review ran: no hole found in the fix (kernel cap drop, per-thread creds, spdlog fd lifetime,
setgroupsfail-closed checked). Pre-existing follow-ups (root still opens user config/faces/db/model files for reading; earlyreadConfigwarnings go to stdout) are handled in a later PR of this stack.Risk
What could break, and for whom: users of the PAM helper. A failing
setgroupsnow fails auth closed. Upgrade note: adebugs/dir left root-owned by very old releases makes debug image saving stop (debug feature only; login unaffected).How to revert
git revertis enough (reintroduces the bug).Checklist