Skip to content

fix: walk a network receiver destination before mkdir - #8899

Merged
oferchen merged 3 commits into
masterfrom
fix/network-receiver-dest-walk
Nov 28, 2026
Merged

oferchen merged 3 commits into
masterfrom
fix/network-receiver-dest-walk

Conversation

@oferchen

@oferchen oferchen commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

A push or pull into a destination below a symlink owned by another user had
two problems. When the destination was new, the network receiver created it
with a plain path mkdir, which followed the symlink. When it existed, the
refusal carried an invented line, failed to access destination directory,
which rsync 3.5.2 never prints. This affects the --server receiver of a push
and the client receiver of a pull (issues #8870, #8863).

rsync 3.5.2 enters the destination in get_local_name() (main.c:714-873)
through change_dir(), whose non-daemon arm walks the path with
open_no_attacker_symlinks_dirfd() and fchdir()s to the result
(util1.c:1363-1392). This change makes both network receivers do the same:

  • change_dir#1 (main.c:777-781): an existing destination directory is
    entered through the ownership walk and the walked descriptor is pinned.
  • change_dir#2 (main.c:836-839): a directory the run creates is made from
    the walked parent and entered the same way.
  • change_dir#3 (main.c:865-868): the parent of a single-file destination is
    walked and pinned.
  • --mkpath (main.c:757-773) builds the missing leading directories per
    component through the walk; the result is then entered as change_dir#1
    (statret refreshed at :770).

A symlink the user or root owns is still followed. --insecure-links on the
receiving side keeps the plain follow; like 3.5.2, a client does not forward
it (options.c:3146-3149).

Design

  • I/O stays in fast_io. The walk uses fast_io's confined-path and
    pinned-root API: operator_open_destination (the ownership walk),
    operator_mkdir, operator_create_dir_all, make_path_beneath_cwd, then
    confinement::pin_destination_root. transfer does not open-code openat
    or O_NOFOLLOW steps.

  • One walk for both legs. ensure_dest_root(.., Entry) in
    receiver/dest_root.rs serves the push and the pull receiver through the
    same ReceiverContext setup; the only switch is destination_entry()
    (walked unless a daemon module or --insecure-links).

  • One message site in this crate. This branch adds no new copy of the
    change_dir#N text: it adds the ChangeDir2 arm to the existing
    SelectStep Display (receiver/dest_root.rs). The text is written today in
    three places across the workspace - transfer receiver/dest_root.rs
    (SelectStep), core client/error.rs and engine local_copy/error.rs
    (both from fix: enter a local copy's destination like change_dir does #8890). Folding them into one shared formatter is a separate follow-up.

  • The late re-open and the canonicalize() block are deleted. The walked
    descriptor is pinned instead. Evidence (below): symlink-dirlink-basis
    passes with this change, and passes with and without the pin; the pin is
    what keeps the two swap-after-entry cells and upstream
    rrsync-receiver-file-arg green.

  • Success-path cost: no extra syscalls. A clean push into an existing
    ordinary directory, strace on client and server, both binaries built with
    cargo build -p bin:

    Tree master openat / stat this branch openat / stat
    1 dir, 10 files 89 / 126 89 / 125
    10 dirs, 100 files 296 / 513 296 / 512

    The one stat fewer per run is the lstat that guarded the deleted
    canonicalize() block. The walk's search check on dest/. (chdir's
    implicit search-permission check, which an O_PATH open skips) replaces
    the dest/. stat master already made, so it adds nothing. readlink counts
    are equal (12 and 12). The difference is the same at both tree sizes.

Output and exit codes

Measured with rsync 3.5.2 and with this branch, same fixture, per leg:

# fixture: ROOT/flink -> ROOT/real (lchown nobody:nobody), ROOT/olink -> ROOT/own_real
# push: rsync -r -e ./lsh --rsync-path=rsync ROOT/src/ localhost:DEST
# pull: rsync -r -e ./lsh --rsync-path=rsync localhost:ROOT/src/ DEST
# lsh: #!/bin/sh / shift / exec sh -c "$*"
Case rsync 3.5.2 (push and pull) this branch
flink/new/ refusal line, [Receiver] change_dir#2 "ROOT/flink/new" failed: Too many levels of symbolic links (40), exit 3 same lines, exit 3
flink/ refusal line, change_dir#1 "ROOT/flink/", exit 3 same
flink/single (one file) refusal line, change_dir#3 "ROOT/flink", exit 3 same
--mkpath flink/a/b/ refusal line, change_dir#1 "ROOT/flink/a/b/", exit 3 same
olink/new/ (own link) exit 0 exit 0
--insecure-links flink/new/ push: refused, exit 3; pull: followed, exit 0 same

change_dir#1 keeps the operand's trailing slash, as 3.5.2 does: full_fname
prints dest_path as given (main.c:779). The trailer names oc's own
file(line), as for every oc trailer.

Deliberate deviation from rsync 3.5.2

Case rsync 3.5.2 oc
A directory the run creates below another user's symlink: the new destination directory, and the missing parents of an absolute --mkpath destination A plain mkdir follows the symlink and creates real/new (main.c:817) or real/a/b (make_path, main.c:757-773), then refuses at change_dir#2 (main.c:836-839) or change_dir#1 (main.c:777-781), exit 3 Walks the leading directories and refuses before any mkdir. Same refusal lines and exit 3; nothing is created.

This is the same deviation the local copy made in #8890. The mkdir that 3.5.2
performs first is the write through an untrusted symlink that the
CVE-2026-53796 fix exists to stop.

Not covered

  • Push line order. 3.5.2 prints the refusal line first:
    refusing to follow a symlink owned by an untrusted user; use --insecure-links locally or "insecure links = yes" in a daemon module ONLY if every path component is trusted
    rsync: [Receiver] change_dir#2 "ROOT/flink/new" failed: Too many levels of symbolic links (40)
    rsync error: errors selecting input/output files, dirs (code 3) at main.c(839) [Receiver=3.5.2]
    
    On a push, oc prints the change_dir#N line and the trailer first and the
    refusal line last. A pull matches. Tracked separately.
  • Pull sender line. On a pull, 3.5.2's sender adds
    rsync error: received SIGUSR1 (code 19) at main.c(1691) [sender=3.5.2]
    after the receiver's trailer; the oc sender prints nothing. Tracked separately.
  • The non-chrooted daemon receiver's module walk (util1.c:1351) is a separate follow-up.
  • The shared change_dir#N formatter is a separate follow-up.

Tests

tests/destination_root_owner_walk.rs:

  • New network_receivers_stop_at_upstreams_change_dir_step: push and pull,
    four stops (new dir change_dir#2, existing dir change_dir#1, single file
    change_dir#3, --mkpath change_dir#1). Each asserts exit 3, the refusal
    line, the exact [Receiver] change_dir#N "<path>" failed: line from the
    3.5.2 run above, no invented text, and that nothing was created below the
    symlink.
  • The existing refused cell's push arm expected the deleted invented text; it
    now expects the refusal line, which a --server receiver relays as
    MSG_ERROR (log.c:437-446).
  • The old skip() is now missing_privilege(), which panics: a host that
    cannot plant a symlink owned by another uid fails these cells instead of
    reporting a pass.

Privileged fixture. Planting the foreign-owned symlink needs root or
passwordless sudo -n. The file runs in these required jobs, both hosted
ubuntu-latest runners with passwordless sudo (their own setup steps run
sudo apt-get / sudo rm non-interactively):

Job Runs this file Privilege
nextest (stable) yes (--workspace) passwordless sudo
Linux musl (stable) yes (--workspace), no container: passwordless sudo
macOS no (tests six named crates only) -
Windows no (cfg(unix)) -

Mutations, each restored afterwards:

Mutation Result
create_root uses a plain std::fs::create_dir new-dir cell red: created below the symlink
change_dir#3 parent walk removed single-file cell red: exit 23 (mkstemp ELOOP) instead of 3
pin skipped (pin_operator_destination(.., None)) both swap-after-entry cells red (push, pull); upstream rrsync-receiver-file-arg red ("in-place transfer changed the outside fixture"); symlink-dirlink-basis still passes

Upstream testsuite (rsync 3.5.2 runtests.py, binary copied to a file named
rsync): master 289 passed, 87 skipped, 0 failed; this branch 289 passed, 87
skipped, 0 failed. symlink-dirlink-basis, rrsync-receiver-file-arg and
rrsync-userns-procfs pass on both. rrsync-userns-procfs fails on master
too when the binary is named oc-rsync ("cannot locate the rsync
executable", rrsync-userns-procfs_test.py:31-41); the copy named rsync
passes on master, so that failure is harness naming, not this change.

Verification

  • cargo fmt --all -- --check, tools/ci/check_rustfmt_all.py: clean
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings: clean
  • the same clippy for x86_64-pc-windows-gnu: clean
  • cargo nextest run -p bin --test destination_root_owner_walk (root): 9 passed
  • cargo nextest run -p transfer -E 'test(dest_root) | test(receiver::)': 937 passed
  • cargo nextest run -p core (scoped): 17 passed
  • no-placeholders, citations, citation drift ratchet, dead-code census,
    unsafe-owner deps, test-seam gates: OK
  • tools/ci/run_tools_tests.sh: OK. The gate run once reported
    FAILED (errors=1, skipped=2). Rerun with full logs: 5 of 5 sequential runs
    pass, and 3 of 6 runs made concurrently with a second copy fail with exactly
    that summary, from FreePortTest.test_bind_free_port_skips_a_port_taken_since_allocation
    (OSError: [Errno 98]). That is the concurrent-run port race fixed by test: point the free-port squatter test at a port it owns #8898,
    not this change.

Closes #8870
Part of #8863 (push line order and the daemon receiver are separate follow-ups)

A push or pull receiver created its destination with a path-based
mkdir and resolved it with canonicalize(), so a symlink another user
planted in the destination's parent chain was followed: the transfer
was refused only after the destination had been made below the link,
and with text rsync never prints.

rsync 3.5.2's get_local_name() enters the destination through
change_dir(), which walks each component with
open_no_attacker_symlinks_dirfd() and fchdir()s into the result
(util1.c:1363-1392), before make_path() or mkdir() run (main.c:757-868).
The receiver now does the same through fast_io's operator walk:

- the parent chain is walked before anything is created, and a new
  destination is made with operator_mkdir() beneath the walked parent;
- the walked descriptor is pinned as the destination root, which
  replaces the canonicalize() block;
- a refusal prints 3.5.2's line for the step that failed,
  `change_dir#1`, `#2` or `#3` with the cleaned full_fname, and exits 3;
- the invented refusal text is gone.

The privileged cells in destination_root_owner_walk.rs now fail
instead of returning early when root or passwordless sudo is missing,
and cover push and pull at each change_dir step.
@oferchen oferchen added this to the 0.6.5 milestone Nov 28, 2026
@github-actions github-actions Bot added the bug Something isn't working label Nov 28, 2026
rsync 3.5.2's make_path() tries mkdir on the deepest directory first
(util1.c:231-247). When that directory is an existing regular file the
mkdir fails with EEXIST, the stat confirms it is not a directory, and
main.c:818-821 prints "mkdir ... failed: File exists (17)". When the
file sits above it, the mkdir fails with ENOTDIR instead.

The network receivers' walk counted the missing chain with the dry-run
rule (util1.c:234-239), which reports ENOTDIR for every non-directory,
so a single-file --mkpath into dstfile/x printed "Not a directory (20)".
The count now leaves the deepest directory's mkdir to the walk that
makes the chain, and fast_io gains operator_make_path(), which accepts
EEXIST only for a directory (util1.c:244-246). make_path_beneath_cwd()
follows the same rule for the relative arm. operator_create_dir_all()
keeps accepting any existing entry, as copy_valid_path() does
(backup.c:128).

The walk-before-mkdir deviation is unchanged: nothing is created below
a foreign-owned symlink.
@oferchen
oferchen merged commit df6f15f into master Nov 28, 2026
89 of 90 checks passed
@oferchen
oferchen deleted the fix/network-receiver-dest-walk branch November 28, 2026 03:42
oferchen added a commit that referenced this pull request Nov 28, 2026
## Summary

The dead-code allowlist (`tools/ci/dead_code_allowlist.tsv`) held 52
rows that all expire on 2026-12-10. On that date the census gate fails
master. This PR clears 42 of the 52 rows. The other 10 stay, held for an
owner decision.

- **Census fix (1 row).** `tools/ci/dead_code_census.py` now follows
`use X as Y` renames, so a reference to `Y` counts for `X`. Without
this, `is_enabled_by_env` (core `async_ssh_transport.rs`), which is
reached only as `async_ssh_enabled`, was reported dead. Its stale row is
removed. The new test is in `tools/tests/test_dead_code_census.py`.
- **Deletions (41 rows).** Each function had no production caller and no
test reference. Each is deleted together with its row.

Task 603 (children 704 and 705). This PR is 704.

## Rows deleted with their function

| Crate | Functions |
|---|---|
| apple-fs | `standard_id` |
| batch | `read_all_delta_ops` |
| core | `registered_waker_count` |
| daemon | `run_stdio_session` (whole `sections/stdio_session.rs`),
`all_sessions`, `update_bytes` |
| engine | `reference_directory`, `drop_devices_enabled` |
| fast_io | `cached_sort_by_cmp`, `unlinkat_at`, `buffer_slice`,
`read_into`, `operator_link`, `process_files`, `with_thread_count` |
| logging | `init_tracing_with_filter` |
| matching | `set_role` |
| protocol | `read_ndx_from_carry_async`, `flist_stats`,
`xattr_cache_mut`, `is_io_error_end_marker` |
| rsync_io | `take_stdin`, `take_stdout`, `into_sync_halves` |
| signature | `strong_digest` |
| transfer | `with_negotiated_algorithms`, `wire_bits`,
`drain_new_redo_indices`, `match_uid`, `match_gid`,
`set_deletion_filter_chain`, `exchange_compat_flags_direct`,
`with_crtimes`, `with_flag_string`, `as_full_mut_slice` |
| xtask | `print_summary`, `run_and_extract_messages`,
`get_groups_for_scenario`, `get_messages_for_scenario`,
`version_string`, `get_oc_rsync_binary` |

Two deletions were checked by hand because their comments described live
paths:

- `run_stdio_session` claimed to serve remote-shell daemon mode
(main.c:1975-1979). The live path is `daemon::run_daemon_stdio`, called
from `crates/cli/src/frontend/server/daemon.rs`. The deleted function
was an unused duplicate.
- `into_sync_halves` was the only constructor of `rsync_io`'s
`SyncReader` / `SyncWriter`. `connect_and_exec` does not use them: it
builds its own `ChannelReader` / `ChannelWriter` in
`embedded/connect.rs`.

## Follow-on removals

Deleting `into_sync_halves` left `SyncReader`, `SyncWriter` and their
`BridgeSyncReader` / `BridgeSyncWriter` re-exports with no production
constructor. They are removed too, with:

- their 10 unit tests;
- the `round_trip_via_channel_pump` / `round_trip_via_bridge` helpers
and the 5 `wire_byte_parity_*` tests, which compared the bridge against
the removed pump.

`SyncAsyncBridge`, `ChunkPool` and `drain_into` stay, with their tests.
`connect.rs` still uses `ChunkPool` and `drain_into`.

The `sync_bridge.rs` module docs no longer describe the removed halves.
Two docs pointed at `into_sync_halves` and now point at `connect.rs`:
`docs/architecture/session-overview-ddp-async-iouring.md` and
`docs/design/russh-async-native-path.md`.

Imports left unused by the deletions are removed (transfer
`setup/compat.rs`, xtask `shared/util.rs`).

## Not covered: 10 rows held for the owner

Untouched, still expiring 2026-12-10 (task 705):

- `fast_io` `iocp/rio.rs`: `as_rio_buf`, `as_rio_buf_with_len`,
`rio_send`, `rio_recv`, `rio_create_request_queue`, `rio_notify`
- `fast_io` `adaptive_dispatch.rs`: `pick`
- `engine` `directory/planner.rs`: `plan_directory_entries_parallel`
- `engine` throughput governor: `current_ceiling` (`rope.rs`),
`into_parts_with_rope` (`work_queue.rs`)

`dead_code_census.py gate --today 2026-12-11` lists exactly these 10 as
expired, and nothing else.

## Verification

Branch head f2aa32c, on master df6f15f.


- `cargo fmt --all -- --check`: clean
- `cargo clippy --workspace --all-targets --all-features --no-deps -- -D
warnings`: clean
- the same clippy for `x86_64-pc-windows-gnu`: clean
- `cargo nextest run --all-features --lib` for every touched crate
(rsync_io, batch, signature, matching, logging, apple-fs, fast_io,
protocol, transfer, core, daemon, engine): 20,215 run, 20,203 passed.
After `cargo build -p bin`, batch passes 148/148; its 9 failures were
the missing-binary panic at `test-support/src/bin_path.rs:64`. The other
3 failures are `rsync_io` `ssh_config_differential` cells. They compare
oc's ssh_config parser against the host's `ssh -G`, which is OpenSSH
10.6p2 rather than the pinned 10.0p2 oracle (task 1079). This change
does not touch the parser. I did not rerun these 3 cells on master.
After the rebase onto #8899: fast_io + transfer --lib 4,121/4,121
- `python3 tools/ci/dead_code_census.py gate`: OK (10 rows, all
allowlisted and unexpired)
- `tools/ci/run_tools_tests.sh`: 420 tests, OK (3 skipped, all
pre-existing)
- xtask `no-placeholders`, xtask `citations`, `citation_drift_audit.py
--ratchet`, `unsafe_owner_deps.py`, `test_seam_gate.py`: OK
- xtask `no-binaries` fails the same way on master: 7
`tests/protocol_handshakes/*.bin` fixtures, none touched here, and no
workflow runs it.
oferchen added a commit that referenced this pull request Nov 28, 2026
## Summary

A local copy with `--mkpath` into a destination whose path runs through
a
regular file printed an invented line, `failed to inspect destination`,
and
exited 23. rsync 3.5.2 prints `mkdir "<dest>" failed: <make_path's
errno>` and
exits 11 (task 1236).

rsync 3.5.2:

- `get_local_name()` hands a destination that does not stat to
`make_path()`
  (main.c:757-761). A failure jumps to `mkdir_error` (main.c:818-821):
`mkdir %s failed` with `full_fname(dest_path)` as given (trailing slash
  kept), then `RERR_FILEIO` (11).
- `make_path()` (util1.c:231-247) tries the deepest directory first and
climbs
only on `ENOENT`, so the errno reported is the deepest mkdir's. `EEXIST`
  counts as success only for a directory (util1.c:244-246).
- For a relative destination the receiver's `do_mkdir_at()` opens the
parent
  through `secure_relative_dirfd()`, which reports a non-directory
intermediate as `ELOOP` (syscall.c:3279-3281). An absolute destination
uses
  plain `mkdir()` and keeps `ENOTDIR`.

This change:

- engine: a destination stat error under `--mkpath` no longer aborts;
the
  destination goes to make_path, and its failure renders as
`mkdir "<dest>" failed` with exit 11. The `--mkpath` line keeps the
trailing
  slash (main.c:760); the plain-mkdir line still cuts it (main.c:815).
- engine: the single-entry parent is made only when it is not already a
  directory (util1.c:244-246).
- fast_io: `make_path_beneath_cwd` walks deepest-first like make_path,
and maps
a non-directory intermediate to `ELOOP` the way `secure_relative_dirfd`
  does. The absolute arm uses `operator_make_path`.
- transfer: the network receiver's counting pass stops at `ENOTDIR` so
the
  making pass reports the errno (the same deepest-first rule as #8899).
- core: the destination-mkdir renderer prints the path as given.

## Measured, rsync 3.5.2 vs this branch

`dst/dstfile` is a regular file. Errno printed; every cell exits 11 on
both.
Local, push and pull give the same results.

| Shape | Relative | Absolute |
|---|---|---|
| `f dst/dstfile/x` | 17 | 17 |
| `f dst/dstfile/x/` | 20 | 20 |
| `f dst/dstfile/x/y/` | 40 | 20 |
| `f dst/dstfile/x/y` | 20 | 20 |
| `-r dst/dstfile/x` | 20 | 20 |
| `-r dst/dstfile/x/y/` | 40 | 20 |

Before this change, a local copy printed `failed to inspect destination`
and
exited 23 for every row. A network receiver given a relative destination
printed 20 where 3.5.2 prints 40.

No deviation from rsync 3.5.2.

## Tests

- New `crates/cli/tests/mkpath_through_a_regular_file.rs`: the 6 shapes
x
relative/absolute on the local, push and pull legs. Each cell runs oc to
oc,
and when `OC_RSYNC_UPSTREAM_BIN_3_5_2` resolves also 3.5.2 to 3.5.2 and
both
mixed pairs. Asserts exit 11, the exact `mkdir "<path>" failed:
<strerror>
  (<n>)` line, no invented text, and that the regular file survives. The
  strerror and errno come from the kernel, not from strings in the test.
- `crates/fast_io/tests/make_path_beneath_cwd.rs`: a regular file as the
  deepest directory's parent gives `ENOTDIR`; one higher gives `ELOOP`.

Mutations, each restored afterwards:

| Mutation | Result |
|---|---|
| make_path walks forward from the root | cli 3 tests red, fast_io 4 red
|
| no `ELOOP` mapping for a non-directory intermediate | cli 3 red,
fast_io 2 red |
| destination stat error aborts again | local red |
| receiver counting pass ignores `ENOTDIR` | push and pull red |
| parent guard made unconditional | local red |

## Verification

- `cargo fmt --all -- --check`: clean
- `cargo clippy --workspace --all-targets --all-features --no-deps -- -D
warnings`: clean
- the same clippy for `x86_64-pc-windows-gnu`: clean
- `cargo doc --workspace --all-features --no-deps --locked`: clean
- `cargo nextest run -p cli --test mkpath_through_a_regular_file` with
the
  3.5.2 oracle required (`OC_RSYNC_UPSTREAM_COMPAT=1`): 3 passed
- `cargo nextest run -p fast_io --test make_path_beneath_cwd`: 8 passed
- lib tests for fast_io, engine, transfer and core: 11873 passed
- `-p engine -p fast_io -p transfer -E 'test(mkpath) | test(make_path) |
test(destination) | test(dest_root)'`: 338 run, 323 passed. The 15
failures were tests that
spawn `oc-rsync` before it was built; after `cargo build -p bin`, a
rerun of
  those 15 (39 matching tests) passed.
- On master-identical `rsync_io`, the 3 `ssh_config_differential` cells
fail
  on the build host: its ssh is OpenSSH_10.6p2, which rejects the
`transport` keyword (task 1079). This branch does not touch `rsync_io`.
- Not run on the host: `bin`'s `destination_root_owner_walk` needs root
or
  passwordless sudo. It runs in the nextest and musl jobs.
oferchen added a commit that referenced this pull request Nov 28, 2026
## Summary

rsync 3.5.2 prints one line when the receiver cannot enter its
destination:
`rsyserr(FERROR, errno, "change_dir#N %s failed", full_fname(..))` in
`get_local_name()`:

- `change_dir#1` (main.c:779): an existing destination directory
- `change_dir#2` (main.c:837): a destination directory the run created
- `change_dir#3` (main.c:866, main.c:982): the parent of a single-file
destination

`rsyserr()` appends `: <strerror> (<errno>)` (log.c:575-585).

oc wrote this text in three places:

- `transfer` `receiver/dest_root.rs`: the `SelectStep` Display (push and
pull receivers)
- `core` `client/error.rs`: the local-copy error mapping
- `engine` `local_copy/error.rs`: the `DestinationEntryFailed` message

All three now render through one formatter, `logging::ChangeDirFailed`.
`logging` is the only crate all three already depend on (`transfer` does
not depend on `engine`).

## Design

- `logging::ChangeDirStep { One, Two, Three }`. `change_dir#4`
  (main.c:1214) has no caller in oc, so it gets no variant.
- `logging::ChangeDirFailed::new(step, fname, cause)` renders
`change_dir#N <fname> failed: <upstream_errno_text>`. The `rsync: [role]
`
  prefix stays with the caller, as before.
- `fname` arrives already rendered by `full_fname()`. Each caller keeps
its
  own name rules: `change_dir#1` keeps the operand's trailing slash
  (main.c:779 prints `dest_path` as given); `change_dir#2` lops it
  (main.c:810).
- Callers keep their own step enums and map them onto `ChangeDirStep`.
  `engine::DestinationEntry::number()` becomes `change_dir_step()`.

## Output

User-visible text is unchanged. The core and transfer lines were already
byte-for-byte upstream's, and the call sites now produce the same bytes
through the shared formatter. Engine's `DestinationEntryFailed` Display
is
not printed to users (core's `map_local_copy_error` builds the
user-visible
line); it now uses `full_fname()` like the other two, not `"{path}"`.

Oracle cells for #8890 (local copy) and #8899 (network receivers), run
on
master and on this branch, with `OC_RSYNC_UPSTREAM_BIN_3_5_2` set to
rsync
3.5.2 and `OC_RSYNC_UPSTREAM_COMPAT=1` so 3.5.2 is required:

| Target | master | this branch |
|---|---|---|
| `core --test untrusted_destination_symlink` | 14/14 | 14/14 |
| `cli --test receiver_preflight_refusals --test
mkpath_through_a_regular_file` | 12/12 | 12/12 |
| `bin --test destination_root_owner_walk` (root via sudo) | 9/9 | 9/9 |
| `transfer --lib test(dest_root)` | 4/4 | 4/4 |
| `core --lib test(change_dir) \| test(destination_entry)` | 2/2 | 2/2 |
| `engine --lib test(change_dir) \| test(destination_entry)` | 3/3 | 3/3
|

The same 44 cells by name, all passing, before and after.

## Tests

New `logging` unit table (`change_dir.rs`):

- Each step is checked against upstream's literal format string
(main.c:779,
  :837, :866), with `%s` filled in and the `rsyserr()` tail appended.
- The errno comes from a real failed `read_dir`, so the tail is the
  platform's own strerror text, not a string the test writes.
- A second test checks the name is printed as given.

Mutations, each restored afterwards:

| Mutation | logging unit | core local-copy cells | bin network cell |
|---|---|---|---|
| (a) `change_dir #N` (space added) | 2/2 red | 6/14 red | 1/9 red |
| (b) steps Two and Three swapped | 2/2 red | 5/14 red | 1/9 red |
| (c) ` failed` dropped | 2/2 red | 6/14 red | 1/9 red |

A mutation in the shared formatter turns the core and bin cells red, so
both
the local-copy path and the network receivers go through it.

## Verification

- `cargo fmt --all -- --check`, `tools/ci/check_rustfmt_all.py`: clean
- `cargo clippy --workspace --all-targets --all-features --no-deps -- -D
warnings`: clean
- the same clippy for `x86_64-pc-windows-gnu`: clean
- `RUSTDOCFLAGS="-D warnings" cargo doc --workspace --all-features
--no-deps --locked`: clean
- `cargo run --locked -p xtask -- no-placeholders`: OK
- `python3 tools/ci/citation_drift_audit.py --ratchet`: OK
oferchen added a commit that referenced this pull request Nov 28, 2026
## Summary

A daemon serving a module with `use chroot = no` had two gaps against
rsync 3.5.2, one destructive bug, and one pre-existing rendering defect
on its privileged leg.

**Data loss: an opted-out module's symlinked root was replaced.** With
`insecure links = yes` and `path =` naming a symlink, oc replaced the
operator's symlink with a new empty directory and wrote the transfer
into it. rsync 3.5.2 follows the link. oc now does the same: the symlink
is still there afterward and the data lands in its target.

**The module root was never walked by a rootless daemon.** rsync 3.5.2
enters the module root with `change_dir(module_chdir)` on every session
(clientserver.c:1063). For an unchrooted module that is the ownership
walk (util1.c:1351-1361): a symlink in `path =` owned by another user is
refused. The client gets `@ERROR: chdir failed`, and the daemon log gets
`chdir <path> failed` (clientserver.c:692-699). oc had this walk, but
`apply_privilege_restrictions_with_upstream_errors` returned early when
the session neither chrooted nor dropped privileges. A rootless daemon
therefore served a foreign-owned symlinked module root, on push and pull
alike. The early path now runs the same walk and keeps the root's
descriptor. It does not chdir (see "Working directory" below).

**The destination beneath the root was not walked either.** rsync 3.5.2
enters the client's destination with the confined walk
`secure_relative_dirfd()` (util1.c:1430-1446). That walk follows an
in-tree relative symlink and refuses one that leaves the module with
`ELOOP`, whoever owns it. `get_local_name()` then prints
`change_dir#1/#2/#3 "<dest>" (in <module>) failed` and exits 3. Under
`--mkpath` it prints `mkdir ... failed` and exits 11 (main.c:757-869).
oc instead did a plain stat and failed later in its anchored sandbox,
with either an oc-only code-11 line or a landlock `EACCES`. The receiver
now walks a daemon destination beneath the module root's descriptor and
prints 3.5.2's lines.

**Pre-existing defect on the privileged leg.** A root daemon serving an
unchrooted module with `uid =` enters the module root and served the
transfer as `.`. Two renderers took the module root from that spelling:

- `full_fname()` rendered a missing source as `link_stat "/d/d/a1" (in
m)`. 3.5.2 prints `"/d/a1"` (util1.c:1540-1547, `p1 = curr_dir +
module_dirlen`).
- A relative merge-file name was not joined onto the module root. oc
logged `failed to open exclude file etc/hostname`; 3.5.2 logs `<module
path>/etc/hostname` (exclude.c:735-746).

Both reproduce on master (c87bc25) under `sudo`. Both renderers now
read one absolute module root, recorded once per session.

`insecure links = yes` keeps the plain open for both the root and the
tail (syscall.c:139, :433-436; util1.c:1447-1451). A chrooted module
also keeps the plain chdir for the tail.

## Difference from rsync 3.5.2's process model

The observable semantics are 3.5.2's, taken from its C source:
- the `full_fname()` strip (util1.c:1543)
- the merge-file join (exclude.c:735-746)
- entering the module root before the privilege drop
(clientserver.c:1063)

Only the mechanism differs, in one place. A rootless unchrooted session
does not change directory; it walks relative to the module root's
descriptor, because oc's threaded async daemon cannot share a process
working directory.

- **What 3.5.2 does:** every session runs `change_dir(module_chdir,
CD_NORMAL)` (clientserver.c:1063). That is safe there because each
connection is its own process: `start_accept_loop()` forks per
connection (socket.c:761).
- **Why oc differs:** under `--features async-daemon`, oc serves
sessions as threads of one process, and those threads share one working
directory. A `chdir`/`fchdir` in one session would move every other
session.
- **What oc does instead:** a rootless session runs the same ownership
walk, keeps the module root's descriptor, and resolves the client's
destination beneath that descriptor.
- **Privileged sessions are unchanged:** they still `fchdir` into the
module root before the privilege drop, as 3.5.2 does
(clientserver.c:1063 before the setgid/setuid at :1102 and :1127). A
module below a directory its `uid` cannot search works only that way.
- **No async session reaches that `fchdir`:** a privileged session
always runs in its own forked process, because the async daemon refuses
`uid`, `gid`, `use chroot` and running as root (daemon.rs,
`run_async_daemon`). No new task is needed.

Client-visible output is byte-identical to 3.5.2. Both renderers take
the module root from its absolute path, so they print what 3.5.2 prints
from its working directory:
- `full_fname()` strips the module root the way util1.c:1540-1547 does
(`p1 = curr_dir + module_dirlen`).
- A relative merge-file name is joined onto the module root, as
exclude.c:735-746 joins it onto `dirbuf`.

The oracle cells compare every line against 3.5.2, in both legs and in
all four client/daemon pairings.

## Changes

- `transfer` `config/served_root.rs`: new `ServedRoot`. It holds the
module root's absolute path, its canonical form, whether the session
runs from that directory, and the root's descriptor. It is set once per
connection and replaces `daemon_module_dir`.
- `transfer` `full_fname.rs`: `FullFnamePaths::daemon` takes the
`ServedRoot`. The module strip always uses the absolute path. A session
served from its working directory roots the relative spellings first;
the sender's paths and `curr_dir` are both cwd-space (`.sender()`), the
receiver's `curr_dir` only.
- `transfer` `receiver/dest_root.rs`: new `Entry::Confined(ModuleRoot)`;
`Entry::Walked` is Unix-only, as its only constructor is. The
destination is walked beneath the root's descriptor:
  - change_dir#1 and #3 through `open_dir_beneath`
  - the change_dir#2 mkdir through `create_dir_beneath`
- `--mkpath` through `make_path_beneath`, whose `ELOOP` stays
make_path()'s own failure (exit 11), as the relative make_path of 3.5.2
reports it (syscall.c:2306-2332)
  - an `ELOOP` from change_dir is the refusal that names the step
- `transfer` `receiver/directory/mod.rs`: the destination root itself is
stat'd through a symlink that names it. Upstream stats `.` in the
directory it entered (main.c:776-781). Without this, serving the
absolute path brought the opted-out data-loss bug back.
- `transfer` `setup/context.rs`: `destination_entry` picks `Confined`
for an unchrooted daemon module that has not opted out. The merge-name
filter strips the canonical and the absolute module root.
- `daemon` `module_access/transfer/sandbox.rs`:
- The rootless early path walks and opens the module root with no chdir.
- The privileged path pins, then fchdirs, as before. Both return the
root's descriptor for the `ServedRoot`.
- On a refusal it logs the walk's own notice, then `[Receiver] chdir
<path> failed: <strerror> (<errno>)` in rsyserr form
(clientserver.c:695).
- `daemon` `orchestration.rs`, `server_config.rs`: build the
`ServedRoot` and hand it to the server config. A relative merge-file
name is joined onto the absolute root (exclude.c:735-746).
- `daemon` `module_access/helpers.rs`: `log_pending_diagnostics` drains
session diagnostics into the daemon log. It is shared with `streams.rs`,
so a notice raised before the transfer reaches the log, not stderr.
- `daemon` `module_access/transfer/streams.rs`: a fatal cause and its
trailer are written to the daemon log before they are framed for the
client. This matches upstream rwrite(), which calls logit() before
sending (log.c:390-407).
- A 3.5.2 client exits on the first error frame and kills its
remote-shell child (cleanup.c:203-204 kill_all()). Over a remote-shell
daemon, that child is the oc server, so the line never reached the log.
- Measured: the cell with a 3.5.2 client and an oc daemon over a remote
shell failed on that log line before this change.
- `fast_io` `at_syscalls/create.rs`: `open_dir_beneath`,
`create_dir_beneath` and `make_path_beneath` take the anchor descriptor.
`EINVAL` for an absolute path or `..`, as at syscall.c:3477-3484.
`make_path_beneath_cwd` delegates to `make_path_beneath(CWD, ...)`. The
cwd-only `open_dir_beneath_cwd` and `create_dir_beneath_cwd` are
removed, so there are no duplicates.

## Deviations

| Case | rsync 3.5.2 | oc |
|---|---|---|
| Push to `mod/esc/new/`, where `esc` leaves the module | `do_mkdir()`
(main.c:817) follows `esc` and **creates `outside/new`**, then
`change_dir#2 "esc/new" (in mod) failed: Too many levels of symbolic
links (40)`, exit 3 | Refuses before the mkdir: the same `change_dir#2`
line, exit 3, **nothing created outside the module** |

This deviation is owner-approved and matches #8858 and #8899. Every
other cell below matches 3.5.2.

## Measured

The 3.5.2 client drove a 3.5.2 daemon and an oc daemon, each with `use
chroot = no` and a global `log file`. The rootless rows ran the daemon
as an unprivileged user, with `flink`/`esc` owned by `nobody`.

| Cell | 3.5.2 | oc before | oc after |
|---|---|---|---|
| root-flink (module root is a foreign symlink) | `@ERROR: chdir
failed`, exit 5 | transfer through the link, exit 0 | same as 3.5.2 |
| root-fmid (`flink/sub`) | exit 5 | exit 0 | same |
| pull-flink | exit 5 | exit 0 | same |
| root-olink (own symlink) | exit 0 | exit 0 | same |
| opt-root-flink (`insecure links = yes`) | follows, exit 0 | replaced
the symlink with an empty dir | same as 3.5.2 |
| tail-rel (`rel -> inner`) | exit 0 | exit 0 | same |
| tail-esc / tail-oesc (foreign / own escaping link) | `change_dir#1
"esc/" (in mod) ... (40)`, exit 3 | oc-only line, exit 11 | same line,
exit 3 |
| tail-escfile (`mod/esc/f`) | `change_dir#3 "esc" (in mod) ... (40)`,
exit 3 | exit 11 | same |
| tail-escmk (`--mkpath mod/esc/a/b/`) | `mkdir "esc/a/b/" (in mod) ...
(40)`, exit 11 | `... Permission denied (13)`, exit 11 | same |
| tail-escnew | see Deviations | `mkdir ... (13)`, exit 11 | see
Deviations |
| opt-tail-esc (`insecure links = yes`) | follows, exit 0 | exit 0 |
same |
| priv: pull missing `d/a1` (root daemon, `uid =` the user) | `link_stat
"/d/a1" (in m)`, exit 23 | `link_stat "/d/d/a1" (in m)` | same as 3.5.2
|
| priv: `-M--filter=. /etc/hostname` | log: `failed to open exclude file
<module>/etc/hostname`, exit 11 | log: `... etc/hostname` | same as
3.5.2 |

Daemon log after the change: line for line equal to 3.5.2's, apart from
the program name (`oc-rsync:`) and the trailer location. That covers the
untrusted-symlink notice, `[Receiver] chdir <path> failed: ...`, each
`change_dir#N`/`mkdir` line with its trailer, and the merge-file line.

## Tests

- `crates/cli/tests/daemon_module_change_dir.rs`. It runs each cell oc
to oc and, when `OC_RSYNC_UPSTREAM_BIN_3_5_2` resolves, with a 3.5.2
client, a 3.5.2 daemon, and both. Results must be equal, except for the
deviation cell, which pins oc's daemon. The cells cover:
- the three refused tails (exit code, line, trailer, daemon-log line,
nothing written outside)
  - the new-directory deviation
  - in-tree and opted-out links
- a Linux-only foreign-owned module root: `@ERROR: chdir failed`, exit
5, nothing written, and the untrusted-symlink notice followed by the
`chdir <path> failed` log line
- a Linux-only opted-out foreign root (the data-loss bug): exit 0, the
root is still a symlink to the same target, and the data is in the
target
- Linux-only privileged leg under `sudo -n`: a missing source renders
`link_stat "/inner/a1" (in priv)`, and the merge file is logged as
`<module>/etc/hostname`. Red against the master binary
(`"/inner/inner/a1"`), green after.
- Linux-only privileged module below a directory its `uid` cannot search
(mode 000): push, pull and a new destination directory all exit 0 and
land in the module. This pins why the privileged session keeps its
working-directory entry.
- The root and privileged cells need `sudo -n`. They fail rather than
skip when it is unavailable.
- Log-line cells compare each daemon log line byte for byte with 3.5.2's
line. Only the program name is substituted (`rsync` vs `oc-rsync`), and
the log stamp before `] ` is stripped. A trailer is compared up to its
source location, which names each program's own file and line.
- `crates/daemon/src/tests/chunks/daemon_async_push_pull.rs`:
`concurrent_async_sessions_keep_their_own_module_roots_and_the_process_cwd`.
Two sessions on different modules run at once in one async daemon. Each
pushes 200 files and pulls a seed from its own module, and the process
working directory is unchanged afterwards. Red on this PR's first head
(a7ac723), where the rootless path fchdir'd: the cwd moved to
`module-a`. Green on master and after.
- `crates/fast_io/tests/daemon_destination_beneath_root.rs` (renamed
from `..._beneath_cwd.rs`): the three walks beneath a descriptor, with
no chdir. Covers the root and an in-tree link, an escape, `EINVAL`,
mkdir errors, a whole `make_path`, nothing made outside, and a cell
showing the anchor, not the cwd, decides where a name resolves.
- `full_fname.rs` unit tests: a session served from its cwd renders the
sender's `./d/a1` once below the root; the receiver roots only its
`curr_dir`; a session not served from its cwd roots nothing.
- Before and after: on the base sources, 4 of the 5 rootless cli cells
fail. The foreign module root exits 0, the opted-out root's symlink is
replaced, and the tails and the new dir exit 11 with oc's own lines. The
in-tree and opted-out-tail cell passes on both, as it should. After the
change all pass.
- Mutations, each red on the new cells:
- (a) plain open of the module root: the root cells red (measured before
the cell split, 4/4)
  - (b) the tail follows the escaping link: only the 2 tail cells red
- (c) swapped step mapping, change_dir#2 reported as #1: only the
new-dir cell red
- Measured locally on Linux, with `OC_RSYNC_UPSTREAM_COMPAT=1` and the
3.5.2 oracle (`cargo nextest run -p <crate> --all-features`):
  - cli: 3773 passed, 2 skipped
  - bin: 1092 passed, 29 skipped (with the 3.5.1 oracle as well)
  - fast_io: 1381 passed, 1 skipped
  - transfer: 3515 passed, 0 skipped
  - daemon: 2209 passed, 20 skipped
- The skips are existing ones. None of the new cells skips; the root and
privileged cells fail without `sudo -n`.
- Gates:
  - fmt and `check_rustfmt_all`
- workspace clippy `-D warnings` on the host and on
`x86_64-pc-windows-gnu`
  - rustdoc `-D warnings`
  - `no-placeholders`
  - `citation_drift_audit --ratchet`

## Follow-ups

- A chrooted module with a `/./` inner path (`module_dirlen > 0`). 3.5.2
confines the tail there too (util1.c:1430). oc keeps its anchored
sandbox for chrooted modules, unchanged here.
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

1 participant