Repository navigation
fix: follow symlink at dest_root to match upstream main.c:745-754 - #5675
Merged
Merged
Conversation
Owner
Author
|
Auto-rebase blocked: substantive conflict in |
oferchen
force-pushed
the
fix/uts-sldb-follow-symlink-dest-root
branch
2 times, most recently
from
June 11, 2026 17:59
0e73b5f to
fd28ea2
Compare
The receiver-side `ensure_dest_root_exists()` pre-flight used `symlink_metadata()` (lstat) and rejected any symlinked destination with `InvalidInput`. Upstream `main.c:745-754` calls `do_stat()` (follows symlinks), accepts the dest when `S_ISDIR(st.st_mode)` is true, then enters the resolved directory via `change_dir()`. The upstream `symlink-dirlink-basis` interop test (issue #715) drives this path with `$HOME/dir -> $HOME/real-dir` and `-K`. Switch the helper to `metadata()` so a symlink-to-existing-directory dest is accepted, and surface a dangling-symlink dest as `NotFound` via an `lstat` follow-up (instead of letting `create_dir_all` materialize the directory at the link target). Canonicalize the symlinked dest in `setup_transfer` so the downstream `DirSandbox` opens the resolved target dirfd once; per-entry `*at` syscalls then anchor at the canonical path. Skip the canonicalize step for daemon connections so the strict `open_sandbox_for_dest_strict` path keeps refusing symlinked dests (chdir-symlink-race defense). Security model: per-entry writes are sandboxed by the SEC-1 `*at` chain (`openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` on Linux 5.6+, `openat(O_NOFOLLOW | O_DIRECTORY)` elsewhere). Accepting a symlinked dest at the pre-flight does not weaken that containment because the canonical resolved path becomes the sandbox root. Tests: - Update `uts_2_dest_root_mkdir.rs` to assert the new accept-on- symlink-to-dir behavior and the dangling-symlink `NotFound` surface; remove the four pre-PR refusal tests they superseded. - Add a chained-dangling-symlink regression and an explicit rejected-non-directory test.
oferchen
force-pushed
the
fix/uts-sldb-follow-symlink-dest-root
branch
from
June 11, 2026 18:30
fd28ea2 to
e49563a
Compare
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
) * fix(receiver): follow symlink at dest_root to match upstream The receiver-side `ensure_dest_root_exists()` pre-flight used `symlink_metadata()` (lstat) and rejected any symlinked destination with `InvalidInput`. Upstream `main.c:745-754` calls `do_stat()` (follows symlinks), accepts the dest when `S_ISDIR(st.st_mode)` is true, then enters the resolved directory via `change_dir()`. The upstream `symlink-dirlink-basis` interop test (issue #715) drives this path with `$HOME/dir -> $HOME/real-dir` and `-K`. Switch the helper to `metadata()` so a symlink-to-existing-directory dest is accepted, and surface a dangling-symlink dest as `NotFound` via an `lstat` follow-up (instead of letting `create_dir_all` materialize the directory at the link target). Canonicalize the symlinked dest in `setup_transfer` so the downstream `DirSandbox` opens the resolved target dirfd once; per-entry `*at` syscalls then anchor at the canonical path. Skip the canonicalize step for daemon connections so the strict `open_sandbox_for_dest_strict` path keeps refusing symlinked dests (chdir-symlink-race defense). Security model: per-entry writes are sandboxed by the SEC-1 `*at` chain (`openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` on Linux 5.6+, `openat(O_NOFOLLOW | O_DIRECTORY)` elsewhere). Accepting a symlinked dest at the pre-flight does not weaken that containment because the canonical resolved path becomes the sandbox root. Tests: - Update `uts_2_dest_root_mkdir.rs` to assert the new accept-on- symlink-to-dir behavior and the dangling-symlink `NotFound` surface; remove the four pre-PR refusal tests they superseded. - Add a chained-dangling-symlink regression and an explicit rejected-non-directory test. * style: apply cargo fmt to receiver dest_root + test wrappings
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
The receiver-side
ensure_dest_root_exists()pre-flight usedsymlink_metadata()(lstat) and explicitly rejected any symlinked destination withInvalidInput. Upstreammain.c:745-754(get_local_name()) instead callsdo_stat()which follows symlinks, accepts the destination whenS_ISDIR(st.st_mode)is true, and then enters the resolved directory viachange_dir(dest_path, CD_NORMAL). The upstreamsymlink-dirlink-basisinterop test (issue #715) drives exactly this code path with\$HOME/dir -> \$HOME/real-dirand-K (--copy-dirlinks).This change brings the helper in line with upstream:
metadata()so a symlink-to-existing-directory dest is accepted.metadata()reportsNotFound, do anlstatfollow-up and surfaceNotFoundinstead of lettingcreate_dir_allresolve the link and materialize a directory at the link target.transfer::receiver::transfer::setup::setup_transferso the downstreamDirSandbox::open_rootopens the resolved target dirfd; per-entry*atsyscalls then anchor at the canonical path.open_sandbox_for_dest_strictkeeps refusing symlinked dests viaELOOP/ENOTDIR(the chdir-symlink-race defense).Security model
Per-entry writes are sandboxed by the SEC-1 `*at` chain (see `crates/fast_io/src/dir_sandbox/mod.rs:150` `secure_open_dir` and `crates/transfer/src/receiver/transfer/setup.rs:310` `open_sandbox_for_dest_strict`). Opens route through `openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` on Linux 5.6+ and `openat(O_NOFOLLOW | O_DIRECTORY)` elsewhere. Accepting a symlinked dest at the pre-flight does not weaken containment because the canonical resolved path becomes the sandbox root and every subsequent open is anchored at that resolved fd. Daemon connections keep the strict refusal at the sandbox layer.
The chdir-symlink-race tests (UTS-16) live in `crates/transfer/src/receiver/transfer/setup.rs::symlink_race_tests` and target `open_sandbox_for_dest_strict` (per-entry symlink swap, not dest-root). They test a different attack surface and remain unchanged.
Test changes
Test plan