Skip to content

fix(sender): follow a symlinked dir named with the DOTDIR marker - #7510

Merged
oferchen merged 2 commits into
masterfrom
fix/dotdir-symlink-operand
Aug 26, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/dotdir-symlink-operand

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Silent data loss on an ordinary invocation

oc-rsync -a host:current/ dest/, where current is a symlink to a directory, delivered nothing and exited 0. Upstream delivers the contents. current -> releases/2026-08-25 is 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 sets name_type = DOTDIR_NAME for an operand ending in / (flist.c:2589-2594) or /. (:2604), and flist.c:2697 passes:

link_stat(fbuf, &st, copy_dirlinks || name_type != NORMAL_NAME)

So the marker does two things: selects "contents of", and resolves the operand before the walk decides what it is. --copy-dirlinks is not required.

oc had only the first disjunct.

Two spellings, two different failures

  • alias/ — resolve_symlink_metadata stripped the trailing separator (correctly, so the stat is platform-independent) then discarded that it had been there, leaving the follow gated on --copy-dirlinks alone. lstat'd as a symlink, walk never descended → empty.
  • alias/. — non_relative_walk_base recognised only a trailing /, so /. fell through to Path::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_marker predicate instead of re-deriving the rule independently — which is exactly what let the two spellings drift apart.

Measured against real rsync 3.5.0

operand oc before oc after upstream 3.5.0
sub/ (real dir, control) deep deep/f2 deep deep/f2 deep deep/f2
alias/ empty deep deep/f2 deep deep/f2
alias/. alias alias/deep alias/deep/f2 deep deep/f2 deep deep/f2
alias (no marker) alias alias alias
alias/ --copy-dirlinks deep deep/f2 deep deep/f2 deep deep/f2

5/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:

  • reverting the follow gate to copy_dirlinks alone → the two DOTDIR cells fail, both controls stay green;
  • reverting the base split to trailing-/-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 -a on an ordinary symlink.

cargo fmt --all -- --check clean; clippy -p transfer --all-targets --all-features clean; -p transfer 2733/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.

`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.
@github-actions github-actions Bot added the bug Something isn't working label Aug 25, 2026
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.
@oferchen
oferchen merged commit 0cc1517 into master Aug 26, 2026
69 checks passed
@oferchen
oferchen deleted the fix/dotdir-symlink-operand branch August 26, 2026 00:09
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