Skip to content

feat(fast_io,engine): replace lstat/symlink_metadata with fstatat(AT_SYMLINK_NOFOLLOW) (SEC-1.f) - #4668

Merged
oferchen merged 3 commits into
masterfrom
feat/sec-1-f-fstatat-migration
May 21, 2026
Merged

oferchen merged 3 commits into
masterfrom
feat/sec-1-f-fstatat-migration

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Adds fast_io::fstatat_nofollow (single unsafe block, SAFETY comment) plus a typed AtMetadata surface in the new crates/fast_io/src/dir_sandbox/at_syscalls.rs module, and a sandbox-aware lstat_via_sandbox_or_fallback adaptor for callers that hold an absolute path.
  • Wires the receiver-side hardlink and symlink obstacle probes (crates/transfer/src/receiver/directory/links.rs:85, :227) through the helper when the SEC-1.e DirSandbox carrier is available, falling back to std::fs::symlink_metadata otherwise. create_symlinks and create_hardlinks grow an Option<&DirSandbox> parameter threaded from PipelineSetup by sync.rs / pipelined.rs / pipelined_incremental.rs.
  • Closes the lstat-class slice of the TOCTOU window upstream patched in rsync 3.4.3 (CVE-2026-29518, CVE-2026-43619): a symlink swap on a single-component receiver-owned leaf can no longer redirect the obstacle stat to an attacker-chosen inode.

Builds on:

Audit source: docs/audits/sec-1-a-path-syscall-surface-2026-05-20.md. This PR is the lstat-class slice (symlink_metadata sites only). The remaining *at siblings (unlinkat, mkdirat, fchmodat, renameat, ...) are SEC-1.g-j.

Migrated sites (lstat-class, receiver-reachable)

File Line Before After
crates/transfer/src/receiver/directory/links.rs 85 link_path.symlink_metadata().is_ok() fast_io::lstat_via_sandbox_or_fallback(...).is_ok()
crates/transfer/src/receiver/directory/links.rs 227 fs::symlink_metadata(&link_path) fast_io::lstat_via_sandbox_or_fallback(...) (link side)

The leader_path stat (links.rs:228) stays on fs::symlink_metadata because the leader is owned by the receiver-managed HardlinkApplyTracker and may live under a different parent than dest_dir for cross-segment hardlinks. Multi-component relative paths take the path-based fallback for now; the SEC-1.f follow-up will extend the cutover once the descent stack is wired through every executor.

Engine-side lstat sites listed in the audit (engine/src/local_copy/..., engine/src/delete/extras.rs) need a CopyContext carrier extension that is sequenced as SEC-1.g - flagged but not migrated here to keep this PR focused on what the existing SEC-1.e plumbing reaches.

Constraints honoured

  • No unsafe outside fast_io. Transfer keeps its #![deny(unsafe_code)] gate.
  • No #[allow(...)] waivers. clippy::unnecessary_cast portability handled with explicit per-OS widening helpers (widen_dev / widen_ino / widen_size).
  • No new workspace dependencies.
  • Public APIs unchanged outside the new fast_io re-exports (AtMetadata, LstatOutcome, fstatat_nofollow, lstat_via_sandbox_or_fallback).
  • Unix-only; Windows continues to use NTFS handle-based APIs per the SEC-1.l audit.

Tests

New:

  • fast_io::dir_sandbox::at_syscalls::tests::fstatat_nofollow_rejects_symlink_leaf (the core SEC-1.f invariant) and four siblings: fstatat_nofollow_stats_regular_file, fstatat_nofollow_stats_directory, fstatat_nofollow_reports_enoent_for_missing_leaf, fstatat_nofollow_exposes_dev_and_ino.
  • Four lstat_via_sandbox_or_fallback cases covering single-component vs multi-component vs absent-sandbox dispatch, plus dev/ino cross-check.
  • crates/transfer/tests/fstatat_swap_resistance.rs (5 tests) exercises the receiver-shaped symlink obstacle probe and the hardlink quick-check against a real destination tree, asserting AT_SYMLINK_NOFOLLOW reports the symlink itself and that dev/ino match across the two stat paths.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings clean
  • cargo nextest run -p fast_io --all-features -E 'test(fstatat) or test(lstat)': 10/10 green
  • cargo nextest run -p transfer --features 'incremental-flist' --test fstatat_swap_resistance: 5/5 green
  • cargo nextest run -p transfer --features 'incremental-flist' -E 'test(hardlink) or test(symlink) or test(create_hardlinks) or test(create_symlinks)': 92/92 green
  • cargo nextest run -p fast_io -p engine -p transfer --features 'parallel-receive-delta incremental-flist io_uring': 6414/6416 (the 2 pre-existing failures on master - macOS /var/folders rewrap and empty_file_checksum_verification_sha1 - reproduce on unmodified master and are not caused by this change)
  • cargo nextest run -p protocol --all-features -E 'test(golden)': 407/407 green

