Skip to content

fix(receiver): stat alt-dest basis via the ownership walk - #7421

Merged
oferchen merged 3 commits into
masterfrom
fix/alt-dest-confined-parent
Aug 21, 2026
Merged

oferchen merged 3 commits into
masterfrom
fix/alt-dest-confined-parent

Conversation

@oferchen

Copy link
Copy Markdown
Owner

What

The receiver resolved a --compare-dest / --copy-dest / --link-dest basis
entry with a plain fs::symlink_metadata, which re-walks every component of a
peer-supplied entry name at call time. Upstream reaches the same entry
through owner_walk_parent() + link_stat_at() (generator.c:979-990), so a
symlink component owned by neither root nor our euid is refused with ELOOP
rather than traversed.

This routes the basis stat onto fast_io::owner_walk - the same primitive the
sibling operator-path families already use for --temp-dir (#7398) and
--backup-dir (#7404).

Why this shape

Only the parent is walked. The leaf is fstatat(AT_SYMLINK_NOFOLLOW)'d and
never opened:

  • upstream must report a symlink at the basis name as a symlink so its
    !S_ISREG filter drops it. Opening the leaf resolves it, which measurably
    re-opens the hole fix(receiver): never follow a symlinked alt-dest basis entry #7419 just closed - the existing
    link_dest_skips_symlink_basis_entry cell caught exactly that while this was
    being built.
  • opening would also demand read permission that the --link-dest hard-link
    path does not need.

The fs::Metadata handed downstream comes from a second path stat, accepted
only when it names the same (dev, ino) the confined stat saw. That keeps
quick_check_matches / metadata_unchanged on their std types while making
a parent flipped between the two calls refusable rather than silently followed.

Scope, stated plainly

The ownership walk's rule is ownership, not location: uid 0 or our euid is the
operator's own layout (--link-dest=/backup where backup -> /mnt/disk) and is
followed; any other uid is refused.

Measured against real rsync 3.5.0: with basis/sub -> ../outside owned by
the invoking user, upstream consumes the basis and does not transfer
sub/payload.bin. oc did the same before this change, so the traversing half is
unchanged - and it is now pinned, because breaking it would break the deployments
that rely on it.

The half that changes behaviour needs a foreign-owned symlink and therefore
root to construct, so it is not reachable from a non-root nextest cell. It
stays pinned at the predicate, by owner_walk's existing
refuses_an_owner_that_is_neither_root_nor_the_euid.

Verification

  • symlink_basis_tests 6/6, including the three --copy-dest / --link-dest /
    --compare-dest leaf cells from fix(receiver): never follow a symlinked alt-dest basis entry #7419 as the regression guard.
  • full -p transfer --all-features: 2762 run, 2762 passed, 3 skipped.
  • cargo fmt --all -- --check clean; clippy -p transfer -p fast_io --all-targets --all-features -D warnings clean.
  • oracle script comparing oc against the built rsync-3.5.0 binary on the
    symlinked-parent and real-parent cells.

Closes the alt-dest half of the operator-path confinement family.

@github-actions github-actions Bot added the bug Something isn't working label Aug 21, 2026
@oferchen
oferchen force-pushed the fix/alt-dest-confined-parent branch from a536e95 to 01307b4 Compare August 21, 2026 09:23
@oferchen
oferchen marked this pull request as draft August 21, 2026 09:28
@oferchen

Copy link
Copy Markdown
Owner Author

Marking draft: the required interop check is red, and it is this change.

--link-dest: hello.txt not hardlinked (count=1)                 UNEXPECTED FAIL: up:link-dest
--compare-dest: hello.txt was transferred despite matching ref  UNEXPECTED FAIL: up:compare-dest

Both fail at every protocol (unforced and fp=28..32), in the up: cells only — upstream as client with oc as the server-side receiver via --rsync-path. Master is green at this branch's base (80d5461), so this is a regression, not an inherited red. Failure mode is "basis looks absent", which is exactly what basis_stat returning None produces.

Ruled out so far, by measurement on macOS against the same shapes:

  • relative vs absolute alt-dest path — both skip/hardlink correctly
  • --compare-dest / --link-dest / --copy-dest on the local-copy path — all correct
  • upstream-client push to an oc server receiver with the reference dir inside the destination (the harness's exact layout) — correct

So the trigger is Linux-specific and not reproducible here. Not merging until it is root-caused; the earlier operator_open_read misstep in this same PR is a reminder that the peer-facing receiver is a different path from the one the unit tests exercise.

The receiver resolved a `--compare-dest` / `--copy-dest` / `--link-dest`
basis entry with a plain path stat, which walks every component of a
peer-supplied entry name at call time. Upstream reaches the same entry
through `owner_walk_parent()` plus `link_stat_at()` (generator.c:979-990),
so a symlink component owned by neither root nor our euid is refused with
ELOOP instead of followed.

Route the basis stat onto `fast_io::owner_walk`, the same primitive the
sibling operator-path families already use for --temp-dir and --backup-dir.
Only the parent is walked: the leaf is `fstatat(AT_SYMLINK_NOFOLLOW)`'d and
never opened, because upstream must report a symlink at the basis name AS a
symlink for its `!S_ISREG` filter to drop it, and because opening would
demand read permission the --link-dest hard-link path does not need. The
`fs::Metadata` handed downstream comes from a second path stat that is
accepted only when it names the same (dev, ino) the confined stat saw, so a
parent flipped between the two calls is refused.

Measured against real rsync 3.5.0: a self-owned symlinked parent is
traversed by both implementations, and that half is now pinned. The
refusing half needs a foreign-owned symlink and therefore root to
construct; it stays pinned at the predicate, by owner_walk's
`refuses_an_owner_that_is_neither_root_nor_the_euid`.
The alt-dest basis lookup stats a file two ways - `fstatat` through the
confined dirfd and `symlink_metadata` by path - and accepts the second only
when it names the same `(dev, ino)` as the first. That cross-check silently
degrades into "basis absent" on any target where the two stat APIs disagree,
and the comparison is not a tautology: `fstatat_nofollow` calls
`libc::fstatat`, while `std` on Linux goes through `statx` and rebuilds
`st_dev` from the returned major/minor pair.

Pin the agreement directly so the platform where it stops holding fails
loudly and by name instead of surfacing as a mis-attributed transfer.
@oferchen
oferchen force-pushed the fix/alt-dest-confined-parent branch from a6c3ccf to b3ccc59 Compare August 21, 2026 14:33
`basis_link_stat()` has three arms, and only the first belongs to a
non-daemon receiver:

  1. `!am_daemon && am_root >= 0 && !symlink_optout_allowed()` resolves the
     basis parent through the ownership walk (generator.c:978).
  2. `am_daemon && !am_chrooted && path[0] == '/'` walks it with module-root
     confinement (generator.c:993).
  3. everything else takes a plain `link_stat()` (generator.c:1010).

The ownership walk was being applied unconditionally, so a daemon receiver
took arm 1 where upstream takes arm 3. That is not just stricter than
upstream, it is inoperative: the walk opens every component starting at `/`,
and a daemon worker is confined - chroot, or a Landlock ruleset rooted at the
module - precisely so the module's ancestors are not openable. The first
`openat("/")` returns EACCES, the basis looks absent, and every file is
re-transferred. Upstream's own note on arm 2 covers this exact shape: a
relative basis such as `--link-dest=../01` is a dest-relative sibling whose
`../` `sanitize_path` has already clamped to the module root, so it "must
keep the plain link_stat below (#915/#930)".

Arm selection is spelled as a `BasisTrust` value rather than a bare bool so
neither arm can be picked by accident at a call site. Arm 2 (an absolute
basis under module-root confinement) is not implemented here; on that path
the receiver keeps the path-based stat it has always used, so this is no
weaker than before in any configuration.

Measured on Linux against the upstream 3.5.0 testsuite cell
`link-dest-relative-basis`, which exercises `--link-dest`, `--copy-dest` and
`--compare-dest` over a daemon push: it is `pass` in both pipe manifests, and
the unconditional walk turned it red.
@oferchen
oferchen marked this pull request as ready for review August 21, 2026 16:31
@oferchen
oferchen merged commit 176782a into master Aug 21, 2026
71 checks passed
@oferchen
oferchen deleted the fix/alt-dest-confined-parent branch August 21, 2026 16:31
oferchen added a commit that referenced this pull request Aug 24, 2026
…7477)

The docs were last refreshed at #7423; 55 PRs have merged since, and the
testsuite figures they quote had drifted far enough to understate the
current state by roughly half.

CHANGELOG: fill in Unreleased for everything merged since #7423. The
dominant theme is routing every operator-named auxiliary file open onto
the ownership walk - upstream's open_no_attacker_symlinks() applied at the
call sites upstream applies it - plus a daemon hardening batch and an
alt-dest correctness batch.

README and SECURITY: the per-leg outcome tables were re-derived from the
committed expect manifests rather than carried forward. Failures fell and
the corpus grew, so every figure moved:

  non-root pipe  43 -> 21 fail   (345 -> 349 corpus)
  root pipe      62 -> 29 fail   (345 -> 349 corpus)
  non-root tcp   42 -> 29 fail   (155 -> 158 corpus)
  root tcp       55 -> 38 fail   (155 -> 158 corpus)

Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55
across all four.

SECURITY, two CVE rows that had gone stale:
- CVE-2026-53790 said "under audit". The refusal has since been applied at
  the live sink - oc-rsync's own single-character config expander, which
  upstream does not have, so an upstream-shaped port alone would have been
  inert (#7465, #7430, #7445).
- CVE-2026-53795 listed only the staging family. The auxiliary-file family
  followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459,
  #7463); what remains is the per-option-family confinement.
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix(receiver): stat alt-dest basis via the ownership walk

The receiver resolved a `--compare-dest` / `--copy-dest` / `--link-dest`
basis entry with a plain path stat, which walks every component of a
peer-supplied entry name at call time. Upstream reaches the same entry
through `owner_walk_parent()` plus `link_stat_at()` (generator.c:979-990),
so a symlink component owned by neither root nor our euid is refused with
ELOOP instead of followed.

Route the basis stat onto `fast_io::owner_walk`, the same primitive the
sibling operator-path families already use for --temp-dir and --backup-dir.
Only the parent is walked: the leaf is `fstatat(AT_SYMLINK_NOFOLLOW)`'d and
never opened, because upstream must report a symlink at the basis name AS a
symlink for its `!S_ISREG` filter to drop it, and because opening would
demand read permission the --link-dest hard-link path does not need. The
`fs::Metadata` handed downstream comes from a second path stat that is
accepted only when it names the same (dev, ino) the confined stat saw, so a
parent flipped between the two calls is refused.

Measured against real rsync 3.5.0: a self-owned symlinked parent is
traversed by both implementations, and that half is now pinned. The
refusing half needs a foreign-owned symlink and therefore root to
construct; it stays pinned at the predicate, by owner_walk's
`refuses_an_owner_that_is_neither_root_nor_the_euid`.

* test(fast_io): pin AtMetadata against std::fs::Metadata on one file

The alt-dest basis lookup stats a file two ways - `fstatat` through the
confined dirfd and `symlink_metadata` by path - and accepts the second only
when it names the same `(dev, ino)` as the first. That cross-check silently
degrades into "basis absent" on any target where the two stat APIs disagree,
and the comparison is not a tautology: `fstatat_nofollow` calls
`libc::fstatat`, while `std` on Linux goes through `statx` and rebuilds
`st_dev` from the returned major/minor pair.

Pin the agreement directly so the platform where it stops holding fails
loudly and by name instead of surfacing as a mis-attributed transfer.

* fix(receiver): keep the plain basis stat on a daemon receiver

`basis_link_stat()` has three arms, and only the first belongs to a
non-daemon receiver:

  1. `!am_daemon && am_root >= 0 && !symlink_optout_allowed()` resolves the
     basis parent through the ownership walk (generator.c:978).
  2. `am_daemon && !am_chrooted && path[0] == '/'` walks it with module-root
     confinement (generator.c:993).
  3. everything else takes a plain `link_stat()` (generator.c:1010).

The ownership walk was being applied unconditionally, so a daemon receiver
took arm 1 where upstream takes arm 3. That is not just stricter than
upstream, it is inoperative: the walk opens every component starting at `/`,
and a daemon worker is confined - chroot, or a Landlock ruleset rooted at the
module - precisely so the module's ancestors are not openable. The first
`openat("/")` returns EACCES, the basis looks absent, and every file is
re-transferred. Upstream's own note on arm 2 covers this exact shape: a
relative basis such as `--link-dest=../01` is a dest-relative sibling whose
`../` `sanitize_path` has already clamped to the module root, so it "must
keep the plain link_stat below (#915/#930)".

Arm selection is spelled as a `BasisTrust` value rather than a bare bool so
neither arm can be picked by accident at a call site. Arm 2 (an absolute
basis under module-root confinement) is not implemented here; on that path
the receiver keeps the path-based stat it has always used, so this is no
weaker than before in any configuration.

Measured on Linux against the upstream 3.5.0 testsuite cell
`link-dest-relative-basis`, which exercises `--link-dest`, `--copy-dest` and
`--compare-dest` over a daemon push: it is `pass` in both pipe manifests, and
the unconditional walk turned it red.
oferchen added a commit that referenced this pull request Aug 24, 2026
…7477)

The docs were last refreshed at #7423; 55 PRs have merged since, and the
testsuite figures they quote had drifted far enough to understate the
current state by roughly half.

CHANGELOG: fill in Unreleased for everything merged since #7423. The
dominant theme is routing every operator-named auxiliary file open onto
the ownership walk - upstream's open_no_attacker_symlinks() applied at the
call sites upstream applies it - plus a daemon hardening batch and an
alt-dest correctness batch.

README and SECURITY: the per-leg outcome tables were re-derived from the
committed expect manifests rather than carried forward. Failures fell and
the corpus grew, so every figure moved:

  non-root pipe  43 -> 21 fail   (345 -> 349 corpus)
  root pipe      62 -> 29 fail   (345 -> 349 corpus)
  non-root tcp   42 -> 29 fail   (155 -> 158 corpus)
  root tcp       55 -> 38 fail   (155 -> 158 corpus)

Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55
across all four.

SECURITY, two CVE rows that had gone stale:
- CVE-2026-53790 said "under audit". The refusal has since been applied at
  the live sink - oc-rsync's own single-character config expander, which
  upstream does not have, so an upstream-shaped port alone would have been
  inert (#7465, #7430, #7445).
- CVE-2026-53795 listed only the staging family. The auxiliary-file family
  followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459,
  #7463); what remains is the per-option-family confinement.
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