Repository navigation
fix: refuse a bad --backup-dir and an unenterable dest root - #8882
Merged
Merged
Conversation
The receiver stats the backup directory before it transfers anything, resolved against the destination, as rsync 3.5.2 does in do_recv() (main.c:1036-1057). A path that exists but is not a directory ends the run with "The backup-dir is not a directory: %s" and exit 1; any stat failure except ENOENT, such as a path below a regular file, ends it with "Failed to stat %s: %s" and exit 11. The name shown is backup_dir_buf: leading "./" pairs stripped and one trailing slash removed (options.c:2514-2530, main.c:1039-1040). Previously the transfer started and failed at the first backup (exit 23 locally, a keep_backup error remotely), or did not fail at all when no file needed a backup. The client receiver checks before connecting, ahead of --temp-dir as upstream orders them; the --server receiver checks before its --temp-dir check and sends the line to the client.
rsync 3.5.2 get_local_name() (main.c:776-781) changes into an existing destination directory and, when that fails, reports change_dir#1 "<dest>/" failed: <strerror> and exits 3, dry run included. A pull or push into a mode-000 destination root carried on instead, failed every entry and exited 23; a dry-run pull exited 0. The receiver pre-flight now stats "<dest>/." for an existing destination directory, which like chdir needs search permission and not read permission, and reports a failure as a new change_dir#1 select step through the existing get_local_name() refusal path.
oferchen
added a commit
that referenced
this pull request
Nov 27, 2026
## 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. - `--mkpath` builds the missing leading directories per component, as `make_path()` does. A relative destination uses `do_mkdir_at()`'s confined arm (syscall.c:2306-2332): an in-tree symlink is followed, one that leaves the tree fails with `mkdir "<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-links` keeps 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 of `change_dir#1` keeps 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 | Case | rsync 3.5.2 | oc | |---|---|---| | A directory the run creates below another user's symlink: the created destination directory, and the missing parents of an absolute `--mkpath` destination | A plain mkdir follows the symlink and creates the directory in the other user's tree (`do_mkdir()`, or `make_path()` creating `outside/new`), prints `created directory` under -v, then refuses at `change_dir#2` / `change_dir#3`, exit 3 | Walks the leading directories and refuses before any mkdir. Same refusal lines and exit 3; nothing is created and no `created directory` line 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_mkdir` | A 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()` and `do_mkdir()` are unchanged from 3.5.2, and the 4.0.0 milestone plans no change here. ## Tests - Core cells for the single-file (immediate and interior symlink), created-directory and existing-directory cases, each refused for a foreign owner and followed for the user's own symlink, run unprivileged through the ownership test seam. - fast_io cells: a single-file commit lands in the pinned parent after the parent is swapped for a symlink, with a control showing an unpinned commit follows the swap; confined `make_path` cells for in-tree, absolute-target and climbing symlinks. - Measured with a real symlink owned by uid 65534 against rsync 3.5.2: local single-file and created-directory runs print the same lines and exit 3 (apart from the deviation above). - Stderr order: the cli and bin suites with the 3.5.2 oracle (4,800 tests) pass unchanged. ## Cost `strace -c`, local copy of 10,000 files (100 directories of 100) into an existing directory, two runs each: | syscall | master | this change | |---|---|---| | openat | 20,346 | 20,346 | | openat2 | 10,001 | 10,001 | | newfstatat | 20,420 | 20,420 | | statx | 30,227 | 30,225 | | mkdir | 100 | 100 | | getdents64 | 210 | 210 | ## 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#1` does (main.c:776-781) and reports that failure itself. Measured on a mode-000 destination root, master b56e3a1 against this branch: | Leg | master | this branch | rsync 3.5.2 | |---|---|---|---| | local | exit 3, `failed to access destination directory '<B>/dest/': Permission denied (13)` | exit 3, `[Receiver] change_dir#1 "<B>/dest/" failed: Permission denied (13)` and the code-3 `[Receiver=]` trailer | exit 3, same two lines | | push | exit 3, `change_dir#1` line and code-3 trailer | identical bytes | exit 3, same lines | | pull | exit 3, `change_dir#1` line and code-3 trailer | identical except the trailer's own source line, `error.rs(443)` -> `error.rs(445)` | exit 3, same lines plus the sender's `received SIGUSR1` line | The local row changes on purpose: it now prints rsync 3.5.2's lines. The dry-run pull matches the pull row. `receiver_preflight_refusals` runs all 8 cells unprivileged, none skipped. With the engine `change_dir#1` entry removed, `a_local_copy_refuses_an_unsearchable_destination_root` fails (exit 0 instead of 3), so that cell exercises the new path. That cell now asserts the `change_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 - Network receivers: #8870, #8863. Closes #8858
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
Two receiver pre-flight refusals rsync 3.5.2 makes before it transfers
anything, which oc-rsync either reported with the wrong exit code or did not
make at all.
--backup-dirthat is not a directoryrsync 3.5.2
main.c:1036-1057do_recv()stats the backup directory once,after
get_local_name()has entered the destination, so a relative valueresolves against the destination:
The backup-dir is not a directory: %s,RERR_SYNTAX(1);ENOENT(for example a path below a regular file,ENOTDIR):Failed to stat %s: %s,RERR_FILEIO(11);ENOENTis accepted; the first backup creates it.The name shown is
backup_dir_buf: leading./pairs stripped and onetrailing slash removed (
options.c:2514-2530,main.c:1039-1040).oc-rsync never ran this check. It started the transfer and failed at the first
backup: exit 23 on a local copy, exit 11 with a
keep_backup failedline on apush or pull, and no refusal at all when no file needed backing up.
The fix adds
transfer::check_backup_dir, shared by both receivers:existing
--temp-dircheck and ahead of it, as upstream orders them;--serverreceiver (push, daemon push) checks right before its--temp-dircheck and sends the line to the client, ascheck_server_temp_dirdoes.Destination root the receiver cannot enter
rsync 3.5.2
main.c:776-781get_local_name()doeschange_dir()into anexisting destination directory and, when that fails, reports
change_dir#1 "<dest>/" failed: <strerror>and exitsRERR_FILESELECT(3),dry run included.
The local copy already exited 3. A pull or push into a mode-000 root did not:
the receiver went on, failed every entry, and exited 23; a dry-run pull exited
0.
ensure_dest_root()now stats<dest>/.for an existing directory. Likechdir, that needs search permission and not read permission. A failurebecomes a new
SelectStep::ChangeDir1, which the existingDestRootSelectErrorreporting already renders with upstream's role and exit code.
Before / after vs rsync 3.5.2
Measured on Linux (glibc, non-root) with a 3.5.2 build that has xxhash, zstd and lz4.
--backup-dir=<abs>/reg/sub(below a file)keep_backup failed)Failed to stat ...)keep_backup failed)Failed to stat ...)--backup-dir=reg/sub(relative)keep_backup failed)Failed to stat reg/sub: ...)--backup-dir=<abs>/reg(a file)--backup-dir=../reg(a file)Not changed:
--checksum-choice=xxh128 --protocol=29and--compress-choice=lz4 --protocol=30These were reported as cases where 3.5.2 exits 4. It does not. 3.5.2 has no
protocol gate on either choice (
checksum.c:192-226parse_checksum_choice(),compat.c:183-221parse_compress_choice()). The exit 4 comes from buildscompiled without xxhash or lz4, which print
unknown checksum name: xxh128orunknown compress name: lz4. A 3.5.2 build with both libraries exits 0 on everyleg (local, ssh push and pull, daemon push and pull), and so does oc-rsync. No
change was made for these.
Tests
crates/cli/tests/receiver_preflight_refusals.rs: every cell asserts themeasured 3.5.2 exit code and message, and that the old destination file is
untouched (nothing was transferred). With the 3.5.2 oracle available, each cell
also runs 3.5.2 at both ends and in both mixed pairings.
across local, push, pull and daemon push. The absolute spellings skip the
daemon, which sanitizes them (
options.c:2473).root, because root ignores mode 000.
Unit tests in
transfer::receiver::backup_dircover the displayed-namenormalization,
ENOENTacceptance, trailing-slash handling anddestination-relative resolution.
Mutation check, with the 3.5.2 oracle required (
OC_RSYNC_UPSTREAM_COMPAT=1):check_backup_dir()short-circuited toOk(()), all 4 backup-dir testsfail (local, push, pull, daemon push);
<dest>/.probe short-circuited, the push, pull and dry-run pullunsearchable-root tests fail. The local cell still passes: the local copy
already exited 3 before this change, and that cell guards against
regressions.
Remaining differences
failed to access destination directory '<dest>/'instead ofchange_dir#1 "<dest>/" failed. The exit codematches. The same function also words the destination symlink-walk refusal,
so I left the rewording for a separate change.
oc-rsync error: <text> (code N) at ...single-line form that the
--temp-dirrefusals already use, not upstream'stwo lines.
Closes #8881