Skip to content

fix: allow DirSandbox to follow in-tree symlinks for -K - #5510

Merged
oferchen merged 4 commits into
masterfrom
fix/copy-dirlinks-sandbox-regression
Jun 10, 2026
Merged

oferchen merged 4 commits into
masterfrom
fix/copy-dirlinks-sandbox-regression

Conversation

@oferchen

@oferchen oferchen commented Jun 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add DirSandbox::enter_follow_dirlinks() method that follows directory symlinks resolving within the sandbox tree, fixing a regression where -K / --copy-dirlinks caused the receiver sandbox to reject legitimate directory symlinks during descent
  • On Linux 5.6+ uses openat2(RESOLVE_BENEATH) without RESOLVE_NO_SYMLINKS for kernel-enforced confinement; on older kernels and macOS falls back to fstat same-device verification
  • Add openat2_beneath_follow() syscall helper and openat_follow_and_verify() fallback in fast_io::dir_sandbox

Context

Upstream rsync 3.4.3 fixed a regression where secure_relative_open() rejected every symlink via per-component O_NOFOLLOW walk, breaking -K (copy-dirlinks) during delta transfers with "failed verification -- update discarded" errors. Our SEC-1 sandbox had the same issue: DirSandbox::enter() uses RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS which rejects directory symlinks that -K needs to follow.

The fix mirrors upstream's approach: use RESOLVE_BENEATH alone (no RESOLVE_NO_SYMLINKS) so symlinks within the tree are followed while .. escapes are still rejected by the kernel.

Test plan

  • enter_follow_dirlinks_allows_in_tree_symlink - directory symlink to in-tree target succeeds
  • enter_follow_dirlinks_works_on_real_directory - non-symlink directories still work
  • enter_follow_dirlinks_rejects_nonexistent - ENOENT for missing children
  • enter_follow_dirlinks_rejects_file_child - ENOTDIR for non-directory children
  • enter_follow_dirlinks_nested_descent_through_symlink - descend through symlink then into real subdirectory
  • enter_follow_dirlinks_preserves_stack_on_failure - stack integrity on failed descent
  • copy_dirlinks_descent_through_in_tree_directory_symlink - integration test verifying default enter() still rejects symlinks while enter_follow_dirlinks() permits them, including file stat through the followed symlink
  • Existing enter_rejects_symlink_child test continues to pass (no regression on default behavior)

@github-actions github-actions Bot added the bug Something isn't working label Jun 5, 2026
@oferchen
oferchen force-pushed the fix/copy-dirlinks-sandbox-regression branch 3 times, most recently from 5e8846e to ca2e0de Compare June 6, 2026 19:54
oferchen added 3 commits June 10, 2026 05:59
The SEC-1 sandbox unconditionally rejected symlinks during directory
descent via RESOLVE_NO_SYMLINKS / O_NOFOLLOW. This caused failures
when -K (--copy-dirlinks) was active because the receiver could not
descend through legitimate directory symlinks on the destination side.

Add DirSandbox::enter_follow_dirlinks() that uses RESOLVE_BENEATH
without RESOLVE_NO_SYMLINKS on Linux 5.6+, allowing symlinks that
resolve within the tree while still rejecting .. escapes. On older
kernels and other platforms, a same-device fstat check provides a
conservative fallback.

Mirrors upstream rsync 3.4.3 fix for secure_relative_open() which
switched from per-component O_NOFOLLOW to openat2(RESOLVE_BENEATH).
The two failing tests created symlinks with absolute path targets. openat2's
RESOLVE_BENEATH flag rejects symlinks whose stored target is an absolute
path even when that path would resolve in-tree, because the kernel cannot
prove the target stays beneath dirfd without re-resolving from /.

Real-world -K (copy-dirlinks) flows preserve the source's symlink target
verbatim over the wire and these are typically relative (foo/bar) rather
than absolute (/tmp/xyz/foo/bar). Switching the test fixtures to relative
targets aligns with both the RESOLVE_BENEATH contract and how rsync's
wire protocol round-trips symlinks during -K.

Affected tests:
- enter_follow_dirlinks_allows_in_tree_symlink
- enter_follow_dirlinks_nested_descent_through_symlink

The existing rejection tests (enter_rejects_symlink_child,
open_root_rejects_symlink_root) keep absolute targets because their
assertion (ELOOP / ENOTDIR) is independent of target absoluteness.
@oferchen
oferchen force-pushed the fix/copy-dirlinks-sandbox-regression branch from 625db0c to aa73355 Compare June 10, 2026 02:59
The copy_dirlinks_descent_through_in_tree_directory_symlink test was
still creating an absolute-target symlink in the transfer crate's
integration test, matching the same bug fixed in the fast_io unit
tests by aa73355. openat2(RESOLVE_BENEATH) rejects absolute symlink
targets with EXDEV ("Cross-device link") even when the target resolves
in-tree, because the kernel cannot prove the re-resolution from /
stays beneath the dirfd.

Real -K (--copy-dirlinks) flows preserve the source's symlink target
verbatim over the wire and these are typically relative. Switching the
fixture to a relative target aligns with both the RESOLVE_BENEATH
contract and how rsync's wire protocol round-trips -K symlinks.

