Repository navigation
fix: protect receiver chdir against symlink-race TOCTOU - #5519
Merged
Merged
Conversation
Daemon receivers without chroot now refuse a leaf-symlink at the destination directory and route the client's positional dest through to the receiver instead of silently writing every transfer into the module root. Two coupled changes close the chdir-symlink-race attack window: * `client_args.rs::build_server_config` now mirrors upstream's `read_args()` + `glob_expand_module()` (io.c:1295, util1.c:813-814). The wire positional after the `.` separator carries the module name prefix (e.g. `upload/realdir/`); we strip the bare module name and join the tail with the on-disk module path so the receiver writes into the requested subdirectory. The Generator path is left at the module root for now to keep the daemon pull tests stable. The resulting connection is tagged `is_daemon_connection = true` so the strict symlink-refusal branch fires. * `receiver/transfer/setup.rs` gains `open_sandbox_for_dest_strict`, which promotes ELOOP / ENOTDIR / EXDEV from the DirSandbox open into a transfer error when the connection is a daemon. ENOENT and generic errors keep the existing soft-fall-back so first-run pushes still create the destination. This mirrors upstream's `use_secure_symlinks = am_daemon && !am_chrooted` gate (clientserver.c:1018) and `change_dir()`'s `secure_relative_open() + fchdir()` branch (util1.c:1175-1216). Unit tests cover the new helpers and the symlink-refusal branches at both the daemon arg-rewrite layer and the receiver sandbox layer.
oferchen
force-pushed
the
fix/uts-16-chdir-symlink-race
branch
from
June 10, 2026 02:58
b3b1571 to
b7beb33
Compare
io::ErrorKind::FilesystemLoop and NotADirectory are still gated behind the unstable io_error_more feature, which blocks stable builds (sync-async-wire-parity + fmt+clippy). Embed the raw errno in the wrapped error message and assert on that substring in the symlink-race test instead. Also collapses a trim_start_matches closure into a char-array pattern to satisfy clippy::manual_pattern_char_comparison.
2 tasks
oferchen
added a commit
that referenced
this pull request
Jun 10, 2026
Group PRs #5510, #5516, #5519, #5520, #5523, #5525-#5544 by shared root cause rather than by Stream bucket. Seven clusters surface; the parser- stores-string and field-vs-method shadowing clusters cover the largest share of the series, and the receiver-driver wiring-parity gap explains the NDX_DEL_STATS goodbye misses in both #5536 and #5542. Includes a defense-in-depth audit mapping each cluster onto the rust-landlock ruleset wired at crates/fast_io/src/landlock.rs. Doc-only; no code paths touched.
oferchen
added a commit
that referenced
this pull request
Jun 10, 2026
Group PRs #5510, #5516, #5519, #5520, #5523, #5525-#5544 by shared root cause rather than by Stream bucket. Seven clusters surface; the parser- stores-string and field-vs-method shadowing clusters cover the largest share of the series, and the receiver-driver wiring-parity gap explains the NDX_DEL_STATS goodbye misses in both #5536 and #5542. Includes a defense-in-depth audit mapping each cluster onto the rust-landlock ruleset wired at crates/fast_io/src/landlock.rs. Doc-only; no code paths touched.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Group PRs #5510, #5516, #5519, #5520, #5523, #5525-#5544 by shared root cause rather than by Stream bucket. Seven clusters surface; the parser- stores-string and field-vs-method shadowing clusters cover the largest share of the series, and the receiver-driver wiring-parity gap explains the NDX_DEL_STATS goodbye misses in both #5536 and #5542. Includes a defense-in-depth audit mapping each cluster onto the rust-landlock ruleset wired at crates/fast_io/src/landlock.rs. Doc-only; no code paths touched.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
* fix: protect receiver chdir against symlink-race TOCTOU Daemon receivers without chroot now refuse a leaf-symlink at the destination directory and route the client's positional dest through to the receiver instead of silently writing every transfer into the module root. Two coupled changes close the chdir-symlink-race attack window: * `client_args.rs::build_server_config` now mirrors upstream's `read_args()` + `glob_expand_module()` (io.c:1295, util1.c:813-814). The wire positional after the `.` separator carries the module name prefix (e.g. `upload/realdir/`); we strip the bare module name and join the tail with the on-disk module path so the receiver writes into the requested subdirectory. The Generator path is left at the module root for now to keep the daemon pull tests stable. The resulting connection is tagged `is_daemon_connection = true` so the strict symlink-refusal branch fires. * `receiver/transfer/setup.rs` gains `open_sandbox_for_dest_strict`, which promotes ELOOP / ENOTDIR / EXDEV from the DirSandbox open into a transfer error when the connection is a daemon. ENOENT and generic errors keep the existing soft-fall-back so first-run pushes still create the destination. This mirrors upstream's `use_secure_symlinks = am_daemon && !am_chrooted` gate (clientserver.c:1018) and `change_dir()`'s `secure_relative_open() + fchdir()` branch (util1.c:1175-1216). Unit tests cover the new helpers and the symlink-refusal branches at both the daemon arg-rewrite layer and the receiver sandbox layer. * style: wrap resolve_receiver_dest signature for rustfmt * fix: handle Windows absolute paths and verify ErrorKind in symlink-race fix * fix: use stable errno instead of unstable ErrorKind variants io::ErrorKind::FilesystemLoop and NotADirectory are still gated behind the unstable io_error_more feature, which blocks stable builds (sync-async-wire-parity + fmt+clippy). Embed the raw errno in the wrapped error message and assert on that substring in the symlink-race test instead. Also collapses a trim_start_matches closure into a char-array pattern to satisfy clippy::manual_pattern_char_comparison.
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
Daemon receivers without chroot now refuse a leaf-symlink at the destination directory and route the client's positional dest through to the receiver instead of silently writing every transfer into the module root. Closes the chdir-symlink-race attack window (the upstream testsuite test of the same name).
Background
The upstream
chdir-symlink-racetest (testsuite/chdir-symlink-race.test) reproduces a post-CVE-2026-29518 TOCTOU race: the daemon receiver chdir's into a destination subdirectory while an attacker swaps that subdirectory for a symlink. Every subsequent path-relative syscall (open, chmod, lchown, ...) then inherits the escape and re-opens the same class of attack the original fix tried to close.When run against oc-rsync the test failed at the positive control stage. The receiver was writing every push directly into the module root, ignoring the client's positional destination (
upload/realdir/). That meant the attacks were vacuously safe (no write ever reached the symlink) but the test fails before exercising the security check.Fix
Two coupled changes:
client_args.rs::build_server_configmirrors upstream'sread_args()+glob_expand_module()(io.c:1295, util1.c:813-814). The wire positional after the.separator carries the module name prefix (e.g.upload/realdir/); we strip the bare module name and join the tail with the on-disk module path so the receiver writes into the requested subdirectory. The Generator path is left at the module root for now to keep the daemon pull tests stable. The resulting connection is taggedis_daemon_connection = trueso the strict symlink-refusal branch fires.receiver/transfer/setup.rsgainsopen_sandbox_for_dest_strict, which promotesELOOP/ENOTDIR/EXDEVfrom theDirSandboxopen into a transfer error when the connection is a daemon.ENOENTand generic errors keep the existing soft-fall-back so first-run pushes still create the destination. This mirrors upstream'suse_secure_symlinks = am_daemon && !am_chrootedgate (clientserver.c:1018) andchange_dir()'ssecure_relative_open() + fchdir()branch (util1.c:1175-1216).DirSandbox::open_rootalready usesopenat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)on Linux 5.6+ (viafast_io::secure_open_dir) andopen(O_NOFOLLOW | O_DIRECTORY)on macOS / older Linux, so no new syscall plumbing was needed - only the refusal-on-failure policy.Test plan
extract_module_relative_paths,resolve_receiver_dest) cover the bare-module, subpath, sibling-prefix and absolute-arg edges.open_sandbox_for_dest_strictconfirm: strict mode refuses symlink dests with ELOOP/ENOTDIR, non-strict mode preserves the soft fall-back, real directories open under strict mode, missing destinations soft-fail (so first-run pushes still mkdir).chdir-symlink-racepasses on Linux when the oc-rsync binary is the daemon-side peer.