Repository navigation
fix(daemon): pin the module root before the privilege drop - #7605
Merged
Merged
Conversation
oferchen
force-pushed
the
fix/daemon-module-dirfd-pin
branch
from
September 1, 2026 11:26
3a58339 to
1a17576
Compare
A daemon module whose path sits under a directory the served uid cannot
search (`path = /home/backup/data` under a 0700 home) could not be
served: the sender re-walked the ABSOLUTE module path after `setuid`, so
every lookup re-traversed the unsearchable ancestor and failed with
`link_stat "." (in m) failed: Permission denied`.
Upstream avoids this by ordering, not by permissions. clientserver.c:
1059-1065 enters the module with `change_dir(module_chdir, CD_NORMAL)`
and then pins it - `module_dirfd = open(".", O_RDONLY | O_DIRECTORY |
O_CLOEXEC)` - both ABOVE the setgid/setuid at :1093. Its three consumers
resolve against that descriptor: flist.c:2035-2059 (the scan),
sender.c:293-295 (the content open), and syscall.c:85-90, which
`dup(module_dirfd)`s instead of re-resolving the absolute root.
oc has neither half. It now takes the same pin in the same position and
gives all three consumers the same anchor:
- `fast_io::confinement` gains `SESSION_ROOT_FD` beside `SESSION_ROOT` -
the same root, as a descriptor. `install_session` drops it whenever it
replaces the path, so a pin that is present is always this session's.
- The pin is taken through the OWNERSHIP WALK, not a plain open, because
upstream's `.` is the directory `change_dir()` entered and a
non-chrooted daemon enters it with `open_no_attacker_symlinks()`
(util1.c:1254-1263). A plain open would let a foreign-uid symlink
planted at the configured `path =` redirect the pin, turning an
ancestor-traversal fix into a module-root escape.
- `fast_io::pinned_root` issues the sender's `lstat`/`stat`/`opendir`
against the pin when the path lies beneath it, and is the ordinary
`std::fs` call otherwise. The stat arm needs `O_PATH` and so is
Linux-only; the scan anchors on every Unix.
- `open_trusted_dir` duplicates the pin when asked for the pinned root,
mirroring `open_anchor_dirfd()`. That covers `SourceOpen::open` and
`read_source_link`, both of which re-opened the root by absolute path
on every call, plus the `openat2` fast path in `open_source_confined`.
Same cause, second symptom, security-relevant: the Landlock rule-path
open ran post-drop too, so `restrict_to_module_paths` failed with EACCES
and the caller only WARNED - the module was then served with no kernel
sandbox at all, on exactly the layout the sandbox was added for. The
rule path is now opened through the pin as well.
Measured on Linux 7.0 aarch64, upstream testsuite 3.5.0 root/pipe:
`daemon-module-private-parent` fails on master and passes here, so its
expect-manifest row flips in this commit. Removing only the
`pin_session_root_fd` call restores both symptoms - the `link_stat`
EACCES and `landlock setup failed` - and `daemon-module-chdir-symlink`
pins the ownership-walk half. The TCP row stays `fail`: there the cell's
second connection hits a separate defect (the threaded daemon's `setuid`
is process-wide and persists across connections, where upstream forks).
Two new cells build the barrier with `chmod 0` rather than a uid drop,
so they run without root: one asserts every anchored lookup survives it
and reverts to EACCES with the pin dropped, the other asserts the
Landlock ruleset still installs. Both carry a traversable-parent
companion so a change that broke the ordinary deployment cannot hide.
oferchen
force-pushed
the
fix/daemon-module-dirfd-pin
branch
from
September 1, 2026 12:33
1a17576 to
abf7133
Compare
The parenthetical "without granting - or requiring - any access" wrapped so that "- or requiring" began a line, which markdown parses as a list item and turns the four following lines into lazy continuations. doc_lazy_continuation is deny-level under -D warnings, so the whole crate failed to compile in the lint job. Reflowed so the hyphen stays mid-line. Prose is unchanged.
oferchen
added a commit
that referenced
this pull request
Sep 1, 2026
…ng them `resolve_upstream_path` returns `ForeignUpstream` for any cited path carrying a `/` that is not a manifest key, on the rule that a directory rsync does not ship names a different project. A citation written as `target/interop/upstream-src/rsync-3.5.0/delete.c:191` matches that rule, so the gate skips it - and the skip `continue`s above `tally.names_checked`, so it leaves no trace in a report whose stated job is telling "clean" apart from "examined nothing". Measured on master at 92e50ab: 8718 names and 8718 ranges checked, and 379 citations skipped. 113 of those 379 name the PINNED release - 34 spelling the full unpack prefix, 79 spelling the bare `rsync-3.5.0/` directory - so their line numbers have never been checked by anything. That set includes the citations #7601, #7603 and #7605 have just rewritten: the retarget sweep landed its new line numbers into the one shape the gate does not read. Three changes: - A leading `[target/interop/upstream-src/]rsync-<VER>/` is split off before resolution, so a prefixed citation of the pinned release resolves to a manifest key and is range-checked exactly as the bare form is. A `rsync-` directory that is not a version number is not stripped. - A citation naming any other release becomes `Violation::UnpinnedRelease`, a hard failure. It names rsync at a version this tree no longer builds against, which is a stale citation, not an out-of-scope one. - Under a pinned prefix, a tail that resolves nowhere is `Missing` rather than `ForeignUpstream`: the prefix asserts the release outright, so it cannot be another project. - The skip is counted before the `continue`, and `execute` prints the skipped and permitted totals, so a population that grows again grows in the open. After: 8831 names and 8831 ranges checked, 10 skipped - all of them zsync's genuinely foreign `librcksum/`. Two exemptions from the unpinned-release arm, both scoped, neither covering the phantom-file or out-of-range arms. `CONTRIBUTING.md` and `xtask/src/commands/citations.rs` document this gate and have to be able to spell a rejected citation to show what it rejects. `docs/` mixes live reference with historical record, and a note describing upstream at 3.4.1 is accurate because it names the old release; 253 citations across 70 files there name a non-pinned release, and sorting record from reference needs a reader per file. Non-vacuity, both arms, end to end. A probe file citing `rsync-3.4.1/flist.c:999999`, `rsync-3.5.0/flist.c:999999` and the bare `rsync-3.5.0/` spelling of the same - a line no rsync release has - was added to the tree. Against master's gate: exit 0, tally `8718 name(s) and 8718 line range(s)`, byte for byte the tally without the probe, so the probe was invisible rather than tolerated. Against this gate: exit 1, the 3.4.1 line reported as unpinned and both 3.5.0 spellings reported as out of range, and those three are the only violations in the tree. The probe was removed before commit. Also sweeps nine citations of `checksum.c:285`, which claims the `schar *buf` cast. At the pin that cast is line 307; 285 is now `case CSUM_SHA256:` inside a digest switch. #7601 corrected three instances of this string and left nine, which is the failure mode the gate's own docs name: a finder only surfaces what its heuristic matched, so working a finding list is not a sweep. All nine are in range and were green under both gates.
`Windows (nightly)` failed to compile the daemon lib with
error[E0425]: cannot find function `pin_session_root_fd`
in module `fast_io::confinement`
`fast_io::confinement` splits its surface deliberately: the held-dirfd
family (`pin_session_root_fd`, `clear_session_root_fd`,
`pinned_root_fd_for`, `session_root_is_pinned`, `pinned_root_relative`)
is `#[cfg(unix)]`, while the policy functions (`install_session`,
`outside_session_root`, `session_confinement_root`, ...) are
cross-platform. This branch added a call to the unix-only half from
unconditional daemon code.
The call site is gated to match, so the policy half above it still runs
everywhere. A Windows arm returning `Ok(())` was deliberately NOT added:
there is no dirfd to hold and no setgid/setuid drop to precede, so it
would report a pin that never happened - the opposite of what the
adjacent warning exists to tell the operator - and it would answer the
open question of what path confinement means on Windows as a side
effect of a build fix.
Verified by cross-compiling the failing target on macOS: `cargo check
-p daemon --target x86_64-pc-windows-gnu` succeeds with the gate and
reproduces E0425 verbatim without it. `cargo check -p daemon` on unix
is unaffected.
oferchen
added a commit
that referenced
this pull request
Sep 2, 2026
…ng them (#7607) `resolve_upstream_path` returns `ForeignUpstream` for any cited path carrying a `/` that is not a manifest key, on the rule that a directory rsync does not ship names a different project. A citation written as `target/interop/upstream-src/rsync-3.5.0/delete.c:191` matches that rule, so the gate skips it - and the skip `continue`s above `tally.names_checked`, so it leaves no trace in a report whose stated job is telling "clean" apart from "examined nothing". Measured on master at 92e50ab: 8718 names and 8718 ranges checked, and 379 citations skipped. 113 of those 379 name the PINNED release - 34 spelling the full unpack prefix, 79 spelling the bare `rsync-3.5.0/` directory - so their line numbers have never been checked by anything. That set includes the citations #7601, #7603 and #7605 have just rewritten: the retarget sweep landed its new line numbers into the one shape the gate does not read. Three changes: - A leading `[target/interop/upstream-src/]rsync-<VER>/` is split off before resolution, so a prefixed citation of the pinned release resolves to a manifest key and is range-checked exactly as the bare form is. A `rsync-` directory that is not a version number is not stripped. - A citation naming any other release becomes `Violation::UnpinnedRelease`, a hard failure. It names rsync at a version this tree no longer builds against, which is a stale citation, not an out-of-scope one. - Under a pinned prefix, a tail that resolves nowhere is `Missing` rather than `ForeignUpstream`: the prefix asserts the release outright, so it cannot be another project. - The skip is counted before the `continue`, and `execute` prints the skipped and permitted totals, so a population that grows again grows in the open. After: 8831 names and 8831 ranges checked, 10 skipped - all of them zsync's genuinely foreign `librcksum/`. Two exemptions from the unpinned-release arm, both scoped, neither covering the phantom-file or out-of-range arms. `CONTRIBUTING.md` and `xtask/src/commands/citations.rs` document this gate and have to be able to spell a rejected citation to show what it rejects. `docs/` mixes live reference with historical record, and a note describing upstream at 3.4.1 is accurate because it names the old release; 253 citations across 70 files there name a non-pinned release, and sorting record from reference needs a reader per file. Non-vacuity, both arms, end to end. A probe file citing `rsync-3.4.1/flist.c:999999`, `rsync-3.5.0/flist.c:999999` and the bare `rsync-3.5.0/` spelling of the same - a line no rsync release has - was added to the tree. Against master's gate: exit 0, tally `8718 name(s) and 8718 line range(s)`, byte for byte the tally without the probe, so the probe was invisible rather than tolerated. Against this gate: exit 1, the 3.4.1 line reported as unpinned and both 3.5.0 spellings reported as out of range, and those three are the only violations in the tree. The probe was removed before commit. Also sweeps nine citations of `checksum.c:285`, which claims the `schar *buf` cast. At the pin that cast is line 307; 285 is now `case CSUM_SHA256:` inside a digest switch. #7601 corrected three instances of this string and left nine, which is the failure mode the gate's own docs name: a finder only surfaces what its heuristic matched, so working a finding list is not a sweep. All nine are in range and were green under both gates.
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.
The gap
A daemon module whose path sits under a directory the served uid cannot search -
path = /home/backup/dataunder a 0700 home - could not be served at all. The sender re-walked the absolute module path aftersetuid, so every lookup re-traversed the unsearchable ancestor:Upstream 3.5.0 serves the same module fine. It avoids this by ordering, not by permissions.
The upstream shape being mirrored
clientserver.c:1059-1065enters the module withchange_dir(module_chdir, CD_NORMAL)and then pins it,both above the
setgid/setuidat:1093. Three consumers resolve against that descriptor:flist.c:2035-2059(the directory scan),sender.c:293-295(the content open), andsyscall.c:85-90open_anchor_dirfd(), whichdup(module_dirfd)s rather than re-resolving the absolute root.oc had neither half -
server_config.rs:289recorded the reason ("oc has no chdir, so it keeps the absolute form").What changed
fast_io::confinementgainsSESSION_ROOT_FDbeside the existingSESSION_ROOT: the same root, as a descriptor.install_sessiondrops it whenever it replaces the path, so a pin that is present is always this session's. It stores the root's literal spelling as well as the physical one, because the sender's absolute paths are built from the former and the two differ wherever an ancestor is a symlink..is the directorychange_dir()entered, and a non-chrooted daemon enters it withopen_no_attacker_symlinks()(util1.c:1254-1263). A plain open would let a foreign-uid symlink planted at the configuredpath =redirect the pin - measured: it turnsdaemon-module-chdir-symlinkred, an ancestor-traversal fix becoming a module-root escape.fast_io::pinned_root(new) issues the sender'slstat/stat/opendiragainst the pin when the path lies beneath it, and is the ordinarystd::fscall otherwise. A..remainder declines to anchor. The stat arm needsO_PATHand is therefore Linux-only; the scan anchors on every Unix.open_trusted_dirduplicates the pin when asked for the pinned root -open_anchor_dirfd()exactly. That is what fixesSourceOpen::openandread_source_link, which reconstructed a module-relative path but then re-opened the root by absolute path on every call, plus theopenat2fast path inopen_source_confined.The three consumers, as fixed
lstat/stat(walk.rs:593)flist.c:1362link_stat()on.afterchange_dirpinned_root::{symlink_metadata,metadata}read_dir+ per-child statflist.c:2028-2059secure_opendir()pinned_root::read_dir,batch_stat_dir_entriesSourceOpen::open,read_source_linksender.c:293-295,syscall.c:87-88open_trusted_dirdups the pinSecond symptom, same cause, security-relevant
The Landlock rule-path open ran post-drop too, so
restrict_to_module_pathsfailed withEACCESbefore adding a single rule. The caller only warns and serves the connection anyway, so the module was served with no kernel sandbox at all - the hardening disappeared on exactly the layout it was added for. The rule path is now opened through the pin.Measured on the same fixture:
Evidence
Linux 7.0 aarch64, upstream testsuite 3.5.0, root/pipe leg.
testsuite/daemon-module-private-parent_test.pypasses against a real 3.5.0 build.master(its manifest row saidfail).tools/ci/upstream-3.5.0-expect.root.txtflips topassin this commit. The only remaining mismatches on this host,batch-file-symlinkandsimd-checksum, reproduce identically on an unmodifiedmasterbuild.pin_session_root_fdcall and rebuilding restores both symptoms: thelink_statEACCES andlandlock setup failed.daemon-module-chdir-symlinkis red with a plain-open pin and green with the walk.The TCP manifest row stays
fail. There the cell opens a second connection, and oc's threaded daemon has already applied a process-widesetuidwhere upstream forks per connection, so the second connection reports@ERROR: module 'm' path does not exist. That is a separate defect and is not touched here.Tests
Two new cells build the barrier with
chmod 0on the parent rather than a uid drop, so they need no root (and skip as root, where no barrier can exist):pinned_module_root_under_unsearchable_parent- asserts the barrier is real first, then that every anchored lookup crosses it, and that each reverts toEACCESwith the pin dropped. Includes a traversable-parent companion and an operator-owned-symlink module root, so a change that broke the ordinary deployment or hardened the pin into a blanketO_NOFOLLOWcannot hide.landlock_rule_under_unsearchable_parent- asserts the ruleset installs (Enforced), which is a distinct claim from "the transfer succeeded": the transfer succeeds either way. Carries the same mutation (Error/EACCESwithout the pin) and the same traversable-parent companion.