This unblocks the Linux feature-flag-combinations cells (incremental-flist,
flat-flist) and Linux musl (stable), which all hit the same EXDEV panic
during enter_follow_dirlinks.
@oferchen
oferchen merged commit b3adc2b into master Jun 10, 2026
70 checks passed
@oferchen
oferchen deleted the fix/copy-dirlinks-sandbox-regression branch June 10, 2026 05:14
oferchen added a commit that referenced this pull request Jun 10, 2026
Group PRs #5510, #5516, #5519, #5520, #5523, #5525-#5544 by shared root
cause rather than by Stream bucket. Seven clusters surface; the parser-
stores-string and field-vs-method shadowing clusters cover the largest
share of the series, and the receiver-driver wiring-parity gap explains
the NDX_DEL_STATS goodbye misses in both #5536 and #5542. Includes a
defense-in-depth audit mapping each cluster onto the rust-landlock
ruleset wired at crates/fast_io/src/landlock.rs.

Doc-only; no code paths touched.
oferchen added a commit that referenced this pull request Jun 10, 2026
Group PRs #5510, #5516, #5519, #5520, #5523, #5525-#5544 by shared root
cause rather than by Stream bucket. Seven clusters surface; the parser-
stores-string and field-vs-method shadowing clusters cover the largest
share of the series, and the receiver-driver wiring-parity gap explains
the NDX_DEL_STATS goodbye misses in both #5536 and #5542. Includes a
defense-in-depth audit mapping each cluster onto the rust-landlock
ruleset wired at crates/fast_io/src/landlock.rs.

Doc-only; no code paths touched.
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix: allow DirSandbox to follow in-tree directory symlinks for -K

The SEC-1 sandbox unconditionally rejected symlinks during directory
descent via RESOLVE_NO_SYMLINKS / O_NOFOLLOW. This caused failures
when -K (--copy-dirlinks) was active because the receiver could not
descend through legitimate directory symlinks on the destination side.

Add DirSandbox::enter_follow_dirlinks() that uses RESOLVE_BENEATH
without RESOLVE_NO_SYMLINKS on Linux 5.6+, allowing symlinks that
resolve within the tree while still rejecting .. escapes. On older
kernels and other platforms, a same-device fstat check provides a
conservative fallback.

Mirrors upstream rsync 3.4.3 fix for secure_relative_open() which
switched from per-component O_NOFOLLOW to openat2(RESOLVE_BENEATH).

* style: fix cargo fmt line break in openat2 flags assignment

* test: use relative symlink targets for enter_follow_dirlinks tests

The two failing tests created symlinks with absolute path targets. openat2's
RESOLVE_BENEATH flag rejects symlinks whose stored target is an absolute
path even when that path would resolve in-tree, because the kernel cannot
prove the target stays beneath dirfd without re-resolving from /.

Real-world -K (copy-dirlinks) flows preserve the source's symlink target
verbatim over the wire and these are typically relative (foo/bar) rather
than absolute (/tmp/xyz/foo/bar). Switching the test fixtures to relative
targets aligns with both the RESOLVE_BENEATH contract and how rsync's
wire protocol round-trips symlinks during -K.

Affected tests:
- enter_follow_dirlinks_allows_in_tree_symlink
- enter_follow_dirlinks_nested_descent_through_symlink

The existing rejection tests (enter_rejects_symlink_child,
open_root_rejects_symlink_root) keep absolute targets because their
assertion (ELOOP / ENOTDIR) is independent of target absoluteness.

* test: use relative symlink target in dir_sandbox_carrier -K test

The copy_dirlinks_descent_through_in_tree_directory_symlink test was
still creating an absolute-target symlink in the transfer crate's
integration test, matching the same bug fixed in the fast_io unit
tests by aa73355. openat2(RESOLVE_BENEATH) rejects absolute symlink
targets with EXDEV ("Cross-device link") even when the target resolves
in-tree, because the kernel cannot prove the re-resolution from /
stays beneath the dirfd.

Real -K (--copy-dirlinks) flows preserve the source's symlink target
verbatim over the wire and these are typically relative. Switching the
fixture to a relative target aligns with both the RESOLVE_BENEATH
contract and how rsync's wire protocol round-trips -K symlinks.

This unblocks the Linux feature-flag-combinations cells (incremental-flist,
flat-flist) and Linux musl (stable), which all hit the same EXDEV panic
during enter_follow_dirlinks.
oferchen added a commit that referenced this pull request Aug 24, 2026
Group PRs #5510, #5516, #5519, #5520, #5523, #5525-#5544 by shared root
cause rather than by Stream bucket. Seven clusters surface; the parser-
stores-string and field-vs-method shadowing clusters cover the largest
share of the series, and the receiver-driver wiring-parity gap explains
the NDX_DEL_STATS goodbye misses in both #5536 and #5542. Includes a
defense-in-depth audit mapping each cluster onto the rust-landlock
ruleset wired at crates/fast_io/src/landlock.rs.

Doc-only; no code paths touched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant