Skip to content

feat(fast_io,transfer): replace remove_file/remove_dir with unlinkat (SEC-1.g) - #4671

Merged
oferchen merged 2 commits into
masterfrom
feat/sec-1-g-unlinkat-migration
May 21, 2026
Merged

oferchen merged 2 commits into
masterfrom
feat/sec-1-g-unlinkat-migration

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Add fast_io::unlinkat + UnlinkFlags as the SEC-1.g primitive (single SAFETY block in fast_io; consumer crates take a safe wrapper) and a DirSandbox::unlinkat_at convenience method, mirroring SEC-1.f's fstatat_nofollow / lstat_at pattern.
  • Migrate the three receiver-side obstacle-remove sites in crates/transfer/src/receiver/directory/links.rs (rows links.rs:84/:86/:251 in docs/audits/sec-1-a-path-syscall-surface-2026-05-20.md) to route through fast_io::unlink_via_sandbox_or_fallback when the SEC-1.e DirSandbox carrier is plumbed, falling back to path-based remove_file otherwise.
  • Closes the unlink-class slice of the TOCTOU window: unlinkat(2) is anchored on the receiver-owned dirfd and is hard-coded to never follow a terminal symlink, so a swap on the leaf cannot redirect the syscall to an attacker-chosen parent and cannot chase the swapped symlink to a sensitive sibling.

Audit cite

The SEC-1.a audit (docs/audits/sec-1-a-path-syscall-surface-2026-05-20.md) enumerates 14 unlinkat(parent_fd, leaf, 0) and unlinkat(parent_fd, leaf, AT_REMOVEDIR) cutover rows across engine and transfer. This PR migrates the three receiver-pipeline rows that already have the SEC-1.e sandbox carrier wired:

audit row site this PR
links.rs:84 create_symlinks stale-symlink-replace migrated
links.rs:86 create_symlinks non-symlink obstacle remove migrated
links.rs:251 create_hardlinks existing-file remove before linkat migrated (Unix only; Windows keeps fs::remove_file per the SEC-1.l NTFS-handle audit)

Deferred to SEC-1.g.followup

Mirrors SEC-1.f's deferral pattern: any site that needs additional plumbing beyond the existing SEC-1.e carrier stays out of scope.

  • crates/transfer/src/receiver/directory/deletion.rs:157,159 (delete_extraneous_files). Runs in parallel_io::map_blocking worker closures over arbitrary subdirectories. The sandbox's current_dirfd reflects the receiver's in-tree descent on the main thread; workers each operate against a different dest_dir.join(dir_rel) and need either per-worker secondary dirfds (DirSandbox::secondary) or a descent-stack copy per worker.
  • crates/transfer/src/temp_guard.rs:217 (TempGuard RAII cleanup). Needs a TempGuard extension to carry a sandbox reference.
  • All engine-side rows (engine/src/delete/emitter/fs.rs, engine/src/local_copy/context_impl/state.rs:471,526,635, engine/src/local_copy/context_impl/reporting.rs:168,175, engine/src/local_copy/executor/file/guard.rs:32,50,155,351,426,469, engine/src/local_copy/executor/file/partial.rs:217, engine/src/local_copy/executor/file/copy/transfer/execute/clonefile.rs:111,115, engine/src/local_copy/executor/sources/orchestration.rs:390, engine/src/local_copy/executor/directory/recursive/deletion.rs:64, engine/src/local_copy/hard_links/cohort.rs:90,156). These need a CopyContext extension to carry a sandbox reference; the plumbing is sequenced as SEC-1.g.followup to keep this PR scoped to the receiver pipeline.
  • fs::remove_dir_all sites stay path-based; they need the hand-rolled openat peel called out in audit section 4 (item 2). That is a separate task.

