Repository navigation
fix(receiver): never follow a symlinked alt-dest basis entry - #7419
Merged
Merged
Conversation
The alt-dest basis stat honoured --copy-links, so a symlink planted in a --compare-dest / --copy-dest / --link-dest directory was resolved and its target consumed as the basis. On a pull the entry name is peer-controlled, which turns an operator's basis directory into a read oracle: the peer names a path whose basis entry is a symlink, and --copy-dest copies the target's contents into the destination. Upstream cannot reach that state. basis_link_stat() does call link_stat_at(), which dispatches to stat when copy_links is set, but it only ever runs on the receiving side and do_recv() clears copy_links before forking the generator (main.c:1009-1011). The flag is therefore always false there, and a basis symlink simply makes the basis look absent so the file transfers normally. Measured against real rsync 3.5.0 with a matching symlink target: basis entry flags dest after symlink -> file -a --copy-links --compare-dest transferred regular file -a --copy-links --compare-dest skipped oc-rsync now matches both rows. The regular-file row is the non-vacuity control: it proves the fixture can produce a skip at all. Rather than pass copy_links=false, the parameter is removed from try_reference_dest / best_reference_match. It is unrepresentable on this path by construction, so deleting it prevents the flag being re-threaded. The four generator-side copy_links consumers are the sending side (sender.c / flist.c), where upstream does honour -L, and are unchanged. RED proven by restoring the follow: the three skip pins fail, the regular-basis companion stays green.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
The alt-dest basis stat honoured --copy-links, so a symlink planted in a --compare-dest / --copy-dest / --link-dest directory was resolved and its target consumed as the basis. On a pull the entry name is peer-controlled, which turns an operator's basis directory into a read oracle: the peer names a path whose basis entry is a symlink, and --copy-dest copies the target's contents into the destination. Upstream cannot reach that state. basis_link_stat() does call link_stat_at(), which dispatches to stat when copy_links is set, but it only ever runs on the receiving side and do_recv() clears copy_links before forking the generator (main.c:1009-1011). The flag is therefore always false there, and a basis symlink simply makes the basis look absent so the file transfers normally. Measured against real rsync 3.5.0 with a matching symlink target: basis entry flags dest after symlink -> file -a --copy-links --compare-dest transferred regular file -a --copy-links --compare-dest skipped oc-rsync now matches both rows. The regular-file row is the non-vacuity control: it proves the fixture can produce a skip at all. Rather than pass copy_links=false, the parameter is removed from try_reference_dest / best_reference_match. It is unrepresentable on this path by construction, so deleting it prevents the flag being re-threaded. The four generator-side copy_links consumers are the sending side (sender.c / flist.c), where upstream does honour -L, and are unchanged. RED proven by restoring the follow: the three skip pins fail, the regular-basis companion stays green.
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.
Problem
The alt-dest basis stat honoured
--copy-links, so a symlink planted in a--compare-dest/--copy-dest/--link-destdirectory was resolved and itstarget consumed as the basis.
On a pull the entry name is peer-controlled. A sender that names an entry
whose counterpart in the operator's basis directory is a symlink gets that
symlink followed: under
--compare-destthe file is silently treated asup to date, and under
--copy-destthe target's contents are copied into thedestination. The basis directory becomes a read oracle.
Why upstream cannot reach that state
basis_link_stat()(generator.c:962) does calllink_stat_at(), whichdispatches to
statwhencopy_linksis set. But it only ever runs on thereceiving side, and
do_recv()clears the flag before forking the generator:So on the receiver the basis stat is always an lstat, and a basis symlink makes
the basis look absent - the file transfers normally.
Measured against real rsync 3.5.0
Basis target is a regular file whose size and mtime match the source, so a
follow would match:
symlink -> ../outside/target-a --copy-links --compare-dest-a --copy-links --compare-destoc-rsync now matches both rows. The second row is the non-vacuity control -
without it the first row would also pass if the fixture simply could not
produce a skip.
Change
try_reference_dest/best_reference_matchalwayssymlink_metadatathebasis entry. The
copy_linksparameter is removed rather than passed asfalse: it is unrepresentable on this path by construction, so deleting itstops the flag being re-threaded from
config.flags.Sites deliberately unchanged
The other four
copy_linksconsumers incrates/transferare all sending-side,where upstream does honour
-L:generator/open_source.rs:94sender.cdo_open_checklinksgenerator/file_list/walk.rs:455,586flist.csend_file_namegenerator/file_list/mod.rs:358,524flist.c:1985/2256send_implied_dirsgenerator/transfer/transfer_loop.rs:1331sender.c:150The local-copy alt-dest implementation in
crates/enginealready behavedcorrectly - measured on the same fixture before this change.
Tests
copy_dest_follows_symlink_basis_entry_with_copy_linksasserted the oppositeand is removed: its rationale ("
link_stat()dispatches tox_stat()") is trueof
link_statin general but false on the receiver path. The three skip pinsare renamed accordingly, and
copy_dest_matches_regular_basis_entryremains asthe non-vacuity companion.
RED proven by restoring the follow -
4 tests run: 1 passed, 3 failed: allthree skip pins fail, the regular-basis companion stays green.
Verification
cargo fmt --all -- --checkcleancargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warningscleancargo nextest run -p transfer --all-features- 2760 run, 2760 passed