Repository navigation
fix: enter a local copy's destination like change_dir does - #8890
Merged
Merged
Conversation
A local copy into a single-file destination, or into a destination directory the run creates, resolved the destination with plain path calls, so a symlink owned by another user in the leading directories was followed and the copy wrote outside the operator's tree. The engine now enters the destination the way rsync 3.5.2's get_local_name() does (main.c:757-868): change_dir#1 for an existing directory, change_dir#2 after creating one, change_dir#3 for a single-file destination's parent. Each entry goes through the ownership walk and pins the entered descriptor. A refusal prints upstream's line and exits 3. --mkpath builds missing parents per component like make_path(); a relative destination uses do_mkdir_at()'s confined arm (fast_io::make_path_beneath_cwd), which fails with ELOOP on a symlink that leaves the tree. Deliberate deviation: a directory the run would create below another user's symlink is refused before the mkdir; rsync 3.5.2 creates it first and refuses afterwards. Closes #8858
oferchen
added a commit
that referenced
this pull request
Nov 28, 2026
## 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 #8890). Folding them into one shared formatter is task 1233. - **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 with task 1104. - 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 with task 548. - The non-chrooted daemon receiver's module walk (util1.c:1351) is task 1227. - The shared `change_dir#N` formatter is task 1233. ## 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 #8898, not this change. Closes #8870 Part of #8863 (push line order: task 1104; daemon receiver: task 1227)
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
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 local copy into a single-file destination, or into a destination directory the run creates, resolved the destination with plain path calls. A symlink owned by another user in the leading directories was followed, so the copy wrote outside the operator's tree. rsync 3.5.2 enters the destination with
change_dir()and refuses that symlink.This change makes the local copy enter its destination the way
get_local_name()does (main.c:777-868):change_dir#1: an existing destination directory is entered through the ownership walk and pinned.change_dir#2: a directory the run creates is entered and pinned after the mkdir.change_dir#3: the parent of a single-file destination is entered and pinned, and every later open, rename and link of that entry goes through the pinned descriptor.--mkpathbuilds the missing leading directories per component, asmake_path()does. A relative destination usesdo_mkdir_at()'s confined arm (syscall.c:2306-2332): an in-tree symlink is followed, one that leaves the tree fails withmkdir "<dest>" failed: Too many levels of symbolic links (40), exit 11.A symlink the user owns is still followed, as in 3.5.2.
--insecure-linkskeeps the old behaviour.Output and exit codes
For each refused case oc prints 3.5.2's refusal line, then
change_dir#N "<path>" failed: Too many levels of symbolic links (40), and exits 3. The"dest/"spelling ofchange_dir#1keeps the operand's trailing slash, as 3.5.2 does. Messages queued before the failure are printed before the failure report, so the order matches 3.5.2.Deliberate deviation from rsync 3.5.2
--mkpathdestinationdo_mkdir(), ormake_path()creatingoutside/new), printscreated directoryunder -v, then refuses atchange_dir#2/change_dir#3, exit 3created directoryline is printed. Cells:a_directory_created_for_several_entries_under_an_untrusted_symlink_is_refused,a_directory_created_for_a_trailing_slash_under_an_untrusted_symlink_is_refused,mkpath::an_absolute_destination_through_a_foreign_symlink_is_refused_before_any_mkdirA symlink the user owns is followed in both, so there is no difference there.
The mkdir that 3.5.2 performs first is the very write through an untrusted symlink that the CVE-2026-53796 fix exists to stop. Upstream master's
get_local_name()anddo_mkdir()are unchanged from 3.5.2, and the 4.0.0 milestone plans no change here.Tests
make_pathcells for in-tree, absolute-target and climbing symlinks.Cost
strace -c, local copy of 10,000 files (100 directories of 100) into an existing directory, two runs each:Scope
This change covers the local copy.
Rebase note
#8882 added a mode-000 destination-root check in core's client run path. This change removes it, because the engine now enters an existing destination the way
change_dir#1does (main.c:776-781) and reports that failure itself. Measured on a mode-000 destination root, master b56e3a1 against this branch:failed to access destination directory '<B>/dest/': Permission denied (13)[Receiver] change_dir#1 "<B>/dest/" failed: Permission denied (13)and the code-3[Receiver=]trailerchange_dir#1line and code-3 trailerchange_dir#1line and code-3 trailererror.rs(443)->error.rs(445)received SIGUSR1lineThe local row changes on purpose: it now prints rsync 3.5.2's lines. The dry-run pull matches the pull row.
receiver_preflight_refusalsruns all 8 cells unprivileged, none skipped. With the enginechange_dir#1entry removed,a_local_copy_refuses_an_unsearchable_destination_rootfails (exit 0 instead of 3), so that cell exercises the new path. That cell now asserts thechange_dir#1 "<dest>/" failed: Permission denied (13)line and the code-3 trailer on every leg, local included, and passes against the rsync 3.5.2 oracle too.Remaining differences
Closes #8858