Constraints honoured

  • No unsafe outside fast_io (deny gate intact on transfer).
  • No #[allow(...)] waivers added; the single SAFETY block lives in fast_io::dir_sandbox::at_syscalls.
  • No new workspace dependencies.
  • Cross-platform compile preserved: unlink_via_sandbox_or_fallback and UnlinkFlags are #[cfg(unix)]; Windows create_hardlinks keeps fs::remove_file.

Test plan

  • cargo nextest run -p fast_io --all-features -E 'test(unlinkat) + test(unlink_via_sandbox)' (5 new unlinkat_* + 4 new unlink_via_sandbox_* tests, plus the SEC-1.f siblings remain green)
  • cargo nextest run -p transfer --test unlinkat_swap_resistance (4 new integration tests, including the symlink-swap attack scenario)
  • cargo nextest run -p transfer --all-features -E 'test(create_hardlinks) + test(create_symlinks)' (existing receiver tests stay green through the cfg-aware call_create_hardlinks shim)
  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings
  • Full CI matrix: fmt+clippy, nextest (stable), Windows, macOS, Linux musl

@github-actions github-actions Bot added the enhancement New feature or request label May 21, 2026
…(SEC-1.g)

Add `fast_io::unlinkat` as the SEC-1.g primitive and wire the
receiver-side symlink and hardlink obstacle removes through it when
the SEC-1.e `DirSandbox` carrier is available, falling back to
path-based `remove_file` otherwise.

Closes the unlink-class slice of the TOCTOU window cited in the
SEC-1.a audit (docs/audits/sec-1-a-path-syscall-surface-2026-05-20.md
rows links.rs:84/:86/:251): a symlink swap on a single-component
receiver-owned leaf can no longer redirect the obstacle remove to an
attacker-chosen parent, because the syscall is anchored on the dirfd
opened at receiver setup rather than re-walking the path through the
kernel. `unlinkat(2)` is also hard-coded to never follow a terminal
symlink, so even when the attacker swaps the leaf itself for a
symlink at the swap moment the kernel removes the symlink itself
rather than the chase target.

* `crates/fast_io/src/dir_sandbox/at_syscalls.rs`:
  - New `pub fn unlinkat(dirfd, name, flags)` wraps
    `libc::unlinkat`. Single SAFETY block with the FFI cite and the
    invariants upheld (dirfd lifetime, NUL-terminated name, the only
    two valid raw flag values).
  - New `pub enum UnlinkFlags { File, Dir }` selects between
    `unlinkat(_, _, 0)` and `unlinkat(_, _, AT_REMOVEDIR)`. Encoding
    the choice as an enum keeps call sites self-documenting; the
    discriminator-to-raw-flag mapping lives in a private
    `as_raw` method so the surface cannot leak invalid bitflags.
  - New `pub fn unlink_via_sandbox_or_fallback` adaptor for callers
    that hold an absolute path. Mirrors
    `lstat_via_sandbox_or_fallback` shape exactly: routes through
    the sandbox dirfd on single-component paths and falls back to
    `std::fs::remove_file` / `std::fs::remove_dir` otherwise.

* `crates/fast_io/src/dir_sandbox/mod.rs`:
  - New `DirSandbox::unlinkat_at(leaf, flags)` convenience method
    mirroring `lstat_at`. Resolves against the current dirfd stack
    top.
  - Re-export `UnlinkFlags`, `unlinkat`,
    `unlink_via_sandbox_or_fallback` from the module surface.

* `crates/fast_io/src/lib.rs`:
  - Re-export the three new public items behind the existing
    `#[cfg(unix)]` `dir_sandbox` umbrella.

* `crates/transfer/src/receiver/directory/links.rs`:
  - Three receiver-side unlink call sites now route through
    `fast_io::unlink_via_sandbox_or_fallback` when the sandbox is
    plumbed (single-component paths) and fall back to
    `std::fs::remove_file` otherwise:
    - `create_symlinks` stale-symlink-replace (line 85 pre-edit).
    - `create_symlinks` non-symlink obstacle remove (line 99
      pre-edit).
    - `create_hardlinks` existing-file remove before `linkat`
      (line 282 pre-edit). Cfg-gated `#[cfg(unix)]` /
      `#[cfg(not(unix))]` because the helper is Unix-only; Windows
      stays on the path-based `remove_file` per the SEC-1.l
      NTFS-handle audit.

