Repository navigation
fix(receiver): confine a daemon's absolute alt-dest basis to the module root - #7725
Merged
Merged
Conversation
…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.
… 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.
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 defect
Upstream
rsync-3.5.0/generator.cbasis_link_stat()has four arms; oc modelled two.generator.c:979!am_daemon && am_root >= 0 && !symlink_optout_allowed()generator.c:1004am_daemon && !am_chrooted && path[0] == '/' && !symlink_optout_allowed()operator_path_resolve = 1generator.c:1046am_daemon && am_chrooted && module_dirlen && path[0] != '/'secure_relative_open()generator.c:1064link_stat()BasisTrustwas 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 = 1does.Upstream's own comment at
generator.c:991-1003names thedaemon-symlink-escape-matrixcell and explains thepath[0] == '/'term.The read oracle it closes
The daemon roots a peer's
--compare-dest=/evilunder the module (clamp_basis_to_module, mirroring upstreamsanitize_path), so the basis path is<module>/evil/tgtfile. The escaping componentevilis therefore a parent, andfs::symlink_metadatadeclines 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
BasisTrustnow carries the two session facts upstream branches on (am_daemon,am_chrooted).BasisTrust::arm_for(path)applies the per-pathpath[0] == '/'term and yields aBasisArm. One predicate owns the whole decision; the call site is a singleBasisTrust::for_connection(&connection)and states no policy of its own.fast_io::operator_symlink_metadata_confinedis arm 2's resolver: the same walk withPathKind::Confined, so the resolved leaf is judged against the session root. Both spellings share one body.fast_io::confinementpublishesam_chrootedalongside the opt-out it already published. Achroot()changes the process root, so it belongs in process state; a module'sinsecure linksdirective does not, and stays on the connection where it already lives.am_daemonis read asserved_module_root().is_some(), notis_daemon_connection. The latter is set on both ends of anrsync://transfer, so it was applying a daemon's confinement to anrsync://client's own local destination — a shape upstream leaves on arm 1.ConnectionConfig::served_module_root()'s own doc already designates it as oc'sam_daemonspelling; 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_walkmirrors 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 bysanitize_path, and confining it would breaklink-dest-relative-basis(#915/#930), whose manifest row passes on both pipe legs. That is pinned bya_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_chrootedis 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-fastat the 1.88.0 pin. Every summary satisfiespassed + failed == run(3489), so no list is truncated.a_non_chrooted_daemon_confines_an_absolute_basis_to_the_module;a_daemon_refuses_a_basis_whose_parent_escapes_the_modulea_daemon_refuses_a_basis_whose_parent_escapes_the_modulepath[0] == '/'term (confine a relative basis)a_non_chrooted_daemon_keeps_the_plain_stat_for_a_relative_basisam_chrootedignoreda_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_fixtuream_daemonignoreda_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_linkowner_walk::tests::the_confined_stat_refuses_a_parent_that_leaves_the_module;a_daemon_refuses_a_basis_whose_parent_escapes_the_moduleam_chrootedconfinement::tests::install_session_publishes_the_chroot_state;the_serving_daemon_takes_the_daemon_armis_daemon_connectionasam_daemonan_rsync_client_is_not_a_daemon_receiverfor_connectionignores the session chroot statethe_serving_daemon_takes_the_daemon_armM8 initially survived: the derivation lived at the call site inside the receiver loop, which no test reaches. Folding it into
BasisTrust::for_connectionmade 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. Notools/ci/upstream-3.5.0-expect.*manifest row was touched.Two gaps are named rather than papered over:
generator.c:1046) — a chrooted daemon with a/./inner module boundary resolving a RELATIVE basis throughsecure_relative_open()— has no oc counterpart. oc takes arm 4 there, asBasisArm::PlainStatdocuments.try_dests_non(generator.c:1226/:1253) reachesbasis_link_stat()upstream, but oc'stry_reference_dest_nonuses a plainsymlink_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.