Follow-up

SEC-1.g (mkdirat / unlinkat) and the engine-side carrier plumbing land next; this PR holds the line on the receiver-reachable lstat surface where the SEC-1.e dirfd is already in scope.

…T_SYMLINK_NOFOLLOW) (SEC-1.f)

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

Closes the lstat-class slice of the TOCTOU window upstream patched in
rsync 3.4.3 (CVE-2026-29518, CVE-2026-43619): a symlink swap on a
single-component receiver-owned leaf can no longer redirect the obstacle
stat to an attacker-chosen inode, because the syscall is anchored on the
dirfd opened at receiver setup rather than re-walking the path through
the kernel.

* New `crates/fast_io/src/dir_sandbox/at_syscalls.rs` module wraps
  `libc::fstatat(AT_SYMLINK_NOFOLLOW)` behind a typed `AtMetadata`
  surface so consumer crates take on no `unsafe`. Single `unsafe` block
  with a SAFETY comment, paired with a sandbox-aware
  `lstat_via_sandbox_or_fallback` helper for callers that hold an
  absolute path.
* `transfer/src/receiver/directory/links.rs`: three lstat call sites
  (symlink obstacle probe + hardlink quick-check link side) now route
  through the helper. `create_symlinks` and `create_hardlinks` grow an
  `Option<&DirSandbox>` parameter threaded from `PipelineSetup` by the
  three transfer entry points (sync, pipelined, pipelined_incremental).
* Multi-component relative paths and absent-sandbox cases fall back to
  `std::fs::symlink_metadata`; the SEC-1.f follow-up will extend the
  cutover once the descent stack is wired through every executor.

Constraints honoured:
* No `unsafe` outside `fast_io` (deny gate is intact on `transfer`).
* No `#[allow(...)]` waivers; the `clippy::unnecessary_cast` portability
  story is handled with explicit per-OS widening helpers.
* No new workspace dependencies.
* Public APIs unchanged outside the new fast_io re-exports.

Tests:
* `fast_io::dir_sandbox::at_syscalls::tests::fstatat_nofollow_rejects_symlink_leaf`
  plus four siblings (`fstatat_nofollow_stats_regular_file`,
  `fstatat_nofollow_stats_directory`,
  `fstatat_nofollow_reports_enoent_for_missing_leaf`,
  `fstatat_nofollow_exposes_dev_and_ino`) and four
  `lstat_via_sandbox_or_fallback` cases covering single-component vs
  multi-component vs absent-sandbox dispatch.
* `crates/transfer/tests/fstatat_swap_resistance.rs` exercises the
  receiver-shaped symlink obstacle probe and the hardlink quick-check
  against a real destination tree, asserting `AT_SYMLINK_NOFOLLOW`
  reports the symlink itself and that dev/ino match across the two
  stat paths.

