Skip to content

fix(receiver): confine a daemon's absolute alt-dest basis to the module root - #7725

Merged
oferchen merged 2 commits into
masterfrom
fix/daemon-basis-module-confined
Sep 7, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/daemon-basis-module-confined

Conversation

@oferchen

@oferchen oferchen commented Sep 7, 2026

Copy link
Copy Markdown
Owner

The defect

Upstream rsync-3.5.0/generator.c basis_link_stat() has four arms; oc modelled two.

upstream condition resolver
arm 1 generator.c:979 !am_daemon && am_root >= 0 && !symlink_optout_allowed() ownership walk
arm 2 generator.c:1004 am_daemon && !am_chrooted && path[0] == '/' && !symlink_optout_allowed() ownership walk with operator_path_resolve = 1
arm 3 generator.c:1046 am_daemon && am_chrooted && module_dirlen && path[0] != '/' secure_relative_open()
arm 4 generator.c:1064 — plain link_stat()

BasisTrust was a two-valued enum keyed on one bool, so every daemon receiver fell straight to arm 4.

Arm 2 is not decoration. The ownership rule answers who planted this symlink; it does not answer where following it lands. A module tree belongs to the daemon uid, so an in-module symlink pointing outside the module is trusted-OWNED and the plain walk follows it. Only the module-root judgement on the resolved leaf refuses it — and that is exactly what upstream's operator_path_resolve = 1 does.

Upstream's own comment at generator.c:991-1003 names the daemon-symlink-escape-matrix cell and explains the path[0] == '/' term.

The read oracle it closes

The daemon roots a peer's --compare-dest=/evil under the module (clamp_basis_to_module, mirroring upstream sanitize_path), so the basis path is <module>/evil/tgtfile. The escaping component evil is therefore a parent, and fs::symlink_metadata declines to follow a symlink at the leaf only — the kernel resolves every parent component, and the stat lands outside the module.

All four of arm 2's conditions hold in that cell: daemon, use chroot: no, absolute basis, insecure links = no.

The change

  • BasisTrust now carries the two session facts upstream branches on (am_daemon, am_chrooted). BasisTrust::arm_for(path) applies the per-path path[0] == '/' term and yields a BasisArm. One predicate owns the whole decision; the call site is a single BasisTrust::for_connection(&connection) and states no policy of its own.
  • fast_io::operator_symlink_metadata_confined is arm 2's resolver: the same walk with PathKind::Confined, so the resolved leaf is judged against the session root. Both spellings share one body.
  • fast_io::confinement publishes am_chrooted alongside the opt-out it already published. A chroot() changes the process root, so it belongs in process state; a module's insecure links directive does not, and stays on the connection where it already lives.
  • am_daemon is read as served_module_root().is_some(), not is_daemon_connection. The latter is set on both ends of an rsync:// transfer, so it was applying a daemon's confinement to an rsync:// client's own local destination — a shape upstream leaves on arm 1. ConnectionConfig::served_module_root()'s own doc already designates it as oc's am_daemon spelling; this call site was not reading it.

Deliberately not restated: the symlink opt-out

Upstream tests !symlink_optout_allowed() at each arm, but it reads the same global the walk reads: ona_open() short-circuits to a legacy symlink-following open before any root is consulted (syscall.c:300-302). fast_io::owner_walk mirrors that short-circuit, so under an opt-out every walking arm already degenerates to the resolution arm 4 performs. Restating the test at the predicate would be a second copy of one policy.

The regression this must not re-open

