Repository navigation
fix(sender): follow a symlinked dir named with the DOTDIR marker - #7510
Merged
Merged
Conversation
`oc-rsync -a host:current/ dest/` where `current` is a symlink to a directory DELIVERED NOTHING and exited 0. `current -> releases/<date>` is an ordinary layout, so this is silent data loss on a plain invocation - no rrsync, no procfs, no restricted shell. upstream sets `name_type = DOTDIR_NAME` for an operand ending in `/` (flist.c:2589-2594) or `/.` (:2604), and flist.c:2697 passes `copy_dirlinks || name_type != NORMAL_NAME` as link_stat()'s follow_dirlinks argument. The marker therefore does two things: it selects "contents of", and it resolves the operand before the walk decides what it is. oc had only the first disjunct. `resolve_symlink_metadata` stripped the trailing separator - correctly, so the stat is platform-independent - and then discarded the fact that it had been there, leaving the follow gated on `--copy-dirlinks` alone. The operand was lstat'd as a symlink and the walk never descended. The `/.` spelling failed differently and worse: `non_relative_walk_base` only recognised a trailing `/`, so `/.` fell through to `Path::parent()`, which normalises the `.` away. That transmitted the symlink ITSELF plus everything under it. Through a restricted shell the link target is the wrapper's pinned `/proc/self/fd/N`, so the absolute host path is published to the client. Both sites now consult one `operand_has_dotdir_marker` predicate rather than re-deriving the rule independently, which is what let the two spellings drift apart in the first place. Measured against real rsync 3.5.0 over a remote shell, 5/5 cells match after the fix (2 were divergent before): `alias/` and `alias/.` now deliver the contents, `sub/` (real dir) and bare `alias` are unchanged, and `alias/ --copy-dirlinks` still works - the last being a positive control on the gate itself. The local-copy executor was measured CORRECT on all four operands both before and after, so the defect is confined to the network sender and the regression cells run over a real two-process transfer. A local fixture would pass without exercising the fix. Both halves are independently mutation-lethal: reverting the follow gate fails the two DOTDIR cells, reverting the base split fails only the `/.` cell, and the two controls stay green under both.
The DOTDIR follow added in this branch used a bare `std::fs::metadata`, which resolves with libc and consults nothing about who owns the link. That is safe for `--copy-dirlinks`, an explicit client request over a client-named tree, but not for the DOTDIR disjunct: `operand_has_dotdir_marker` returns true for a bare `.`, and `.` is the source operand of every daemon transfer (`--server -re.iLsfxCIvu . mod/`). So the follow became unconditional on the daemon path and a foreign-uid symlink planted at the module root redirected the file list outside the module. Caught by `daemon-module-chdir-symlink` in the 3.5.0 root testsuite, which went pass -> fail on both the pipe and TCP legs while every other open PR held that context green. Its log names the observable exactly: the module listing carried the canary from the escape target. Upstream does follow a DOTDIR operand (flist.c:2697 passes `copy_dirlinks || name_type != NORMAL_NAME`), so reverting the follow would restore the silent data loss this branch exists to fix. The difference is WHEN: the daemon resolves its module root through `change_dir()` / `open_no_attacker_symlinks()` (util1.c:1216) before the walk runs, so upstream's `link_stat()` never sees an unresolved operand. oc walks the path as given. The follow is therefore gated on upstream's own ownership rule (syscall.c:406): uid 0 or our euid is the operator's own layout and is followed, any other uid is a plant and is not. `--copy-dirlinks` keeps its existing meaning untouched - the asymmetry is deliberate and stated at the call site. The `current -> releases/2026-08-25` deploy case this branch fixes is operator-owned, so all four cells in tests/dotdir_symlink_operand.rs still pass. A unit test pins the rule; the behavioural proof that a foreign-owned link is refused is the testsuite cell itself, which needs root to create a non-self-owned symlink and so cannot run in-crate.
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.
Silent data loss on an ordinary invocation
oc-rsync -a host:current/ dest/, wherecurrentis a symlink to a directory, delivered nothing and exited 0. Upstream delivers the contents.current -> releases/2026-08-25is how most people lay out a deploy tree.No rrsync, no procfs, no restricted shell — plain SSH.
Upstream rule
--list-only-style option tables aren't involved; this is the file-list walk. Upstream setsname_type = DOTDIR_NAMEfor an operand ending in/(flist.c:2589-2594) or/.(:2604), andflist.c:2697passes:So the marker does two things: selects "contents of", and resolves the operand before the walk decides what it is.
--copy-dirlinksis not required.oc had only the first disjunct.
Two spellings, two different failures
alias/—resolve_symlink_metadatastripped the trailing separator (correctly, so the stat is platform-independent) then discarded that it had been there, leaving the follow gated on--copy-dirlinksalone. lstat'd as a symlink, walk never descended → empty.alias/.—non_relative_walk_baserecognised only a trailing/, so/.fell through toPath::parent(), which normalises.away. That transmitted the symlink itself plus everything under it. Through a restricted shell the link target is the wrapper's pinned/proc/self/fd/N, so the absolute host path is published to the client.Both sites now consult one
operand_has_dotdir_markerpredicate instead of re-deriving the rule independently — which is exactly what let the two spellings drift apart.Measured against real rsync 3.5.0
sub/(real dir, control)deep deep/f2deep deep/f2deep deep/f2alias/deep deep/f2deep deep/f2alias/.alias alias/deep alias/deep/f2deep deep/f2deep deep/f2alias(no marker)aliasaliasaliasalias/ --copy-dirlinksdeep deep/f2deep deep/f2deep deep/f25/5 match after; 2 were divergent before.
Scope
The local-copy executor was measured correct on all four operands, before and after. The defect is confined to the network sender's file-list walk, so the regression cells run over a real two-process remote-shell transfer — a local fixture would pass without exercising the fix at all.
Non-vacuity
Both halves are independently mutation-lethal:
copy_dirlinksalone → the two DOTDIR cells fail, both controls stay green;/-only → only the/.cell fails, three stay green.The
alias(no-marker) cell is the guard against the tempting over-fix: a change that simply always followed dirlinks would pass every other cell while breaking-aon an ordinary symlink.cargo fmt --all -- --checkclean;clippy -p transfer --all-targets --all-featuresclean;-p transfer2733/2733.Related
Task 861 (
rrsync-pull-arg-shapes) is one symptom of this and should be re-measured after this lands rather than fixed separately. The daemon transport is not measured here — the operand's file type is the variable and the transport is not, so transport-independence is expected but unproven.