Verification:
* `cargo fmt --all -- --check` clean
* `cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings` clean
* `cargo nextest run -p fast_io -p engine -p transfer --features 'parallel-receive-delta incremental-flist io_uring'`: 6414 pass, 2 pre-existing failures on master unrelated to this change (macOS `/var/folders` and `empty_file_checksum_verification_sha1`)
* `cargo nextest run -p protocol --all-features -E 'test(golden)'`: 407/407 green
@github-actions github-actions Bot added the enhancement New feature or request label May 21, 2026
oferchen added 2 commits May 21, 2026 14:00
The original `u32::from(self.stat.st_mode)` triggered
`clippy::useless_conversion` on Linux because `mode_t` is already `u32`
there. Match the existing widen_dev pattern: cfg-gated `widen_mode`
helper that does `u32::from` on macOS (where mode_t is u16) and
identity on other Unix targets.
SEC-1.f added \`Option<&fast_io::DirSandbox>\` parameter to
\`create_hardlinks\` under \`#[cfg(unix)]\`. DirSandbox itself is
Unix-only, so on Windows the signature stays 2-arg. The test file
runs on all platforms and called the function with 3 args
unconditionally, breaking the Windows build with E0061.

Routed every test call through a single \`call_create_hardlinks\`
shim that picks the right arity per platform. Production call sites
in sync.rs / pipelined.rs / pipelined_incremental.rs already use this
cfg-gated pattern; only the tests were missing it.
@oferchen
oferchen merged commit 2038dd0 into master May 21, 2026
54 of 55 checks passed
@oferchen
oferchen deleted the feat/sec-1-f-fstatat-migration branch May 21, 2026 13:27
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 added a commit that referenced this pull request Aug 24, 2026
…SYMLINK_NOFOLLOW) (SEC-1.f) (#4668)

* feat(fast_io,transfer): replace lstat/symlink_metadata with fstatat(AT_SYMLINK_NOFOLLOW) (SEC-1.f)

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

Closes the lstat-class slice of the TOCTOU window upstream patched in
rsync 3.4.3 (CVE-2026-29518, CVE-2026-43619): a symlink swap on a
single-component receiver-owned leaf can no longer redirect the obstacle
stat to an attacker-chosen inode, because the syscall is anchored on the
dirfd opened at receiver setup rather than re-walking the path through
the kernel.

* New `crates/fast_io/src/dir_sandbox/at_syscalls.rs` module wraps
  `libc::fstatat(AT_SYMLINK_NOFOLLOW)` behind a typed `AtMetadata`
  surface so consumer crates take on no `unsafe`. Single `unsafe` block
  with a SAFETY comment, paired with a sandbox-aware
  `lstat_via_sandbox_or_fallback` helper for callers that hold an
  absolute path.
* `transfer/src/receiver/directory/links.rs`: three lstat call sites
  (symlink obstacle probe + hardlink quick-check link side) now route
  through the helper. `create_symlinks` and `create_hardlinks` grow an
  `Option<&DirSandbox>` parameter threaded from `PipelineSetup` by the
  three transfer entry points (sync, pipelined, pipelined_incremental).
* Multi-component relative paths and absent-sandbox cases fall back to
  `std::fs::symlink_metadata`; the SEC-1.f follow-up will extend the
  cutover once the descent stack is wired through every executor.

Constraints honoured:
* No `unsafe` outside `fast_io` (deny gate is intact on `transfer`).
* No `#[allow(...)]` waivers; the `clippy::unnecessary_cast` portability
  story is handled with explicit per-OS widening helpers.
* No new workspace dependencies.
* Public APIs unchanged outside the new fast_io re-exports.

Tests:
* `fast_io::dir_sandbox::at_syscalls::tests::fstatat_nofollow_rejects_symlink_leaf`
  plus four siblings (`fstatat_nofollow_stats_regular_file`,
  `fstatat_nofollow_stats_directory`,
  `fstatat_nofollow_reports_enoent_for_missing_leaf`,
  `fstatat_nofollow_exposes_dev_and_ino`) and four
  `lstat_via_sandbox_or_fallback` cases covering single-component vs
  multi-component vs absent-sandbox dispatch.
* `crates/transfer/tests/fstatat_swap_resistance.rs` exercises the
  receiver-shaped symlink obstacle probe and the hardlink quick-check
  against a real destination tree, asserting `AT_SYMLINK_NOFOLLOW`
  reports the symlink itself and that dev/ino match across the two
  stat paths.

Verification:
* `cargo fmt --all -- --check` clean
* `cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings` clean
* `cargo nextest run -p fast_io -p engine -p transfer --features 'parallel-receive-delta incremental-flist io_uring'`: 6414 pass, 2 pre-existing failures on master unrelated to this change (macOS `/var/folders` and `empty_file_checksum_verification_sha1`)
* `cargo nextest run -p protocol --all-features -E 'test(golden)'`: 407/407 green

* fix(fast_io): per-OS widen_mode helper for AtMetadata::mode

The original `u32::from(self.stat.st_mode)` triggered
`clippy::useless_conversion` on Linux because `mode_t` is already `u32`
there. Match the existing widen_dev pattern: cfg-gated `widen_mode`
helper that does `u32::from` on macOS (where mode_t is u16) and
identity on other Unix targets.

* fix(transfer): cfg-aware create_hardlinks shim in hard_links tests

SEC-1.f added \`Option<&fast_io::DirSandbox>\` parameter to
\`create_hardlinks\` under \`#[cfg(unix)]\`. DirSandbox itself is
Unix-only, so on Windows the signature stays 2-arg. The test file
runs on all platforms and called the function with 3 args
unconditionally, breaking the Windows build with E0061.

Routed every test call through a single \`call_create_hardlinks\`
shim that picks the right arity per platform. Production call sites
in sync.rs / pipelined.rs / pipelined_incremental.rs already use this
cfg-gated pattern; only the tests were missing it.
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
…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