Repository navigation
Conversation
…EC-1.q) Extend DeleteFs with unix-only `*_at` siblings (unlink_file_at, rmdir_at, unlink_symlink_at, unlink_device_at, unlink_special_at, remove_dir_all_at) that take a parent dirfd + single-component leaf and route through fast_io::unlinkat / fast_io::recursive_unlinkat (SEC-1.s). Path-based methods stay as the no-sandbox / Windows fallback so existing callers keep working unchanged. Closes the six GAP sites in crates/engine/src/delete/emitter/fs.rs from PR #4710 audit section 4 (#22-#27) by giving RealDeleteFs a dirfd- anchored dispatch shape. Adds DeleteEmitter::with_sandbox carrier slot that opens a per-plan dirfd via DirSandbox::root_dirfd just before dispatch so a mid-syscall symlink swap on the parent walk cannot redirect the call. Plan-directory open failure transparently falls back to the path-based methods so the drain stays compatible. RecordingDeleteFs and ScriptedDeleteFs implement `*_at` by discarding parent_fd and recording the leaf name so every emitter unit test keeps working without sandbox plumbing. New sandbox.rs test module exercises each `*_at` variant against a live tempdir, the recursive peel's symlink-swap resistance, and the sandbox-off / missing-plan-directory fallback paths. Promotes recursive_unlinkat(parent_dirfd, leaf) from a SEC-1.s internal helper to a pub entry point so engine can use it directly without synthesising absolute-path arguments. Receiver-deletion integration in crates/transfer/ deferred to a follow-up per design doc; the receiver loop does not yet route through DeleteEmitter.
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
SEC-1.q closes the six GAP sites in
crates/engine/src/delete/emitter/fs.rsthat PR #4710's path-syscall audit flagged as remaining sandbox holes in
the
--deletesyscall surface. Extends theDeleteFstrait withunix-only
*_atsiblings that take a parent dirfd plus asingle-component leaf, wires a
DirSandboxcarrier slot throughDeleteEmitter, and routes the dirfd-anchored siblings throughfast_io::unlinkat(SEC-1.g) andfast_io::recursive_unlinkat(SEC-1.s).
Design reference
docs/design/sec-1-q-delete-emitter-sandbox-2026-05-22.mddocs/audits/sec-1-path-syscall-audit-2026-05-22.mdsection 4 rows Split protocol negotiation into focused modules #22-Add coverage for legacy AUTHREQD parser edge cases #27, section 6 "DeleteFs trait" row.
Six GAP sites closed
unlink_fileunlink_file_at->unlinkat(parent_fd, name, 0)rmdirrmdir_at->unlinkat(parent_fd, name, AT_REMOVEDIR)unlink_symlinkunlink_symlink_at->unlinkat(parent_fd, name, 0)unlink_deviceunlink_device_at->unlinkat(parent_fd, name, 0)unlink_specialunlink_special_at->unlinkat(parent_fd, name, 0)remove_dir_allremove_dir_all_at->fast_io::recursive_unlinkat(parent_fd, name)Implementation shape
*_atsiblings are additive next to the existingpath-based methods, so every existing caller stays on the legacy
fallback. Path-based methods are documented as the no-sandbox /
Windows route; the
*_atsiblings carry the security-relevantTOCTOU-closing dispatch shape.
RealDeleteFs: each*_atbody is a one-line delegation to thecorresponding
fast_iohelper.RecordingDeleteFs/ScriptedDeleteFs:*_atimpls discardparent_fdand record the leaf name. Every existing emitter unittest passes unchanged because the recorded sequence asserts paths
that the dispatcher reconstructs from
plan.directory.join(name).DeleteEmitter::with_sandbox(new): attaches anArc<DirSandbox>.drain_planopens a per-plan dirfd againstsandbox.root_dirfd()just before dispatch; on open failure (already-removed parent during
an in-flight recursive drain) the dispatcher transparently falls
back to the path-based methods.
fast_io::recursive_unlinkat: SEC-1.s's internal helper promotedto
pubso the engine can drive the recursive peel directly off adirfd it already holds.
Deferred receiver-deletion integration
The receiver-deletion call sites in
crates/transfer/(PR #4710 rows#5-#7) are not wired in this PR. The receiver's delete traversal
does not yet route through
DeleteEmitter; it issues its own per-entryunlink/rmdir loop in
crates/transfer/src/receiver/directory/.Threading the sandbox through that loop is a separate refactor and
ships as a follow-up. The design doc has been updated with this
deferred-follow-up note.
Until that follow-up lands,
DeleteEmitter::with_sandboxis exercisedby unit tests and any caller that builds the emitter directly. The
path-based fallback remains the production path for the live receiver
loop, so this is a net-positive defense-in-depth change with zero
behavioural regression.
Base branch
This PR targets
feat/sec-1-s-recursive-unlinkat-helper-impl(PR#4726, OPEN), not master. SEC-1.q depends on the SEC-1.s
recursive_unlinkathelper landing first.Test plan
sandbox.rsmodule exercises every*_atvariant against a live tempdirvia the legacy
dispatch/dispatch_dirshape*_atdispatch shape compilesagainst
std::os::fd::BorrowedFdandlibcO_DIRECTORY | O_NOFOLLOW | O_CLOEXECFiles changed
crates/engine/src/delete/emitter/fs.rs- trait extension, blanketimpl,
RealDeleteFs*_atwiring,RecordingDeleteFs*_atrecording shim.
crates/engine/src/delete/emitter/mod.rs-DeleteEmittersandboxcarrier slot,
with_sandboxbuilder, sandbox-awaredispatch/dispatch_dir/drain_plan, per-planopenathelper.crates/engine/src/delete/emitter/tests/mod.rs-ScriptedDeleteFs*_atfailure-script forwarding.crates/engine/src/delete/emitter/tests/sandbox.rs- new SEC-1.qsandbox dispatch test module.
crates/fast_io/src/dir_sandbox/at_syscalls.rs- promoterecursive_unlinkat(parent_dirfd, leaf)topub.crates/fast_io/src/dir_sandbox/mod.rs- re-exportrecursive_unlinkat.crates/fast_io/src/lib.rs- re-exportrecursive_unlinkatat thecrate root.
docs/design/sec-1-q-delete-emitter-sandbox-2026-05-22.md-document the deferred receiver-deletion follow-up.