A RELATIVE basis (--link-dest=../01) keeps the plain stat on both implementations. Its ../ is already clamped to the module root by sanitize_path, and confining it would break link-dest-relative-basis (#915/#930), whose manifest row passes on both pipe legs. That is pinned by a_non_chrooted_daemon_keeps_the_plain_stat_for_a_relative_basis, and mutation M3 below confirms the pin bites.

Non-vacuity

The discriminating fixture is one module tree with escape -> ../outside, a symlink the test itself owns, so the ownership rule trusts it:

  • a_daemon_refuses_a_basis_whose_parent_escapes_the_module — arm 2 refuses; nothing is written to the destination.
  • the_non_daemon_arm_still_follows_the_same_self_owned_link — on the same fixture, arm 1 follows it. The refusal comes from the module-root judgement and from nothing else.
  • a_daemon_still_consumes_a_basis_inside_the_module — the confined arm is not "refuse everything".
  • a_chrooted_daemon_keeps_the_fall_through_on_the_same_fixture — am_chrooted is a real input.

All assert on the observed outcome (basis consumed or not, bytes present or not), never on a message string.

Mutation kill list

Nine mutants, each run against cargo nextest run -p fast_io -p transfer --lib --no-fail-fast at the 1.88.0 pin. Every summary satisfies passed + failed == run (3489), so no list is truncated.

# mutation killed by
M1 arm 2 never selected (reverts the fix) a_non_chrooted_daemon_confines_an_absolute_basis_to_the_module; a_daemon_refuses_a_basis_whose_parent_escapes_the_module
M2 arm 2 selected, resolved by the UNCONFINED walk a_daemon_refuses_a_basis_whose_parent_escapes_the_module
M3 drop the path[0] == '/' term (confine a relative basis) a_non_chrooted_daemon_keeps_the_plain_stat_for_a_relative_basis
M4 am_chrooted ignored a_chrooted_daemon_falls_through_to_the_plain_stat; the_serving_daemon_takes_the_daemon_arm; a_chrooted_daemon_keeps_the_fall_through_on_the_same_fixture
M5 am_daemon ignored a_non_daemon_receiver_walks_the_basis_parent; an_rsync_client_is_not_a_daemon_receiver; the_non_daemon_arm_still_follows_the_same_self_owned_link
M6 the confined stat aliases the ancillary one owner_walk::tests::the_confined_stat_refuses_a_parent_that_leaves_the_module; a_daemon_refuses_a_basis_whose_parent_escapes_the_module
M7 the session never publishes am_chrooted confinement::tests::install_session_publishes_the_chroot_state; the_serving_daemon_takes_the_daemon_arm
M8 read is_daemon_connection as am_daemon an_rsync_client_is_not_a_daemon_receiver
M9 for_connection ignores the session chroot state the_serving_daemon_takes_the_daemon_arm

M8 initially survived: the derivation lived at the call site inside the receiver loop, which no test reaches. Folding it into BasisTrust::for_connection made it unit-reachable — a design change the mutation testing drove, not a test written to fit the code.

Verification (pinned toolchain 1.88.0)

  • tools/ci/check_rustfmt_all.py — clean, 3422 files at edition 2024.
  • cargo clippy -p transfer -p fast_io --all-targets -- -D warnings — clean.
  • cargo nextest run -p fast_io -p transfer --no-fail-fast — 4020 passed, 0 failed, 4 skipped.

Scope: what this does NOT claim

This closes the compare-dest vector of daemon-symlink-escape-matrix. The cell's other four vectors (read / write / read-plain / write-plain) are unmeasured — the cell needs a root + TCP leg, which was not run here, and only an executed root-TCP run enumerates the residual set. No tools/ci/upstream-3.5.0-expect.* manifest row was touched.

Two gaps are named rather than papered over:

  • upstream arm 3 (generator.c:1046) — a chrooted daemon with a /./ inner module boundary resolving a RELATIVE basis through secure_relative_open() — has no oc counterpart. oc takes arm 4 there, as BasisArm::PlainStat documents.
  • try_dests_non (generator.c:1226/:1253) reaches basis_link_stat() upstream, but oc's try_reference_dest_non uses a plain symlink_metadata. That is the same defect class for non-regular basis entries, and it is untouched here because the cell's transferred file is regular and a change there would ship unexercised by the failing cell.

…le root

Upstream's `basis_link_stat()` has four arms. oc modelled two of them, and
the missing one is the arm that exists for a daemon:

  generator.c:979  arm 1  !am_daemon                -> ownership walk
  generator.c:1004 arm 2  am_daemon && !am_chrooted
                          && path[0] == '/'         -> ownership walk with
                                                       operator_path_resolve = 1
  generator.c:1046 arm 3  am_daemon && am_chrooted
                          && relative               -> secure_relative_open
  generator.c:1064 arm 4                            -> plain link_stat

`BasisTrust` was a two-valued enum keyed on one bool, so every daemon
receiver fell straight to arm 4. The ownership rule alone cannot stand in
for arm 2: a module tree belongs to the daemon uid, so an in-module symlink
whose target lands outside the module is trusted-OWNED and is followed.
Only the module-root judgement on the resolved leaf refuses it.

That is a read oracle. The daemon roots a peer's `--compare-dest=/evil`
under the module (`clamp_basis_to_module`, upstream `sanitize_path`), so
the basis path is `<module>/evil/tgtfile` and the escaping component is a
PARENT. `fs::symlink_metadata` declines to follow a symlink at the LEAF
only; the kernel resolves every parent, and the stat lands outside.

Changes:

- `BasisTrust` becomes the two session facts upstream branches on
  (`am_daemon`, `am_chrooted`); `BasisTrust::arm_for` applies the per-path
  `path[0] == '/'` term and yields a `BasisArm`. A RELATIVE basis keeps the
  plain stat on both implementations - upstream's own comment at
  generator.c:997-1001 spells out why, and confining it would re-open the
  `link-dest-relative-basis` regression (#915/#930).
- `fast_io::operator_symlink_metadata_confined` is the arm-2 resolver:
  the same walk, with `PathKind::Confined` so the resolved leaf is judged
  against the session root. Both spellings share one body.
- `fast_io::confinement` publishes `am_chrooted` alongside the opt-out it
  already published. A chroot changes the process root, so it belongs in
  process state; a module's `insecure links` directive does not, and stays
  on the connection.
- The predicate reads `am_daemon` as `served_module_root().is_some()`, not
  `is_daemon_connection`. The latter is set on BOTH ends of an `rsync://`
  transfer, so it was applying a daemon's confinement to an `rsync://`
  CLIENT's own local destination, which upstream leaves on arm 1.

The symlink opt-out is deliberately not restated at the predicate. Upstream
tests it per arm but reads the same global the walk reads, and `ona_open()`
short-circuits to a legacy symlink-following open before any root is
consulted (syscall.c:300-302); `fast_io::owner_walk` mirrors that, so under
an opt-out every walking arm already degenerates to arm 4's resolution.

Still absent, and named rather than papered over: upstream's arm 3, and
`try_dests_non` (generator.c:1226/1253) which reaches `basis_link_stat`
upstream but a plain `symlink_metadata` here.
@github-actions github-actions Bot added the bug Something isn't working label Sep 7, 2026
… consumer

`BasisArm` and `BasisTrust::arm_for` were declared unconditionally while
their sole production consumer is the `cfg(unix)` `basis_stat`, so on Windows
both are dead and `-D warnings` makes that fatal. Two of the three arms name
the ownership walk, which the `cfg(not(unix))` `basis_stat` already documents
as having no Windows analogue - it takes the plain stat for every
`BasisTrust` and never asks which arm applies. Selecting an arm is therefore
not a question that can be posed off Unix, so the gate states a platform
truth rather than silencing a lint.

`BasisTrust` itself stays ungated: both `basis_stat` arms take it, which is
why only the other two were reported. The test module follows `arm_for`'s
gate because every case asserts an `arm_for` answer.
@oferchen
oferchen merged commit 26a502a into master Sep 7, 2026
77 checks passed
@oferchen
oferchen deleted the fix/daemon-basis-module-confined branch September 7, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant