Repository navigation
fix: walk a network receiver destination before mkdir - #8899
Merged
Merged
Conversation
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.
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.
This was referenced Nov 28, 2026
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.
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.
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
--serverreceiver of a pushand 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 withopen_no_attacker_symlinks_dirfd()andfchdir()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 isentered through the ownership walk and the walked descriptor is pinned.
change_dir#2(main.c:836-839): a directory the run creates is made fromthe walked parent and entered the same way.
change_dir#3(main.c:865-868): the parent of a single-file destination iswalked and pinned.
--mkpath(main.c:757-773) builds the missing leading directories percomponent 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-linkson thereceiving 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, thenconfinement::pin_destination_root.transferdoes not open-codeopenator
O_NOFOLLOWsteps.One walk for both legs.
ensure_dest_root(.., Entry)inreceiver/dest_root.rsserves the push and the pull receiver through thesame
ReceiverContextsetup; the only switch isdestination_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#Ntext: it adds theChangeDir2arm to the existingSelectStepDisplay (receiver/dest_root.rs). The text is written today inthree places across the workspace -
transferreceiver/dest_root.rs(
SelectStep),coreclient/error.rsandenginelocal_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 walkeddescriptor is pinned instead. Evidence (below):
symlink-dirlink-basispasses 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-arggreen.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:The one stat fewer per run is the
lstatthat guarded the deletedcanonicalize()block. The walk's search check ondest/.(chdir'simplicit search-permission check, which an
O_PATHopen skips) replacesthe
dest/.stat master already made, so it adds nothing. readlink countsare 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:
flink/new/[Receiver] change_dir#2 "ROOT/flink/new" failed: Too many levels of symbolic links (40), exit 3flink/change_dir#1 "ROOT/flink/", exit 3flink/single(one file)change_dir#3 "ROOT/flink", exit 3--mkpath flink/a/b/change_dir#1 "ROOT/flink/a/b/", exit 3olink/new/(own link)--insecure-links flink/new/change_dir#1keeps the operand's trailing slash, as 3.5.2 does:full_fnameprints
dest_pathas given (main.c:779). The trailer names oc's ownfile(line), as for every oc trailer.
Deliberate deviation from rsync 3.5.2
--mkpathdestinationreal/new(main.c:817) orreal/a/b(make_path, main.c:757-773), then refuses atchange_dir#2(main.c:836-839) orchange_dir#1(main.c:777-781), exit 3This 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
change_dir#Nline and the trailer first and therefusal line last. A pull matches. Tracked separately.
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.
change_dir#Nformatter is a separate follow-up.Tests
tests/destination_root_owner_walk.rs:network_receivers_stop_at_upstreams_change_dir_step: push and pull,four stops (new dir
change_dir#2, existing dirchange_dir#1, single filechange_dir#3,--mkpathchange_dir#1). Each asserts exit 3, the refusalline, the exact
[Receiver] change_dir#N "<path>" failed:line from the3.5.2 run above, no invented text, and that nothing was created below the
symlink.
now expects the refusal line, which a
--serverreceiver relays asMSG_ERROR (log.c:437-446).
skip()is nowmissing_privilege(), which panics: a host thatcannot 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 hostedubuntu-latestrunners with passwordless sudo (their own setup steps runsudo apt-get/sudo rmnon-interactively):--workspace)--workspace), nocontainer:cfg(unix))Mutations, each restored afterwards:
create_rootuses a plainstd::fs::create_dirpin_operator_destination(.., None))rrsync-receiver-file-argred ("in-place transfer changed the outside fixture");symlink-dirlink-basisstill passesUpstream testsuite (rsync 3.5.2
runtests.py, binary copied to a file namedrsync): master 289 passed, 87 skipped, 0 failed; this branch 289 passed, 87skipped, 0 failed.
symlink-dirlink-basis,rrsync-receiver-file-argandrrsync-userns-procfspass on both.rrsync-userns-procfsfails on mastertoo when the binary is named
oc-rsync("cannot locate the rsyncexecutable", rrsync-userns-procfs_test.py:31-41); the copy named
rsyncpasses on master, so that failure is harness naming, not this change.
Verification
cargo fmt --all -- --check,tools/ci/check_rustfmt_all.py: cleancargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings: cleanx86_64-pc-windows-gnu: cleancargo nextest run -p bin --test destination_root_owner_walk(root): 9 passedcargo nextest run -p transfer -E 'test(dest_root) | test(receiver::)': 937 passedcargo nextest run -p core(scoped): 17 passedunsafe-owner deps, test-seam gates: OK
tools/ci/run_tools_tests.sh: OK. The gate run once reportedFAILED (errors=1, skipped=2). Rerun with full logs: 5 of 5 sequential runspass, 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)