Skip to content

fix(receiver): never follow a symlinked alt-dest basis entry - #7419

Merged
oferchen merged 1 commit into
masterfrom
fix/alt-dest-confined
Aug 21, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/alt-dest-confined

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Problem

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. A sender that names an entry
whose counterpart in the operator's basis directory is a symlink gets that
symlink followed: under --compare-dest the file is silently treated as
up to date, and under --copy-dest the target's contents are copied into the
destination. The basis directory becomes a read oracle.

Why upstream cannot reach that state

basis_link_stat() (generator.c:962) 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 the flag before forking the generator:

/* The receiving side mustn't obey this, or an existing symlink that
 * points to an identical file won't be replaced by the referent. */
copy_links = copy_dirlinks = copy_unsafe_links = 0;   /* main.c:1009-1011 */

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:

basis entry flags dest after
symlink -> ../outside/target -a --copy-links --compare-dest transferred
regular file (control) -a --copy-links --compare-dest skipped

oc-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_match always symlink_metadata the
basis entry. The copy_links parameter is removed rather than passed as
false: it is unrepresentable on this path by construction, so deleting it
stops the flag being re-threaded from config.flags.

Sites deliberately unchanged

The other four copy_links consumers in crates/transfer are all sending-side,
where upstream does honour -L:

site upstream analogue
generator/open_source.rs:94 sender.c do_open_checklinks
generator/file_list/walk.rs:455,586 flist.c send_file_name
generator/file_list/mod.rs:358,524 flist.c:1985/2256 send_implied_dirs
generator/transfer/transfer_loop.rs:1331 sender.c:150

The local-copy alt-dest implementation in crates/engine already behaved
correctly - measured on the same fixture before this change.

Tests

copy_dest_follows_symlink_basis_entry_with_copy_links asserted the opposite
and is removed: its rationale ("link_stat() dispatches to x_stat()") is true
of link_stat in general but false on the receiver path. The three skip pins
are renamed accordingly, and copy_dest_matches_regular_basis_entry remains as
the non-vacuity companion.

RED proven by restoring the follow - 4 tests run: 1 passed, 3 failed: all
three skip pins fail, the regular-basis companion stays green.

Verification

  • cargo fmt --all -- --check clean
  • cargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warnings clean
  • cargo nextest run -p transfer --all-features - 2760 run, 2760 passed

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.
@github-actions github-actions Bot added the bug Something isn't working label Aug 21, 2026
@oferchen
oferchen merged commit 80d5461 into master Aug 21, 2026
70 checks passed
@oferchen
oferchen deleted the fix/alt-dest-confined branch August 21, 2026 08:33
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.
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