Deferred to SEC-1.g.followup (mirroring SEC-1.f's deferral pattern):

* `crates/transfer/src/receiver/directory/deletion.rs` (lines 157,
  159). `delete_extraneous_files` runs in `parallel_io::map_blocking`
  worker closures over arbitrary subdirectories of the destination
  tree. The sandbox's `current_dirfd` reflects the receiver's
  in-tree descent on the main thread; the deletion workers each
  operate against a different `dest_path = dest_dir.join(dir_rel)`,
  so they need either (a) per-worker secondary dirfds via
  `DirSandbox::secondary`, or (b) a descent-stack copy per worker.
  Both are SEC-1.g.followup work. The current site stays on
  path-based `remove_file` / `remove_dir_all` until then.

* Engine-side sites enumerated in the SEC-1.a audit
  (`engine/src/delete/emitter/fs.rs`, `engine/src/local_copy/...`,
  `crates/transfer/src/temp_guard.rs:217`). These need
  `CopyContext` / `TempGuard` extensions to carry a sandbox
  reference; that plumbing is sequenced as SEC-1.g.followup so this
  PR stays scoped to the receiver-pipeline sites that already have
  the SEC-1.e carrier wired.

Constraints honoured:
* No `unsafe` outside `fast_io` (deny gate intact on `transfer`).
* No `#[allow(...)]` waivers (the single SAFETY block already lives
  inside `fast_io::dir_sandbox::at_syscalls`).
* No new workspace dependencies.
* Cross-platform compile preserved: `unlink_via_sandbox_or_fallback`
  and `UnlinkFlags` are `#[cfg(unix)]` via the dir_sandbox umbrella;
  Windows-side `create_hardlinks` keeps `fs::remove_file`.

Tests:
* `fast_io::dir_sandbox::at_syscalls::tests`:
  - `unlinkat_removes_regular_file`
  - `unlinkat_removes_empty_dir_with_at_removedir`
  - `unlinkat_returns_eperm_or_eisdir_on_dir_without_at_removedir`
  - `unlinkat_returns_enotempty_on_non_empty_dir_with_at_removedir`
  - `unlinkat_rejects_symlink_traversal` (pins the SEC-1 TOCTOU
    invariant: `unlinkat(File)` removes the symlink itself even when
    the leaf points at a sensitive sibling outside the sandbox)
  - `unlinkat_reports_enoent_for_missing_leaf`
  - Four `unlink_via_sandbox_or_fallback` cases covering single-
    component file/dir vs multi-component vs absent-sandbox
    dispatch.
* `crates/transfer/tests/unlinkat_swap_resistance.rs` adds the
  end-to-end integration test exercising the receiver-shaped swap
  attack: an attacker pre-swaps `dest/target/` for a symlink to
  `../sensitive/`, the helper unlinks via the sandbox dirfd, and
  the test asserts the symlink itself is removed while the
  sensitive tree outside the sandbox survives. Plus three sibling
  tests pinning the leaf-file unlink, the `Dir` non-empty refusal,
  and the multi-component path fallback shape.
@oferchen
oferchen force-pushed the feat/sec-1-g-unlinkat-migration branch from e80dca9 to 54d7c9f Compare May 21, 2026 13:48
cargo fmt --all - one file affected (at_syscalls.rs).
oferchen added a commit that referenced this pull request May 21, 2026
…EC-1.o-partial) (#4672)

Reflect SEC-1.f (PR #4668, merged) and SEC-1.g (PR #4671, in CI):

- Flip CVE-2026-29518 and CVE-2026-43619 status from APPLICABLE
  to Mitigations in progress.
- Add a SEC-1 progress subsection listing shipped (lstat via
  fstatat AT_SYMLINK_NOFOLLOW, remove via unlinkat, both through
  DirSandbox for sandbox-plumbed call sites) and still-pending
  work (SEC-1.h/i/j *at siblings, CopyContext dirfd extension,
  per-worker dirfds for --delete consumer, SEC-1.m/n regression
  tests).
- Cite SEC-1 umbrella issue #2516 as tracking.
- Record SEC-1.l audit conclusion that Windows uses NTFS handle-
  based APIs and is not affected by either CVE.

Partial update; the final Fixed promotion stays gated on SEC-1.h/i/j
landing and SEC-1.m/n regression tests passing.
@oferchen
oferchen merged commit 7ab1d1f into master May 21, 2026
55 checks passed
@oferchen
oferchen deleted the feat/sec-1-g-unlinkat-migration branch May 21, 2026 14:52
oferchen added a commit that referenced this pull request May 21, 2026
Add a consolidated end-to-end attack harness that ties the SEC-1.f
(lstat-class) and SEC-1.g (unlink-class) primitives together at the
receiver-pipeline integration level. The two existing per-primitive
test files cover the helpers on quiescent trees; this harness pins
the documented SEC-1 TOCTOU invariant against an active attacker
thread that races the receiver.

Three scenarios:

1. Lstat-class invariant under live race: attacker swaps the
   destination leaf for a symlink pointing into a sibling sensitive
   tree between the receiver's decide-to-stat moment and the
   sandbox-anchored lstat. The helper must report the leaf itself
   (file or symlink), never the dereferenced target outside the
   sandbox.

2. Unlink-class invariant under live race: attacker swaps a
   hardlink follower for a symlink to the leader between the
   receiver's decide-to-delete moment and the sandbox-anchored
   unlinkat. The leader must survive every interleaving; a
   path-based remove_file would have deleted the leader through
   the swapped symlink (the exact regression SEC-1.g prevents).

3. Tight race-window stress: 64 iterations of swap-vs-stat-vs-unlink
   with deterministic crossbeam-channel handshakes (not sleep-based,
   per the concurrent-dispatch flake learning). The sensitive tree
   must remain byte-identical across every iteration regardless of
   who wins each race.

Dependencies / sequencing:

- Consumes the SEC-1.g API surface (fast_io::UnlinkFlags,
  fast_io::unlink_via_sandbox_or_fallback) added in #4671. CI
  failures before #4671 merges are expected; rebase after merge.
- No unsafe outside fast_io, no allow waivers, no new workspace
  deps (crossbeam-channel and tempfile are already dev-deps).
- Gated #[cfg(unix)] since DirSandbox is Unix-only.
oferchen added a commit that referenced this pull request May 21, 2026
Add a consolidated end-to-end attack harness that ties the SEC-1.f
(lstat-class) and SEC-1.g (unlink-class) primitives together at the
receiver-pipeline integration level. The two existing per-primitive
test files cover the helpers on quiescent trees; this harness pins
the documented SEC-1 TOCTOU invariant against an active attacker
thread that races the receiver.

Three scenarios:

1. Lstat-class invariant under live race: attacker swaps the
   destination leaf for a symlink pointing into a sibling sensitive
   tree between the receiver's decide-to-stat moment and the
   sandbox-anchored lstat. The helper must report the leaf itself
   (file or symlink), never the dereferenced target outside the
   sandbox.

2. Unlink-class invariant under live race: attacker swaps a
   hardlink follower for a symlink to the leader between the
   receiver's decide-to-delete moment and the sandbox-anchored
   unlinkat. The leader must survive every interleaving; a
   path-based remove_file would have deleted the leader through
   the swapped symlink (the exact regression SEC-1.g prevents).

3. Tight race-window stress: 64 iterations of swap-vs-stat-vs-unlink
   with deterministic crossbeam-channel handshakes (not sleep-based,
   per the concurrent-dispatch flake learning). The sensitive tree
   must remain byte-identical across every iteration regardless of
   who wins each race.

Dependencies / sequencing:

- Consumes the SEC-1.g API surface (fast_io::UnlinkFlags,
  fast_io::unlink_via_sandbox_or_fallback) added in #4671. CI
  failures before #4671 merges are expected; rebase after merge.
- No unsafe outside fast_io, no allow waivers, no new workspace
  deps (crossbeam-channel and tempfile are already dev-deps).
- Gated #[cfg(unix)] since DirSandbox is Unix-only.
oferchen added a commit that referenced this pull request May 21, 2026
#4675)

Add a consolidated end-to-end attack harness that ties the SEC-1.f
(lstat-class) and SEC-1.g (unlink-class) primitives together at the
receiver-pipeline integration level. The two existing per-primitive
test files cover the helpers on quiescent trees; this harness pins
the documented SEC-1 TOCTOU invariant against an active attacker
thread that races the receiver.

Three scenarios:

1. Lstat-class invariant under live race: attacker swaps the
   destination leaf for a symlink pointing into a sibling sensitive
   tree between the receiver's decide-to-stat moment and the
   sandbox-anchored lstat. The helper must report the leaf itself
   (file or symlink), never the dereferenced target outside the
   sandbox.

2. Unlink-class invariant under live race: attacker swaps a
   hardlink follower for a symlink to the leader between the
   receiver's decide-to-delete moment and the sandbox-anchored
   unlinkat. The leader must survive every interleaving; a
   path-based remove_file would have deleted the leader through
   the swapped symlink (the exact regression SEC-1.g prevents).

3. Tight race-window stress: 64 iterations of swap-vs-stat-vs-unlink
   with deterministic crossbeam-channel handshakes (not sleep-based,
   per the concurrent-dispatch flake learning). The sensitive tree
   must remain byte-identical across every iteration regardless of
   who wins each race.

Dependencies / sequencing:

- Consumes the SEC-1.g API surface (fast_io::UnlinkFlags,
  fast_io::unlink_via_sandbox_or_fallback) added in #4671. CI
  failures before #4671 merges are expected; rebase after merge.
- No unsafe outside fast_io, no allow waivers, no new workspace
  deps (crossbeam-channel and tempfile are already dev-deps).
- Gated #[cfg(unix)] since DirSandbox is Unix-only.
oferchen added a commit that referenced this pull request May 21, 2026
)

Adds the create-class siblings to the SEC-1 dirfd carrier:
mkdirat / symlinkat / linkat and the via_sandbox_or_fallback
adaptors that route a single-component leaf under the receiver's
DirSandbox root through the *at variant while preserving the
existing path-based fallback for multi-component paths, missing
sandbox, and non-Unix targets.

Wires the receiver pipeline:
- create_symlinks now creates symlinks through
  symlinkat_via_sandbox_or_fallback.
- create_hardlinks creates follower hard links through
  linkat_via_sandbox_or_fallback, keeping fast_io::hard_link
  (io_uring LINKAT fast path) as the fallback so EXDEV/EPERM
  semantics survive.
- create_directories and create_directory_incremental create
  new directories through mkdirat_via_sandbox_or_fallback, with
  fs::create_dir_all retained as the multi-component fallback.

Follows the SEC-1.g pattern (PR #4671). mknodat is deferred:
device/FIFO/socket creation is wrapped by the metadata crate and
needs deeper refactoring before the sandbox can be threaded
through; receiver-side mknod is not on the daemon-reachable
TOCTOU surface today.

Windows stays on path-based stdlib per the SEC-1.l NTFS-handle
audit.
oferchen added a commit that referenced this pull request Aug 24, 2026
…EC-1.o-partial) (#4672)

Reflect SEC-1.f (PR #4668, merged) and SEC-1.g (PR #4671, in CI):

- Flip CVE-2026-29518 and CVE-2026-43619 status from APPLICABLE
  to Mitigations in progress.
- Add a SEC-1 progress subsection listing shipped (lstat via
  fstatat AT_SYMLINK_NOFOLLOW, remove via unlinkat, both through
  DirSandbox for sandbox-plumbed call sites) and still-pending
  work (SEC-1.h/i/j *at siblings, CopyContext dirfd extension,
  per-worker dirfds for --delete consumer, SEC-1.m/n regression
  tests).
- Cite SEC-1 umbrella issue #2516 as tracking.
- Record SEC-1.l audit conclusion that Windows uses NTFS handle-
  based APIs and is not affected by either CVE.

Partial update; the final Fixed promotion stays gated on SEC-1.h/i/j
landing and SEC-1.m/n regression tests passing.
oferchen added a commit that referenced this pull request Aug 24, 2026
…(SEC-1.g) (#4671)

* feat(fast_io,transfer): replace remove_file/remove_dir with unlinkat (SEC-1.g)

Add `fast_io::unlinkat` as the SEC-1.g primitive and wire the
receiver-side symlink and hardlink obstacle removes through it when
the SEC-1.e `DirSandbox` carrier is available, falling back to
path-based `remove_file` otherwise.

Closes the unlink-class slice of the TOCTOU window cited in the
SEC-1.a audit (docs/audits/sec-1-a-path-syscall-surface-2026-05-20.md
rows links.rs:84/:86/:251): a symlink swap on a single-component
receiver-owned leaf can no longer redirect the obstacle remove to an
attacker-chosen parent, because the syscall is anchored on the dirfd
opened at receiver setup rather than re-walking the path through the
kernel. `unlinkat(2)` is also hard-coded to never follow a terminal
symlink, so even when the attacker swaps the leaf itself for a
symlink at the swap moment the kernel removes the symlink itself
rather than the chase target.

* `crates/fast_io/src/dir_sandbox/at_syscalls.rs`:
  - New `pub fn unlinkat(dirfd, name, flags)` wraps
    `libc::unlinkat`. Single SAFETY block with the FFI cite and the
    invariants upheld (dirfd lifetime, NUL-terminated name, the only
    two valid raw flag values).
  - New `pub enum UnlinkFlags { File, Dir }` selects between
    `unlinkat(_, _, 0)` and `unlinkat(_, _, AT_REMOVEDIR)`. Encoding
    the choice as an enum keeps call sites self-documenting; the
    discriminator-to-raw-flag mapping lives in a private
    `as_raw` method so the surface cannot leak invalid bitflags.
  - New `pub fn unlink_via_sandbox_or_fallback` adaptor for callers
    that hold an absolute path. Mirrors
    `lstat_via_sandbox_or_fallback` shape exactly: routes through
    the sandbox dirfd on single-component paths and falls back to
    `std::fs::remove_file` / `std::fs::remove_dir` otherwise.

* `crates/fast_io/src/dir_sandbox/mod.rs`:
  - New `DirSandbox::unlinkat_at(leaf, flags)` convenience method
    mirroring `lstat_at`. Resolves against the current dirfd stack
    top.
  - Re-export `UnlinkFlags`, `unlinkat`,
    `unlink_via_sandbox_or_fallback` from the module surface.

* `crates/fast_io/src/lib.rs`:
  - Re-export the three new public items behind the existing
    `#[cfg(unix)]` `dir_sandbox` umbrella.

* `crates/transfer/src/receiver/directory/links.rs`:
  - Three receiver-side unlink call sites now route through
    `fast_io::unlink_via_sandbox_or_fallback` when the sandbox is
    plumbed (single-component paths) and fall back to
    `std::fs::remove_file` otherwise:
    - `create_symlinks` stale-symlink-replace (line 85 pre-edit).
    - `create_symlinks` non-symlink obstacle remove (line 99
      pre-edit).
    - `create_hardlinks` existing-file remove before `linkat`
      (line 282 pre-edit). Cfg-gated `#[cfg(unix)]` /
      `#[cfg(not(unix))]` because the helper is Unix-only; Windows
      stays on the path-based `remove_file` per the SEC-1.l
      NTFS-handle audit.

Deferred to SEC-1.g.followup (mirroring SEC-1.f's deferral pattern):

* `crates/transfer/src/receiver/directory/deletion.rs` (lines 157,
  159). `delete_extraneous_files` runs in `parallel_io::map_blocking`
  worker closures over arbitrary subdirectories of the destination
  tree. The sandbox's `current_dirfd` reflects the receiver's
  in-tree descent on the main thread; the deletion workers each
  operate against a different `dest_path = dest_dir.join(dir_rel)`,
  so they need either (a) per-worker secondary dirfds via
  `DirSandbox::secondary`, or (b) a descent-stack copy per worker.
  Both are SEC-1.g.followup work. The current site stays on
  path-based `remove_file` / `remove_dir_all` until then.

* Engine-side sites enumerated in the SEC-1.a audit
  (`engine/src/delete/emitter/fs.rs`, `engine/src/local_copy/...`,
  `crates/transfer/src/temp_guard.rs:217`). These need
  `CopyContext` / `TempGuard` extensions to carry a sandbox
  reference; that plumbing is sequenced as SEC-1.g.followup so this
  PR stays scoped to the receiver-pipeline sites that already have
  the SEC-1.e carrier wired.

Constraints honoured:
* No `unsafe` outside `fast_io` (deny gate intact on `transfer`).
* No `#[allow(...)]` waivers (the single SAFETY block already lives
  inside `fast_io::dir_sandbox::at_syscalls`).
* No new workspace dependencies.
* Cross-platform compile preserved: `unlink_via_sandbox_or_fallback`
  and `UnlinkFlags` are `#[cfg(unix)]` via the dir_sandbox umbrella;
  Windows-side `create_hardlinks` keeps `fs::remove_file`.

Tests:
* `fast_io::dir_sandbox::at_syscalls::tests`:
  - `unlinkat_removes_regular_file`
  - `unlinkat_removes_empty_dir_with_at_removedir`
  - `unlinkat_returns_eperm_or_eisdir_on_dir_without_at_removedir`
  - `unlinkat_returns_enotempty_on_non_empty_dir_with_at_removedir`
  - `unlinkat_rejects_symlink_traversal` (pins the SEC-1 TOCTOU
    invariant: `unlinkat(File)` removes the symlink itself even when
    the leaf points at a sensitive sibling outside the sandbox)
  - `unlinkat_reports_enoent_for_missing_leaf`
  - Four `unlink_via_sandbox_or_fallback` cases covering single-
    component file/dir vs multi-component vs absent-sandbox
    dispatch.
* `crates/transfer/tests/unlinkat_swap_resistance.rs` adds the
  end-to-end integration test exercising the receiver-shaped swap
  attack: an attacker pre-swaps `dest/target/` for a symlink to
  `../sensitive/`, the helper unlinks via the sandbox dirfd, and
  the test asserts the symlink itself is removed while the
  sensitive tree outside the sandbox survives. Plus three sibling
  tests pinning the leaf-file unlink, the `Dir` non-empty refusal,
  and the multi-component path fallback shape.

* style(fast_io): apply rustfmt to SEC-1.g unlinkat primitive

cargo fmt --all - one file affected (at_syscalls.rs).
oferchen added a commit that referenced this pull request Aug 24, 2026
#4675)

Add a consolidated end-to-end attack harness that ties the SEC-1.f
(lstat-class) and SEC-1.g (unlink-class) primitives together at the
receiver-pipeline integration level. The two existing per-primitive
test files cover the helpers on quiescent trees; this harness pins
the documented SEC-1 TOCTOU invariant against an active attacker
thread that races the receiver.

Three scenarios:

1. Lstat-class invariant under live race: attacker swaps the
   destination leaf for a symlink pointing into a sibling sensitive
   tree between the receiver's decide-to-stat moment and the
   sandbox-anchored lstat. The helper must report the leaf itself
   (file or symlink), never the dereferenced target outside the
   sandbox.

2. Unlink-class invariant under live race: attacker swaps a
   hardlink follower for a symlink to the leader between the
   receiver's decide-to-delete moment and the sandbox-anchored
   unlinkat. The leader must survive every interleaving; a
   path-based remove_file would have deleted the leader through
   the swapped symlink (the exact regression SEC-1.g prevents).

3. Tight race-window stress: 64 iterations of swap-vs-stat-vs-unlink
   with deterministic crossbeam-channel handshakes (not sleep-based,
   per the concurrent-dispatch flake learning). The sensitive tree
   must remain byte-identical across every iteration regardless of
   who wins each race.

Dependencies / sequencing:

- Consumes the SEC-1.g API surface (fast_io::UnlinkFlags,
  fast_io::unlink_via_sandbox_or_fallback) added in #4671. CI
  failures before #4671 merges are expected; rebase after merge.
- No unsafe outside fast_io, no allow waivers, no new workspace
  deps (crossbeam-channel and tempfile are already dev-deps).
- Gated #[cfg(unix)] since DirSandbox is Unix-only.
oferchen added a commit that referenced this pull request Aug 24, 2026
)

Adds the create-class siblings to the SEC-1 dirfd carrier:
mkdirat / symlinkat / linkat and the via_sandbox_or_fallback
adaptors that route a single-component leaf under the receiver's
DirSandbox root through the *at variant while preserving the
existing path-based fallback for multi-component paths, missing
sandbox, and non-Unix targets.

Wires the receiver pipeline:
- create_symlinks now creates symlinks through
  symlinkat_via_sandbox_or_fallback.
- create_hardlinks creates follower hard links through
  linkat_via_sandbox_or_fallback, keeping fast_io::hard_link
  (io_uring LINKAT fast path) as the fallback so EXDEV/EPERM
  semantics survive.
- create_directories and create_directory_incremental create
  new directories through mkdirat_via_sandbox_or_fallback, with
  fs::create_dir_all retained as the multi-component fallback.

Follows the SEC-1.g pattern (PR #4671). mknodat is deferred:
device/FIFO/socket creation is wrapped by the metadata crate and
needs deeper refactoring before the sandbox can be threaded
through; receiver-side mknod is not on the daemon-reachable
TOCTOU surface today.

Windows stays on path-based stdlib per the SEC-1.l NTFS-handle
audit.
oferchen added a commit that referenced this pull request Aug 24, 2026
…n/.k/.l ship state

Update CVE-2026-29518 and CVE-2026-43619 entries to "Mostly fixed",
reflecting the SEC-1 sub-tasks now in master:

- .a/.b/.c/.d/.e: DirSandbox carrier, openat2 detection, receiver wiring
- .f: lstat to fstatat (PR #4668)
- .g: remove to unlinkat (PR #4671)
- .h: mkdir/symlink/hard_link to *at variants (PR #4683)
- .k: macOS verified
- .l: Windows audited (NTFS handle-based, not affected)
- .m: symlink-swap attack regression (PR #4675)
- .n: legitimate symlink interop regression (PR #4678)

Remaining work explicitly listed:

- .i (chmod/lchown/utimes to *at) - in flight
- .j (rename to renameat) - in flight
- mknodat for device/FIFO nodes - deferred (not daemon-reachable)
- Receiver wiring for SEC-1.i helpers - deferred (carrier-first staging)

Target full-Fixed status: when SEC-1.i and SEC-1.j ship and all receiver
call sites are wired through DirSandbox.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant