Repository navigation
feat(fast_io): add DirSandbox + thread through receiver pipeline (SEC-1.e) - #4650
Merged
Merged
Conversation
Extract the cached `openat2(2)` availability probe from
`secure_dir::linux::try_openat2` into a new `linux_capabilities` module so
that the SEC-1.e..j cutover sites (`renameat2`, `linkat`, `unlinkat`, etc.)
share a single source of truth instead of each reinventing the probe.
The helper issues one no-op `openat2(AT_FDCWD, ".", { resolve: 0 })`
syscall on first call, caches the outcome in a `OnceLock<bool>`, and is
thread-safe. `ENOSYS` maps to "unsupported"; any other errno still proves
the syscall reached the kernel and is recorded as supported. On non-Linux
Unix targets the helper is a compile-time `false` so callers stay
platform-portable behind a single `#[cfg(unix)]` gate.
`secure_dir::try_openat2` now defers to `openat2_supported()` for the
gating decision; the inline `OnceLock` is gone.
…-1.e)
Introduce a parent-dirfd carrier so the SEC-1.f-j cutover sites can
replace path-based syscalls with their `*at` siblings without
re-walking paths through the kernel.
The carrier implements the hybrid shape picked in
`docs/design/sec-1-b-dirfd-carrier.md`:
* An in-tree dirfd **stack** (`enter` / `exit`) tracks the receiver's
depth-first descent. `current_dirfd()` returns the top of the
stack - or the root when empty - as a `BorrowedFd<'_>` that rayon
workers can capture by copy with zero synchronisation cost.
* A `DashMap<PathBuf, Arc<OwnedFd>>` **side cache** (`secondary`)
covers the cross-directory operands (`--backup-dir`, `--temp-dir`,
`--link-dest`, `--copy-dest`, `--compare-dest`). Entries are
registered once at receiver setup and shared by `Arc`.
Resolution policy mirrors `secure_open_dir`:
* Linux 5.6+ via `openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` -
`RESOLVE_BENEATH` is correct here because every `*at` open is
anchored on a real dirfd, not `AT_FDCWD`.
* Older Linux and other Unix targets fall back to
`openat(O_NOFOLLOW | O_DIRECTORY | O_CLOEXEC)` via `rustix`.
The `transfer::receiver::ReceiverContext` pipeline opens a
`DirSandbox` at the destination root the moment `setup_transfer`
resolves the destination path, stores it as
`Option<Arc<DirSandbox>>` on `PipelineSetup`, and forwards a borrow
into `ResponseContext` so the per-entry response path sees the
sandbox today.
No syscalls are migrated in this PR - the existing path-based code
paths remain the active code. SEC-1.f-j land the site-by-site
cutover on top of this carrier.
Carrier is `#[cfg(unix)]`; Windows continues to use NTFS handle-based
APIs (see the SEC-1.l audit) and does not need this plumbing.
This was referenced May 21, 2026
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…-1.e) (#4650) * feat(fast_io): expose openat2_supported() probe helper (SEC-1.d) Extract the cached `openat2(2)` availability probe from `secure_dir::linux::try_openat2` into a new `linux_capabilities` module so that the SEC-1.e..j cutover sites (`renameat2`, `linkat`, `unlinkat`, etc.) share a single source of truth instead of each reinventing the probe. The helper issues one no-op `openat2(AT_FDCWD, ".", { resolve: 0 })` syscall on first call, caches the outcome in a `OnceLock<bool>`, and is thread-safe. `ENOSYS` maps to "unsupported"; any other errno still proves the syscall reached the kernel and is recorded as supported. On non-Linux Unix targets the helper is a compile-time `false` so callers stay platform-portable behind a single `#[cfg(unix)]` gate. `secure_dir::try_openat2` now defers to `openat2_supported()` for the gating decision; the inline `OnceLock` is gone. * feat(fast_io): add DirSandbox + thread through receiver pipeline (SEC-1.e) Introduce a parent-dirfd carrier so the SEC-1.f-j cutover sites can replace path-based syscalls with their `*at` siblings without re-walking paths through the kernel. The carrier implements the hybrid shape picked in `docs/design/sec-1-b-dirfd-carrier.md`: * An in-tree dirfd **stack** (`enter` / `exit`) tracks the receiver's depth-first descent. `current_dirfd()` returns the top of the stack - or the root when empty - as a `BorrowedFd<'_>` that rayon workers can capture by copy with zero synchronisation cost. * A `DashMap<PathBuf, Arc<OwnedFd>>` **side cache** (`secondary`) covers the cross-directory operands (`--backup-dir`, `--temp-dir`, `--link-dest`, `--copy-dest`, `--compare-dest`). Entries are registered once at receiver setup and shared by `Arc`. Resolution policy mirrors `secure_open_dir`: * Linux 5.6+ via `openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` - `RESOLVE_BENEATH` is correct here because every `*at` open is anchored on a real dirfd, not `AT_FDCWD`. * Older Linux and other Unix targets fall back to `openat(O_NOFOLLOW | O_DIRECTORY | O_CLOEXEC)` via `rustix`. The `transfer::receiver::ReceiverContext` pipeline opens a `DirSandbox` at the destination root the moment `setup_transfer` resolves the destination path, stores it as `Option<Arc<DirSandbox>>` on `PipelineSetup`, and forwards a borrow into `ResponseContext` so the per-entry response path sees the sandbox today. No syscalls are migrated in this PR - the existing path-based code paths remain the active code. SEC-1.f-j land the site-by-site cutover on top of this carrier. Carrier is `#[cfg(unix)]`; Windows continues to use NTFS handle-based APIs (see the SEC-1.l audit) and does not need this plumbing.
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
Adds the parent-dirfd carrier that the SEC-1.f-j cutover sites consume
to replace path-based syscalls with their
*atsiblings. Implementsthe hybrid in-tree dirfd stack plus
DashMap<PathBuf, Arc<OwnedFd>>side-cache shape picked in
docs/design/sec-1-b-dirfd-carrier.md.crates/fast_io/src/dir_sandbox/- newDirSandboxtype (Unixonly). Holds an in-tree dirfd stack for the linear depth-first
descent (
enter/exit/current_dirfd) and aDashMapsidecache for cross-directory operands (
--backup-dir,--temp-dir,--link-dest,--copy-dest,--compare-dest) accessed viasecondary(path).openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)on Linux 5.6+ (gated by
fast_io::linux_capabilities::openat2_supported()),openat(O_NOFOLLOW | O_DIRECTORY | O_CLOEXEC)viarustixeverywhere else.
RESOLVE_BENEATHis correct because each*atopen is anchored on a real dirfd, not
AT_FDCWD(unlike thebootstrap
secure_open_dir, where it had to be dropped per feat(fast_io): add secure_open_dir helper for SEC-1 dirfd sandbox #4618).transfer::receiver::ReceiverContext:setup_transferopens a sandbox at the destination root, stores iton
PipelineSetup, and forwards a borrow intoResponseContextsothe per-entry response path sees the carrier today.
What this does NOT do
No syscalls are migrated in this PR. The existing path-based code
paths remain the active code; the carrier is plumbed but currently
unused at every syscall site. The site-by-site migration is the work
of SEC-1.f-j (see breakdown in
docs/design/sec-1-b-dirfd-carrier.mdSection 7).Prerequisites
secure_open_dirhelper (SEC-1.c) - landed via feat(fast_io): add secure_open_dir helper for SEC-1 dirfd sandbox #4618.openat2_supported()probe helper (SEC-1.d) - landed via feat(fast_io): expose openat2_supported() probe helper (SEC-1.d) #4643;this PR's branch is built on top of that commit and assumes it
reaches master first.
Unblocks
crates/transfer/src/receiver/directory/.crates/engine/src/local_copy/executor/(10 sites infile/guard.rsalone).crates/metadata/src/apply/.renameat/linkatconsuming the
secondarycache).dirfd_remove_dir_all+ remaining edges.Cross-references the 107-site inventory in
docs/audits/sec-1-a-path-syscall-surface-2026-05-20.md.Carrier shape
The
BorrowedFd<'_>accessor isCopy + Send + Sync, so rayonworker closures capture the parent dirfd by value with zero
synchronisation cost - the pattern called out in
docs/design/sec-1-b-dirfd-carrier.mdSection 5.Constraints satisfied
#[cfg(unix)]; Windows continues to usehandle-based NTFS APIs (SEC-1.l audit).
dashmapandrustix; onlyfast_io'sCargo.tomlgains adashmapline.#[allow(...)]waivers; all#[allow(unsafe_code)]blocks areinside
fast_ioper workspace policy and carry a documentedSAFETY argument.
ReceiverContext/ParallelDeltaApplierisunchanged.
ResponseContextgains one Unix-only optional field(
sandbox: Option<&fast_io::DirSandbox>) populated internally; noexternal caller touches the struct.
Test plan
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features --no-deps -- -D warningscargo nextest run -p fast_io --features io_uring -E 'test(dir_sandbox)'-11/11 unit tests pass.
cargo nextest run -p engine --features parallel-receive-delta-4379/4379 pass (no regression).
cargo nextest run -p transfer --features incremental-flist-1611/1613 pass; the 2 failures (
files_from::relative_absolute_source_preserves_full_prefixand
empty_file_checksum_verification_sha1) reproduce on thebase branch without this PR's changes and are unrelated.
cargo nextest run -p transfer -E 'binary(dir_sandbox_carrier)'-4/4 integration tests pass.