Repository navigation
feat(transfer): thread DirSandbox through temp_guard/temp_cleanup (SEC-1.r) - #4723
Merged
Merged
Conversation
…C-1.r) Routes receiver-side temp-file creation and the matching unlink-on-drop through `openat(dirfd, leaf, ...)` / `unlinkat(dirfd, leaf, 0)` instead of path-based syscalls so a TOCTOU symlink swap on the temp parent cannot redirect the create or the cleanup. - `temp_guard::open_tmpfile_sandboxed` dispatches the create through `fast_io::openat_via_sandbox_or_fallback` and seeds the returned `TempFileGuard` with a sandbox anchor for the matching Drop unlink. - `temp_cleanup::cleanup_stale_temp_files_sandboxed` routes the per- entry unlink through `unlink_via_sandbox_or_fallback`; the read_dir scan stays path-based (audit row #20 carrier-acceptable residual). - `DiskCommitConfig` gains `dest_dir` + `sandbox` so the disk-commit worker thread carries the carrier across the SPSC boundary; both pipeline + sync receiver paths plumb the existing `PipelineSetup::sandbox` into the new fields. - `ResponseContext::sandbox` switches to `Option<&Arc<DirSandbox>>` so the temp-file Drop anchor can clone a stable handle that outlives the borrow; renameat call site updates to `.map(Arc::as_ref)`. Includes a regression test that races a rename + symlink-swap on the temp parent between create and Drop and verifies the unlink lands on the original dirfd (decoy survives, real temp file is removed). Falls back to the existing `OpenOptions::create_new` / `std::fs::remove_file` path when the carrier is absent (non-Unix, --temp-dir routed to a sibling tree, or multi-component temp paths); ENOENT recovery keeps `create_dir_all` as accepted residual.
4 tasks
oferchen
added a commit
that referenced
this pull request
May 22, 2026
#4729) Captures the receiver-side `--delete` wiring follow-up SEC-1.q (PR #4728) intentionally deferred. The merged engine-side work added a sandbox-aware DeleteFs trait surface plus the DeleteEmitter::with_sandbox carrier, but the receiver loop in crates/transfer/src/receiver/directory/deletion.rs still calls std::fs::remove_file / remove_dir_all / read_dir directly. Lays out three options (migrate receiver to DeleteEmitter, swap to fast_io *_via_sandbox_or_fallback helpers, defer behind Landlock) with LoC scope, risk, test cost, and cross-platform plan. Recommends Option B (direct helper swap) on effort-vs-risk grounds and because the SEC-1.r temp_guard / temp_cleanup PR (#4723) is the established precedent for exactly this carrier-threading shape. Closes audit rows #5-#7 in docs/audits/sec-1-path-syscall-audit-2026-05-22.md once the implementation PR lands. Docs-only.
3 of 4 tasks
oferchen
added a commit
that referenced
this pull request
May 22, 2026
…-1.q2) (#4732) * feat(transfer): thread DirSandbox through receiver --delete path (SEC-1.q2) Replace the three unanchored syscalls in delete_extraneous_files with their sandbox-anchored siblings so a TOCTOU symlink swap on a top-level extraneous entry cannot redirect the listing or the unlink to an attacker-chosen inode outside the destination tree. Adds fast_io::read_dir_via_sandbox_or_fallback (mirrors the existing *_via_sandbox_or_fallback shape: openat(O_DIRECTORY | O_NOFOLLOW) + fdopendir for single-component scans, std::fs::read_dir fallback otherwise). Closes audit rows #5, #6, #7 from the SEC-1 path-syscall audit. Mirrors the SEC-1.r temp_guard/temp_cleanup carrier-threading pattern (PR #4723): the Option<Arc<DirSandbox>> is cloned once into the map_blocking worker closure and forwarded to every helper call. Sandbox-off and multi-component paths take the documented identical- behaviour fallback. No transfer-crate unsafe is introduced; all unsafe stays behind the existing fast_io safe wrappers. Windows continues through std::fs::remove_file / remove_dir_all / read_dir (NTFS handle semantics already close the symlink-swap window per the SEC-1.l audit). * fix(engine): use Components::next() walk for plan_directory_to_relative SkipWhile<Components, _> has no as_path() method on stable Rust 1.88; the previous skip_while-then-as_path call introduced in SEC-1.q (#4728) slipped through that PR's CI but breaks fmt+clippy on every subsequent master CI run. Switch to a manual Components::next() walk that consumes the leading Prefix/RootDir/CurDir components, then calls as_path() on the unwrapped Components iterator. * fix(transfer): cfg-gate rel_for_unlink to unix to silence Windows unused-var
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…C-1.r) (#4723) * feat(transfer): thread DirSandbox through temp_guard/temp_cleanup (SEC-1.r) Routes receiver-side temp-file creation and the matching unlink-on-drop through `openat(dirfd, leaf, ...)` / `unlinkat(dirfd, leaf, 0)` instead of path-based syscalls so a TOCTOU symlink swap on the temp parent cannot redirect the create or the cleanup. - `temp_guard::open_tmpfile_sandboxed` dispatches the create through `fast_io::openat_via_sandbox_or_fallback` and seeds the returned `TempFileGuard` with a sandbox anchor for the matching Drop unlink. - `temp_cleanup::cleanup_stale_temp_files_sandboxed` routes the per- entry unlink through `unlink_via_sandbox_or_fallback`; the read_dir scan stays path-based (audit row #20 carrier-acceptable residual). - `DiskCommitConfig` gains `dest_dir` + `sandbox` so the disk-commit worker thread carries the carrier across the SPSC boundary; both pipeline + sync receiver paths plumb the existing `PipelineSetup::sandbox` into the new fields. - `ResponseContext::sandbox` switches to `Option<&Arc<DirSandbox>>` so the temp-file Drop anchor can clone a stable handle that outlives the borrow; renameat call site updates to `.map(Arc::as_ref)`. Includes a regression test that races a rename + symlink-swap on the temp parent between create and Drop and verifies the unlink lands on the original dirfd (decoy survives, real temp file is removed). Falls back to the existing `OpenOptions::create_new` / `std::fs::remove_file` path when the carrier is absent (non-Unix, --temp-dir routed to a sibling tree, or multi-component temp paths); ENOENT recovery keeps `create_dir_all` as accepted residual. * fix(transfer): promote libc dep to cfg(unix) for macOS temp_guard openat flags
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
#4729) Captures the receiver-side `--delete` wiring follow-up SEC-1.q (PR #4728) intentionally deferred. The merged engine-side work added a sandbox-aware DeleteFs trait surface plus the DeleteEmitter::with_sandbox carrier, but the receiver loop in crates/transfer/src/receiver/directory/deletion.rs still calls std::fs::remove_file / remove_dir_all / read_dir directly. Lays out three options (migrate receiver to DeleteEmitter, swap to fast_io *_via_sandbox_or_fallback helpers, defer behind Landlock) with LoC scope, risk, test cost, and cross-platform plan. Recommends Option B (direct helper swap) on effort-vs-risk grounds and because the SEC-1.r temp_guard / temp_cleanup PR (#4723) is the established precedent for exactly this carrier-threading shape. Closes audit rows #5-#7 in docs/audits/sec-1-path-syscall-audit-2026-05-22.md once the implementation PR lands. Docs-only.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…-1.q2) (#4732) * feat(transfer): thread DirSandbox through receiver --delete path (SEC-1.q2) Replace the three unanchored syscalls in delete_extraneous_files with their sandbox-anchored siblings so a TOCTOU symlink swap on a top-level extraneous entry cannot redirect the listing or the unlink to an attacker-chosen inode outside the destination tree. Adds fast_io::read_dir_via_sandbox_or_fallback (mirrors the existing *_via_sandbox_or_fallback shape: openat(O_DIRECTORY | O_NOFOLLOW) + fdopendir for single-component scans, std::fs::read_dir fallback otherwise). Closes audit rows #5, #6, #7 from the SEC-1 path-syscall audit. Mirrors the SEC-1.r temp_guard/temp_cleanup carrier-threading pattern (PR #4723): the Option<Arc<DirSandbox>> is cloned once into the map_blocking worker closure and forwarded to every helper call. Sandbox-off and multi-component paths take the documented identical- behaviour fallback. No transfer-crate unsafe is introduced; all unsafe stays behind the existing fast_io safe wrappers. Windows continues through std::fs::remove_file / remove_dir_all / read_dir (NTFS handle semantics already close the symlink-swap window per the SEC-1.l audit). * fix(engine): use Components::next() walk for plan_directory_to_relative SkipWhile<Components, _> has no as_path() method on stable Rust 1.88; the previous skip_while-then-as_path call introduced in SEC-1.q (#4728) slipped through that PR's CI but breaks fmt+clippy on every subsequent master CI run. Switch to a manual Components::next() walk that consumes the leading Prefix/RootDir/CurDir components, then calls as_path() on the unwrapped Components iterator. * fix(transfer): cfg-gate rel_for_unlink to unix to silence Windows unused-var
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
Closes 4 of the 5 SEC-1 GAP sites flagged in
docs/audits/sec-1-path-syscall-audit-2026-05-22.mdrows #17-#21 bythreading the existing
DirSandboxcarrier into the receiver-sidetemp-file lifecycle. Implements the plan in
docs/design/sec-1-r-temp-file-sandbox-2026-05-22.md. The 5th site(row #20,
fs::read_dirorphan scan) stays path-based as an audit-acknowledged carrier-acceptable residual; see Deferred section below.
GAP closures
temp_guard.rs:130OpenOptions::create_newopenat_via_sandbox_or_fallback(dirfd, leaf, O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW, 0o600)temp_guard.rs:142create_dir_allrecoverytemp_guard.rs:217Dropremove_fileunlink_via_sandbox_or_fallback(dirfd, leaf, File)via newSandboxAnchorfield onTempFileGuardtemp_cleanup.rs:95read_dirorphan scanfdopendirequivalent instd; scan is read-only / informational)temp_cleanup.rs:137remove_fileorphan cleanupunlink_via_sandbox_or_fallback(dirfd, leaf, File)via newcleanup_stale_temp_files_sandboxedReceiver wiring (matches the established SEC-1.j pattern from #4697)
transfer_ops::ResponseContextalready carriedsandbox+dest_dir; this PRflips the field type from
Option<&DirSandbox>toOption<&Arc<DirSandbox>>so the temp-file Drop anchor can clone a stable handle that outlives the
borrow. The synchronous
process_file_responsepath calls the newopen_tmpfile_sandboxed; the existing renameat call site adapts via.map(Arc::as_ref).DiskCommitConfiggainsdest_dir: Option<PathBuf>andsandbox: Option<Arc<DirSandbox>>so the cross-thread disk-commit workercarries the carrier into
process::open_output_file's temp-file branch.receiver/transfer/sync.rsloop reuses the existingsetup.sandboxto callopen_tmpfile_sandboxeddirectly.Test plan
cargo fmt --allcleansandbox_anchored_guard_resists_symlink_swap_on_parent-races a
rename + symlinkswap on the temp parent between create and Dropand verifies the unlinkat lands on the original dirfd (decoy survives,
attacker-owned files untouched, real temp file removed from the renamed
directory)
open_tmpfile_sandboxedhappy path +--temp-dirfallback path +
cleanup_stale_temp_files_sandboxedhappy path + sandbox-absent fallback
Cross-platform
openat_via_sandbox_or_fallbackhelper.TempFileGuard::anchorandopen_tmpfile_sandboxedare#[cfg(unix)]; the publicopen_tmpfilepath on Windows is unchanged.Per SEC-1.l, Windows uses
CreateFileWhandle semantics (already infast_io) instead of dirfd-based*atcalls.--temp-dirand multi-component paths: keep the path-based fallbackbecause the single-component-leaf check fails. ENOENT recovery keeps
create_dir_allas accepted residual (audit row Add streaming negotiation prologue detector #18).Deferred (intentionally)
fs::read_dirorphan scan intemp_cleanup): closingthis would require a
read_dir_via_sandbox_or_fallbackhelper built onopenat(O_DIRECTORY) + fdopendir. The design lists this as optional,same PR window; per the audit it is read-only / informational, the
destructive op is the per-entry unlink which row Add byte-based legacy daemon message parser #21 closes. Follow-up
is tracked as a separate audit item if the residual is ever upgraded.
SECURITY.md: design does not call for an update for SEC-1.r; theopen SEC-1 follow-up entry already covers rows Add negotiation prologue detection helper #17-Add byte-based legacy daemon message parser #21. Leaving
SECURITY.mduntouched per the design.References
docs/design/sec-1-r-temp-file-sandbox-2026-05-22.mddocs/audits/sec-1-path-syscall-audit-2026-05-22.mdrows Add negotiation prologue detection helper #17-Add byte-based legacy daemon message parser #21openat_via_sandbox_or_fallback(feat(fast_io): add openat_via_sandbox_or_fallback + readlinkat_via_sandbox helpers (closes 16+ SEC-1 GAPs) #4716)