Repository navigation
feat(fast_io,engine): replace lstat/symlink_metadata with fstatat(AT_SYMLINK_NOFOLLOW) (SEC-1.f) - #4668
Merged
Conversation
…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
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.
2 tasks
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.
This was referenced May 21, 2026
Merged
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.
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
fast_io::fstatat_nofollow(singleunsafeblock, SAFETY comment) plus a typedAtMetadatasurface in the newcrates/fast_io/src/dir_sandbox/at_syscalls.rsmodule, and a sandbox-awarelstat_via_sandbox_or_fallbackadaptor for callers that hold an absolute path.crates/transfer/src/receiver/directory/links.rs:85,:227) through the helper when the SEC-1.eDirSandboxcarrier is available, falling back tostd::fs::symlink_metadataotherwise.create_symlinksandcreate_hardlinksgrow anOption<&DirSandbox>parameter threaded fromPipelineSetupby sync.rs / pipelined.rs / pipelined_incremental.rs.Builds on:
feat(fast_io): add DirSandbox + thread through receiver pipeline (SEC-1.e)- exposes the parent-dirfd carrier consumed here.Audit source:
docs/audits/sec-1-a-path-syscall-surface-2026-05-20.md. This PR is the lstat-class slice (symlink_metadatasites only). The remaining*atsiblings (unlinkat,mkdirat,fchmodat,renameat, ...) are SEC-1.g-j.Migrated sites (lstat-class, receiver-reachable)
crates/transfer/src/receiver/directory/links.rslink_path.symlink_metadata().is_ok()fast_io::lstat_via_sandbox_or_fallback(...).is_ok()crates/transfer/src/receiver/directory/links.rsfs::symlink_metadata(&link_path)fast_io::lstat_via_sandbox_or_fallback(...)(link side)The
leader_pathstat (links.rs:228) stays onfs::symlink_metadatabecause the leader is owned by the receiver-managedHardlinkApplyTrackerand may live under a different parent thandest_dirfor 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 aCopyContextcarrier 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
unsafeoutsidefast_io. Transfer keeps its#![deny(unsafe_code)]gate.#[allow(...)]waivers.clippy::unnecessary_castportability handled with explicit per-OS widening helpers (widen_dev/widen_ino/widen_size).fast_iore-exports (AtMetadata,LstatOutcome,fstatat_nofollow,lstat_via_sandbox_or_fallback).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.lstat_via_sandbox_or_fallbackcases 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, assertingAT_SYMLINK_NOFOLLOWreports the symlink itself and that dev/ino match across the two stat paths.Test plan
cargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features --no-deps -- -D warningscleancargo nextest run -p fast_io --all-features -E 'test(fstatat) or test(lstat)': 10/10 greencargo nextest run -p transfer --features 'incremental-flist' --test fstatat_swap_resistance: 5/5 greencargo nextest run -p transfer --features 'incremental-flist' -E 'test(hardlink) or test(symlink) or test(create_hardlinks) or test(create_symlinks)': 92/92 greencargo 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/foldersrewrap andempty_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 greenFollow-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.