Skip to content

fix(engine): confine the local-copy alt-dest basis stat to the ownership walk - #7463

Merged
oferchen merged 2 commits into
masterfrom
fix/local-altdest-basis-ownership-walk
Aug 23, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/local-altdest-basis-ownership-walk

Conversation

@oferchen

Copy link
Copy Markdown
Owner

What

Routes the local-copy alt-dest basis lookup onto the ownership walk, mirroring upstream's basis_link_stat().

A --link-dest / --copy-dest / --compare-dest argument is an operator-supplied path, so it may legitimately point outside the transfer tree and location cannot be the trust signal. Upstream makes authority the signal instead — generator.c:962 basis_link_stat():

if (!am_daemon && am_root >= 0 && !symlink_optout_allowed()) {
    int dfd = owner_walk_parent(path, &leaf);
    if (dfd < 0) return -1;          /* basis looks ABSENT -> transfer normally */
    r = link_stat_at(dfd, leaf, stp, 0);

A symlink component owned by neither uid 0 nor our euid is refused, and every one of its four call sites (generator.c:1084, :1110, :1227, :1254) turns the -1 into a continue — so a redirected basis simply looks absent and the file transfers normally.

The local-copy engine resolved its basis candidates with a plain fs::symlink_metadata at all four of its matching sites. An unprivileged user who controls a directory anywhere along the basis path could swap a component for a symlink and redirect the stat — and then the hard link, the copy, or the --compare-dest skip — at a file of their choosing.

Measured

Real upstream 3.5.0 vs oc-rsync, run as root on Linux, parent symlink owned by uid 65534, basis byte-identical to the source. --link-dest:

basis matches src fixture upstream 3.5.0 oc (before)
yes euid-owned link nlink=2 (follows, links) nlink=2
yes foreign-owned link nlink=1 (refuses, transfers fresh) nlink=2 (followed and hard-linked)
no euid-owned link nlink=1 nlink=1
no foreign-owned link nlink=1 nlink=1

The euid-owned row is the control that validates the instrument in both directions. --compare-dest showed the same class: oc skipped the file (destination left stale) where upstream transferred it. The non-matching-basis rows transfer on both impls, which is what rules out "wrong fallback on an unreadable basis" and leaves "followed the link".

Shape

The receiver already carried a complete port of this rule (crates/transfer/src/receiver/quick_check.rs::basis_stat, from #7421). The local-copy path is its unhardened twin. Rather than copy it:

  • the mechanism moves into fast_io::operator_symlink_metadata (parent via owner_trusted_parent, leaf via fstatat_nofollow, plus the (dev, ino) cross-check that makes the returned std::fs::Metadata safe to carry),
  • the receiver's BasisTrust::OwnerWalk arm delegates to it,
  • the engine's four sites call it through one private basis_stat.

Local copy is never a daemon worker, so it has no analogue of upstream's am_daemon plain-stat fall-through (generator.c:1010) — stated in the doc comment rather than left implicit.

Tests, and what they do not prove

Three new fast_io cells pin the contract: a leaf symlink reports as a symlink (so the is_file() filter drops it, which is what stops a symlinked basis entry being hard-linked), a euid-owned parent component is still followed, and a missing leaf is an error rather than a silent empty result.

⚠ Stated plainly: these three do not discriminate the ownership walk from a plain path stat. Mutating operator_symlink_metadata back to fs::symlink_metadata leaves all three green — the mutation kills nothing. The discriminating fixture needs a symlink owned by a foreign uid, which needs root; that is the same reason upstream marks its own matching cells root-only. The discriminating coverage is therefore the root testsuite leg's operator-path-*-dest cells, not a unit test, and the measured table above is the cross-implementation evidence.

The follow-direction cells are still load-bearing: they are what a careless "confine it, refuse every symlink" change would break, and that over-refusal is the most likely regression a future edit introduces here.

Residuals (filed, not claimed as covered)

  • Upstream additionally wraps hard_link_one in operator_path_resolve = 1 (generator.c:1120-1133) to close the stat→link race. This change fixes the stat gate, which is the substance; the race is a separate step.
  • BasisTrust::for_receiver branches only on is_daemon_connection, while upstream's predicate also carries am_root >= 0 (--fake-super) and !symlink_optout_allowed() (--insecure-links). oc is therefore stricter than upstream in those two cells — the opposite direction, and deliberately not folded into a security fix.

…hip walk

A --link-dest / --copy-dest / --compare-dest argument is an operator-supplied
path, so it may legitimately point outside the transfer tree and location
cannot be the trust signal. Upstream makes authority the signal instead:
basis_link_stat() (generator.c:962) resolves the parent with
owner_walk_parent() and lstats the leaf through the returned descriptor, so a
symlink component owned by neither uid 0 nor our euid is refused. A refusal
makes the basis look absent and the file transfers normally, which is what
every one of its four call sites does with the -1 (generator.c:1084, :1110,
:1227, :1254).

The local-copy engine resolved its basis candidates with a plain
fs::symlink_metadata at all four of its matching sites, so an unprivileged
user who controls a directory along the basis path could swap a component
for a symlink and redirect the stat - and then the hard link, the copy, or
the --compare-dest skip - at a file of their choosing.

Measured against real upstream 3.5.0 as root with a nobody-owned parent
symlink and a matching basis, --link-dest:

  upstream, euid-owned link   nlink=2   (follows, links)
  upstream, foreign-owned     nlink=1   (refuses, transfers fresh)
  oc,       euid-owned link   nlink=2   (control: instrument valid)
  oc,       foreign-owned     nlink=2   (followed and hard-linked)

--compare-dest showed the same class: oc skipped the file where upstream
transferred it. The non-matching-basis rows transfer on both, which is what
rules out a fallback difference and leaves "followed the link".

The receiver already carried a complete port of this rule
(receiver/quick_check.rs::basis_stat); the local-copy path is its unhardened
twin. The mechanism moves into fast_io::operator_symlink_metadata so both
sides share one implementation, and the receiver's OwnerWalk arm now
delegates to it. Local copy is never a daemon worker, so it has no analogue
of upstream's am_daemon plain-stat fall-through.

The three new fast_io cells pin the contract - a leaf symlink reports as a
symlink, a euid-owned parent component is still followed, a missing leaf is
an error - and the last of those is what a careless "refuse every symlink"
change would break. They do NOT discriminate the walk from a plain stat:
that requires a symlink owned by a foreign uid and therefore root, so the
discriminating cells are the root testsuite's operator-path alt-dest rows.
The root pipe leg reported exactly three expected-result mismatches against
this branch:

    operator-path-compare-dest: expected fail, got pass (xpass)
    operator-path-copy-dest:    expected fail, got pass (xpass)
    operator-path-link-dest:    expected fail, got pass (xpass)
    overall result is 3

Those three cells plant a symlink owned by a non-self uid and assert that the
alt-dest basis is not reached through it - which is precisely the confinement
this branch restores, so they now pass. The manifest is the ledger: leaving
them recorded as `fail` is what would be the waiver, because a future
regression would then be reported as the expected outcome and pass silently.

⚠ The header says regenerate rather than hand-edit. This edit is equivalent to
a regeneration and is derived from a real run, not typed: the gate compares all
345 outcomes and enumerated exactly these three as mismatched, so a regenerated
manifest differs from the committed one in exactly these three rows. Row count
is unchanged at 345 (254 pass / 37 fail / 54 skip, was 251/40/54).

Deliberately untouched:
- upstream-3.5.0-expect.nonroot.txt already records all three as `pass` - the
  cells need root to plant a foreign-uid symlink and self-skip without it.
- Neither TCP manifest contains these cells at all, which is why the root TCP
  leg reported `overall result is 0` on this same commit.
@oferchen
oferchen merged commit 8223237 into master Aug 23, 2026
71 checks passed
@oferchen
oferchen deleted the fix/local-altdest-basis-ownership-walk branch August 23, 2026 17:49
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
…hip walk (#7463)

* fix(engine): confine the local-copy alt-dest basis stat to the ownership walk

A --link-dest / --copy-dest / --compare-dest argument is an operator-supplied
path, so it may legitimately point outside the transfer tree and location
cannot be the trust signal. Upstream makes authority the signal instead:
basis_link_stat() (generator.c:962) resolves the parent with
owner_walk_parent() and lstats the leaf through the returned descriptor, so a
symlink component owned by neither uid 0 nor our euid is refused. A refusal
makes the basis look absent and the file transfers normally, which is what
every one of its four call sites does with the -1 (generator.c:1084, :1110,
:1227, :1254).

The local-copy engine resolved its basis candidates with a plain
fs::symlink_metadata at all four of its matching sites, so an unprivileged
user who controls a directory along the basis path could swap a component
for a symlink and redirect the stat - and then the hard link, the copy, or
the --compare-dest skip - at a file of their choosing.

Measured against real upstream 3.5.0 as root with a nobody-owned parent
symlink and a matching basis, --link-dest:

  upstream, euid-owned link   nlink=2   (follows, links)
  upstream, foreign-owned     nlink=1   (refuses, transfers fresh)
  oc,       euid-owned link   nlink=2   (control: instrument valid)
  oc,       foreign-owned     nlink=2   (followed and hard-linked)

--compare-dest showed the same class: oc skipped the file where upstream
transferred it. The non-matching-basis rows transfer on both, which is what
rules out a fallback difference and leaves "followed the link".

The receiver already carried a complete port of this rule
(receiver/quick_check.rs::basis_stat); the local-copy path is its unhardened
twin. The mechanism moves into fast_io::operator_symlink_metadata so both
sides share one implementation, and the receiver's OwnerWalk arm now
delegates to it. Local copy is never a daemon worker, so it has no analogue
of upstream's am_daemon plain-stat fall-through.

The three new fast_io cells pin the contract - a leaf symlink reports as a
symlink, a euid-owned parent component is still followed, a missing leaf is
an error - and the last of those is what a careless "refuse every symlink"
change would break. They do NOT discriminate the walk from a plain stat:
that requires a symlink owned by a foreign uid and therefore root, so the
discriminating cells are the root testsuite's operator-path alt-dest rows.

* test(ci): record the three alt-dest operator-path cells as passing

The root pipe leg reported exactly three expected-result mismatches against
this branch:

    operator-path-compare-dest: expected fail, got pass (xpass)
    operator-path-copy-dest:    expected fail, got pass (xpass)
    operator-path-link-dest:    expected fail, got pass (xpass)
    overall result is 3

Those three cells plant a symlink owned by a non-self uid and assert that the
alt-dest basis is not reached through it - which is precisely the confinement
this branch restores, so they now pass. The manifest is the ledger: leaving
them recorded as `fail` is what would be the waiver, because a future
regression would then be reported as the expected outcome and pass silently.

⚠ The header says regenerate rather than hand-edit. This edit is equivalent to
a regeneration and is derived from a real run, not typed: the gate compares all
345 outcomes and enumerated exactly these three as mismatched, so a regenerated
manifest differs from the committed one in exactly these three rows. Row count
is unchanged at 345 (254 pass / 37 fail / 54 skip, was 251/40/54).

Deliberately untouched:
- upstream-3.5.0-expect.nonroot.txt already records all three as `pass` - the
  cells need root to plant a foreign-uid symlink and self-skip without it.
- Neither TCP manifest contains these cells at all, which is why the root TCP
  leg reported `overall result is 0` on this same commit.
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