Skip to content

fix(receiver): open a daemon module root plainly, confine only the peer tail - #7304

Merged
oferchen merged 8 commits into
masterfrom
fix/dest-root-operator-anchor
Aug 14, 2026
Merged

oferchen merged 8 commits into
masterfrom
fix/dest-root-operator-anchor

Conversation

@oferchen

@oferchen oferchen commented Aug 13, 2026 •

Copy link
Copy Markdown
Owner

The bug

A daemon receiver cannot serve a module whose configured root reaches its target through a symlink. With path = /srv/backup where /srv -> /mnt/srv — an ordinary layout — every transfer into that module fails on Linux 5.6+ with ELOOP, and the error blames a chdir-symlink-race that is not happening.

This is an availability defect: the module is unusable, and the diagnostic points away from the cause.

Why

The destination reaches the receiver as a single flattened string, module_root.join(peer_tail), built by resolve_receiver_dest_path in client_args/path_resolution.rs. Fusing the two halves loses the fact that they carry different trust:

half who supplies it
module root the operator, in oc-rsyncd.conf
tail whatever the client sent on the wire

DirSandbox::open_root then applied one resolve policy to the whole string. The rule that belongs to the peer's tail was being enforced against the operator's own root.

Upstream keeps the halves in different mechanisms and says why in the source. open_anchor_dirfd() opens the anchor with a plain openat (syscall.c:85-90), commented at syscall.c:3189-3193 as "Absolute basedir: operator-trusted". ds_descend() (syscall.c:2891) walks the untrusted remainder.

The change

open_sandbox_for_dest_anchored splits the composite back apart and gives each half the mechanism upstream gives it: a plain open for the anchor, RESOLVE_BENEATH per tail component.

Re-anchoring the tail is what keeps this a fix rather than a hole. Opening the root plainly and re-joining the tail into a path-based open would let a symlinked tail component walk straight out of the module. The tail is walked from the anchor fd; a component that leaves it fails EXDEV, and non-Normal components are refused rather than normalised away.

Scope is narrow: only a daemon connection with a resolved module root takes the new path. Every other receiver keeps the existing open.

Second defect, same root cause

The per-entry descent refused every symlinked subdirectory inside the destination tree. Upstream follows one — ds_descend() splices a relative in-tree target back into the walk (syscall.c:2961) and refuses only an absolute target or a climb above the anchor.

The refusal did not come from the resolve mask, which is why an earlier attempt to relax it changed nothing. openat2_beneath also set O_NOFOLLOW in how.flags, and every caller passes a single component, so the leaf is the whole path and O_NOFOLLOW refused it before any resolve flag was consulted. Measured on Linux 7.0.0 against a relative in-tree symlink:

+O_NOFOLLOW  BENEATH|NO_SYMLINKS    -> ENOTDIR
+O_NOFOLLOW  BENEATH|NO_MAGICLINKS  -> ENOTDIR   (mask change alone: inert)
 no NOFOLLOW BENEATH|NO_MAGICLINKS  -> OK        (upstream behaviour)
 no NOFOLLOW BENEATH|NO_SYMLINKS    -> ELOOP
 escape:     BENEATH|NO_MAGICLINKS  -> EXDEV

Row 4 is the control: RESOLVE_NO_SYMLINKS is not redundant in general — it refuses where BENEATH alone does not. It is redundant only here, where O_NOFOLLOW is set and the path is one component. This diff should not be read as removing a safety flag.

Two riders on the tests

Fixtures must use a RELATIVE symlink target. An absolute target is refused under RESOLVE_BENEATH even when it resolves inside the anchor, and upstream refuses absolute targets too (syscall.c:2953), so an absolute-target fixture passes for the wrong reason and can never detect a symlink-following regression.

Symlinked-ancestor tests must plant the symlink explicitly. A TempDir proves nothing on either CI platform, for opposite reasons: on macOS /tmp -> private/tmp gives every tempdir a symlinked ancestor, but the leaf-only non-Linux arm never inspects interior components; on Linux CI tempdirs sit under a real /tmp, so the check is never reached. The platform that has the condition cannot detect it, and the platform that can detect it never has it.

Tests

  • Symlinked module root opens, carrying a Linux-only control asserting the pre-fix path did refuse the same layout — so it cannot pass vacuously on a build that never had the bug.
  • Peer tail escaping the module is refused with EXDEV; an in-tree relative symlink is followed.
  • Both new fast_io descent tests were verified to fail when O_NOFOLLOW is restored.

Three existing tests asserted the old policy and were retargeted, not loosened. All three plant ABSOLUTE symlink targets, which RESOLVE_BENEATH refuses as escapes, so each now asserts EXDEV alongside the prior errnos and says so in its name. The refusal is unchanged — only which errno reports it — and EXDEV is the stronger statement, naming an escape rather than merely a symlink.

A finding in its own right

One of those three is uts_nextest_chdir_symlink_race.rs, the port of the CVE-2026-29518 chdir-symlink-race scenario. It could never have detected a symlink-following regression — it plants an absolute target, which is refused in every configuration this code has ever had, so its refusal assertion passed no matter what the descent policy did. A security regression test that cannot detect the regression it is named for is worse than none, because it occupies the slot. The actual fix is the relative-target case, which neither that file nor dir_sandbox_carrier.rs had; both now have it. The sentinel assertions that prove the attack failed are untouched.

Both files live in crates/transfer/tests/, which crate unit-test runs never touch — the gap was invisible to anything short of a full-target run.

Cross-implementation cell

Real rsync 3.5.0 serves a module whose root sits behind a symlinked ancestor, so oc must too. Measured on Linux, path = $tmp/srv/backup with srv -> mnt-srv (relative target), daemon push over rsync://, asserting the payload lands in the real store:

binary exit file landed
rsync 3.5.0 0 yes
oc-rsync pre-fix (372847513) 23 no — daemon log: refusing to …
oc-rsync with this change 0 yes

The middle row is what makes the other two evidence: the layout upstream serves is exactly the one oc refused.

Coarse timing

enter() is a per-entry descent, so the mask change was checked for regression — coarsely, not benchmarked. Daemon push of 180 directories / 120 files onto a plain module root, best of 3, debug build:

PRE-FIX    45 ms   (120 files)
WITH-FIX   38 ms   (120 files)

No regression. The gap is within noise at this sample size and should not be read as a speed-up; the change swaps one openat2 resolve mask for another on the same syscall, so no per-entry cost was expected either way.

The policy seam

The split above leaves an open question the resolver design has to answer: upstream's walk carries a confinement check the kernel cannot express. ds_descend consults abspath_outside_confinement after each component, and abspath is seeded only for an absolute anchor (syscall.c:2989-2991) — so an operator-trusted caller runs the same walk with the check compiled out, and a daemon caller runs it with the check live.

RESOLVE_BENEATH cannot host that check. It refuses escapes from the anchor, which is not the same predicate as "outside the configured confinement root", and it gives the caller no point at which to evaluate anything. The two callers therefore need different resolution mechanisms, not different arguments to one mechanism.

This PR lands the seam that expresses that, plus the arm that is already exercised:

pub trait ConfinementOracle {
    fn outside_confinement(&self, abspath: &Path) -> bool;
}

pub struct NoExclude;                       // zero-sized; the check compiles out
pub struct ConfinePolicy<O = NoExclude> { /* … */ }

open_dest_anchor now delegates to open_dest_anchor_with_policy(.., ConfinePolicy::operator_trusted()), so the seam sits on the live daemon path from this commit rather than waiting for a future consumer.

Behaviour is unchanged on every currently-exercised path. The NoExclude arm keeps RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS — the mechanism the measurements above already established as matching upstream. No measured cell changes.

Why the seam sits exactly here

Two independent requirements land on the same boundary, which is the strongest thing that can be said for a split of this kind.

The first is the exclude check above. The second is upstream's hop budget: ds_walk_path passes hops by pointer, as a single budget shared across the whole walk rather than reset per component. That budget only exists if oc does the walking. Under RESOLVE_BENEATH the kernel follows symlinks internally and enforces its own limit — oc passes no budget, observes no intermediate hops, and has nothing to make cumulative. So the per-descend-reset bug is unreachable in the BENEATH arm and mandatory to get right in the manual arm.

Arriving at the same boundary from the exclude check and from the hop budget, by unrelated routes, is what makes this a real seam rather than a convenient one.

What is deliberately not here

The manual per-component walk — and with it the shared hop budget, ..-as-movement, and the confinement-root escape check — lands with its oracle, not ahead of it. A walk whose only consumer does not exist yet is unreachable code, and this repository has five such orphans already, all hidden by the same crate-root pub use mechanism that makes dead_code structurally unable to fire.

The manual arm also gives up openat2's atomicity: evaluating the exclude check between components means the walk observes the tree in steps rather than in one kernel call. That is a trade, not an oversight — upstream accepts the same one for the same reason, because a check the kernel cannot express has to be evaluated somewhere the kernel is not. It is recorded as a decision in the design doc rather than left to be rediscovered.

Evidence it is not vacuous

RED was a missing-symbol failure. The new test then passed. Mutating the fixture to point the symlink outside the anchor fails it with EXDEV, so the assertion discriminates between "followed an in-tree symlink" and "accepted anything at all" rather than passing unconditionally.

Deliberately not in this PR

  • The canonicalize block in context.rs stays — do not "finish the job" without reading this. It is gated to !is_daemon_connection, so the daemon path never reaches it and removing it fixes nothing here. More importantly it rewrites dest_dir itself rather than only the sandbox open, so deleting it changes the recorded destination on the local-copy path. That makes it a different change on the hottest path in the product, not a residual of this one. It becomes redundant only once the non-daemon root also opens plainly.
  • secure_dir.rs keeps RESOLVE_NO_SYMLINKS without BENEATH. It is called with AT_FDCWD and an absolute path, where BENEATH would refuse every module root. That is a different call shape, not a third policy, and it is documented in place.
  • metadata_ops is untouched. Its three secure_open_dir callers take an absolute parent with no dirfd anchor; giving them beneath-semantics needs an anchor threaded through their signatures and every caller above.

Residuals, stated plainly

oc does not yet match upstream's symlink policy everywhere. The non-Linux arm is leaf-only O_NOFOLLOW and still refuses a symlink leaf regardless of target; that platform split is a real gap, not an oversight. metadata_ops and the non-daemon root are named above. Tracked separately.

Verification

cargo fmt --all -- --check clean. cargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warnings exits 0. transfer + fast_io + logging: 4063 run, 4063 passed. daemon: 1774 passed. Cross-implementation cell and coarse timing as above.

Re-verified on the seam commit: cargo fmt --all -- --check clean, cargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warnings exits 0, cargo nextest run -p fast_io --all-features 988 passed / 1 skipped.

The new warning's delivery to stderr is asserted, not inferred. Both links are tested: warn_log! emits exactly one event carrying LogCode::Warning at level 0 (the count catches silence; the level catches the unreachable-verbosity bug), and LogCode::Warning resolves to MessageStream::Stderr across the whole StreamContext matrix including --quiet. A third test is the control — Info is Suppressed under --quiet and Stdout otherwise — so the router is shown to discriminate rather than returning Stderr unconditionally.

This replaced an earlier "it routes the same way debug_log! does" argument. That class of reasoning has been wrong twice in this crate already: once because debug_gte short-circuits before the message is ever formatted, and once because the chosen level was unreachable at every verbosity an operator can set.

@github-actions github-actions Bot added the bug Something isn't working label Aug 13, 2026
…tail

Upstream splits path resolution by who supplied the path. An absolute
basedir is operator-supplied and opened with a plain
openat(AT_FDCWD, path, O_RDONLY | O_DIRECTORY) - no O_NOFOLLOW, no
resolve flags (syscall.c:85-90 open_anchor_dirfd, reached from
syscall.c:3189-3193 under the comment "Absolute basedir:
operator-trusted"). Confinement applies to the peer-supplied remainder,
walked beneath that anchor (syscall.c:2891 ds_descend).

oc had no equivalent of the trusted-anchor open, so callers reached for
secure_open_dir and got RESOLVE_NO_SYMLINKS applied to a path the
operator chose. This adds the two halves upstream keeps separate:

open_trusted_dir() is the plain anchor open.

DirSandbox::open_dest_anchor() takes the anchor and the peer tail as
distinct arguments and resolves the tail beneath the anchor, so the two
trust levels cannot be fused into one string and given one policy.

The tail descent uses RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS, matching
the mask the peer-path parent anchor already uses
(at_syscalls/nested.rs:201) and upstream ds_descend, which follows a
relative in-tree symlink and refuses an escape. openat2_beneath now
takes the resolve mask as a parameter; the existing per-entry descent
keeps the mask it had.
The per-entry descent refused every symlinked subdirectory inside the
destination tree. Upstream follows one: ds_descend() (syscall.c:2891)
splices a relative in-tree symlink target back into the walk and refuses
only an absolute target or a climb above the anchor.

The refusal did not come from the resolve mask, which is why it survived
an earlier attempt to relax it. openat2_beneath also set O_NOFOLLOW in
how.flags, and every caller passes a single component, so the leaf is the
whole path and O_NOFOLLOW refused it before any resolve flag was
consulted. Measured on Linux 7.0.0 against a relative in-tree symlink:

  +O_NOFOLLOW  BENEATH|NO_SYMLINKS    -> ENOTDIR
  +O_NOFOLLOW  BENEATH|NO_MAGICLINKS  -> ENOTDIR   (mask change alone: inert)
   no NOFOLLOW BENEATH|NO_MAGICLINKS  -> OK        (upstream behaviour)
   no NOFOLLOW BENEATH|NO_SYMLINKS    -> ELOOP

Dropping O_NOFOLLOW cannot widen what is reachable: RESOLVE_BENEATH is
retained, and a relative symlink leaving the anchor still fails with
EXDEV. RESOLVE_NO_SYMLINKS is not redundant in general - row 4 shows it
refusing where BENEATH alone does not - only here, where O_NOFOLLOW is
set and the path is one component.

openat_dir now carries the same mask as the peer-path parent anchor
(at_syscalls/nested.rs:201), so one policy covers both, and its rationale
comment applies to both rather than contradicting a sibling.

enter_rejects_symlink_child asserted the over-strict behaviour and became
enter_follows_in_tree_symlink_child, plus a negative control that pins an
escape to an escape errno rather than to "there was a symlink". Both fail
if O_NOFOLLOW is restored, verified by restoring it. The module doc
claimed the file confirmed symlink rejection at the descent open; that is
no longer the contract and it now describes the two opens separately.

The fixture must use a RELATIVE symlink target. An absolute target is
refused under RESOLVE_BENEATH even when it resolves inside the anchor,
and upstream refuses absolute targets too (syscall.c:2953), so an
absolute-target fixture passes for the wrong reason.

Also adds warn_log!, the emitter for a level oc had a sink for but no
macro. upstream: FWARNING is dispatched by rwrite() (log.c:341) and
carried to the peer for protocols >= 30 (rsync.h:285, rsync.h:296), so it
is not verbosity-gated. The (code N) at file(line) trailer upstream
renders at log.c:956 is deliberately left to the logcode funnel.
…er tail

A daemon receiver could not serve a module whose configured root reaches
its target through a symlink. `path = /srv/backup` where `/srv` is a link
returned ELOOP and refused every transfer on Linux 5.6+, reporting a
chdir-symlink-race that was not happening.

The destination arrives here as one flattened string,
`module_root.join(peer_tail)`, built by resolve_receiver_dest_path in
client_args/path_resolution.rs. Fusing the halves loses the fact that
they are not equally trusted: the operator authored the root, the client
sent the tail. One resolve policy over the whole string applied the
tail's rule to the root as well.

Upstream keeps them in different mechanisms. open_anchor_dirfd opens the
anchor with a plain openat and records why at syscall.c:3189-3193
- "Absolute basedir: operator-trusted" - while ds_descend, syscall.c:2891,
walks the untrusted remainder. open_sandbox_for_dest_anchored now does
the same: plain open for the anchor, RESOLVE_BENEATH per tail component.

Re-anchoring the tail is what keeps this a fix rather than a hole.
Opening the root plainly and re-joining the tail into a path-based open
would let a symlinked tail component walk out of the module, so the tail
is walked from the anchor fd and a component that leaves it fails EXDEV.
Non-Normal components are refused rather than normalised away.

Scope: only a daemon connection with a resolved module root takes the new
path. Every other receiver keeps the existing open.

The canonicalize block in context.rs is deliberately NOT removed. It is
already gated to non-daemon, so the daemon path never reaches it, and it
rewrites dest_dir itself rather than only the sandbox open - removing it
would change the recorded destination on the hottest path. It becomes
redundant only once the non-daemon root also opens plainly, which is a
separate change.

Tests plant the symlink explicitly. A TempDir proves nothing about
symlinked ancestors on either CI platform, and for opposite reasons: on
macOS /tmp -> private/tmp gives every tempdir one, but the leaf-only
non-Linux arm never inspects interior components; on Linux CI tempdirs
sit under a real /tmp so the check is never reached. The platform that
has the condition cannot detect it and the platform that can never has
it. The symlinked-root test carries a Linux-only control asserting the
pre-fix path DID refuse the same layout, so it cannot pass vacuously on
a build that never had the bug.

Two existing tests pinned the old policy and were retargeted, not
loosened. Both plant ABSOLUTE symlink targets, which RESOLVE_BENEATH
refuses as escapes, so each now asserts EXDEV alongside the old errnos
and says so in its name. The refusal is unchanged - only which errno
reports it - and EXDEV is the stronger statement, naming an escape
rather than merely a symlink. The chdir-symlink-race sentinel assertions
that actually prove the attack failed are untouched. The relative-target
case neither file covered is now covered.
The soft fallback reported itself with debug_log! at level 2, which is
unreachable at every verbosity an operator can actually set, so a daemon
continuing without per-component confinement was unobservable.

Split the fallback by errno. ENOENT stays debug: a first-run push creates
the tail during the transfer and there is nothing to tell anyone. Anything
else means a daemon receiver just lost its anchored dirfd and will use
path-based syscalls instead, without the confinement its role is supposed
to carry - upstream confines exactly this role (use_secure_symlinks =
am_daemon && !am_chrooted, clientserver.c:1018), so say so.

Warning rather than a louder debug level because upstream does not
verbosity-gate this class: FWARNING is dispatched by rwrite() on its own
(log.c:341) and carried to the peer for protocols >= 30 (rsync.h:285,
rsync.h:296).

Delivery to stderr is NOT asserted by a test here - the emitter matches
what debug_log! already does, but that is an argument, not a measurement.
The warning added for the daemon-lost-confinement case rested on an
argument: it routes the same way debug_log! does, and debug_log! reaches
operators. That reasoning has already been wrong twice in this crate -
once because debug_gte short-circuits before the message is formatted,
and once because the chosen level was unreachable at every verbosity an
operator can set. Both links are now asserted.

Link 1: warn_log! emits exactly one event carrying LogCode::Warning at
level 0. Asserting the count catches silence, which is the failure mode
the call site cares about; asserting level 0 catches the unreachable-
verbosity bug directly.

Link 2: LogCode::Warning resolves to MessageStream::Stderr across the
full StreamContext matrix, --quiet included. upstream: FWARNING shares
the f = stderr arm with FERROR (log.c:309-316), and only FINFO consults
quiet (log.c:317-320), so a warning is not suppressible the way an info
message is.

A third test is the control. It asserts Info is Suppressed under --quiet
and Stdout otherwise, so the router is shown to discriminate. Without it
both assertions above would pass on a build where message_stream
returned Stderr unconditionally, and would be evidence of nothing.
The emit_warning comment block was written against 3.5.0 while the
citation gate pins 3.4.4. All four line numbers resolve exactly at
3.5.0 and none at 3.4.4:

  log.c:341  -> 314   case FWARNING:
  rsync.h:285 -> 278  FERROR=3, FWARNING=4 (sent over socket, proto >= 30)
  rsync.h:296 -> 289  MSG_ERROR=FERROR, MSG_WARNING=FWARNING
  log.c:956  -> 909   rprintf(FWARNING, "rsync warning: ...")

log.c in 3.4.4 is 916 lines, so :956 could not resolve at all.

Only the last of these was gate-visible; the other three sit in prose
doc comments the string-anchor scan does not reach, and were wrong in
the same way.
The policy selects the resolution MECHANISM, not merely the call shape.
This lands the seam plus the arm that is already exercised; the manual
per-component walk lands with its oracle in tasks 599/600, because a
walk whose only consumer does not exist yet would be unreachable code.

ConfinementOracle is a trait in fast_io, taken as a type parameter with
a zero-sized NoExclude default, so an operator-trusted walk compiles the
check out entirely - mirroring upstream leaving ds.abspath unseeded for
a non-daemon caller (syscall.c:2989-2991).

open_dest_anchor now delegates to open_dest_anchor_with_policy, so the
seam is on the live daemon path from the first commit rather than
waiting for a future consumer.

Behaviour is unchanged on every currently-exercised path: the NoExclude
arm keeps RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS, which task 598
measured as already matching upstream (in-tree relative symlink
followed, escape refused).

Verified: RED was a missing-symbol failure; the new test then passed;
and a mutation pointing the symlink outside the anchor fails it with
EXDEV, so the assertion discriminates rather than passing vacuously.
Master now pins the citation oracle at rsync 3.5.0
(tools/ci/upstream-3.5.0-lines.tsv). An earlier commit on this branch
retargeted these four at 3.4.4, which was correct under the old pin and
is wrong under the new one.

The citation gate CANNOT catch this, and that is why it is worth
stating. It checks that a cited file exists and that the line is within
the file, not that the line says what the comment claims. Every stale
3.4.4 number is comfortably in-bounds for 3.5.0's longer files, so the
gate returns exit 0 either way - measured, identical output:

  stale 3.4.4 citations, 3.5.0 pin -> exit 0, 7775 citations checked
  fixed 3.5.0 citations, 3.5.0 pin -> exit 0, 7775 citations checked

The evidence is therefore reading the target lines, not running the
gate. What each number points at in rsync 3.5.0:

  log.c:341    case FWARNING:                     <- what the comment claims
  log.c:314    int priority = ... LOG_WARNING     <- what it pointed at (syslog)
  rsync.h:285  FERROR=3, FWARNING=4 (proto >= 30) <- the socket rule
  rsync.h:296  MSG_ERROR=FERROR, MSG_WARNING=...  <- the alias
  log.c:956    rprintf(FWARNING, warning format)  <- the formatting site
  log.c:909    file = (struct file_struct *)bp    <- what it pointed at

Comment-only change. fmt clean; nextest -p logging 355 passed, 1 skipped.
@oferchen
oferchen force-pushed the fix/dest-root-operator-anchor branch from 4f2132b to 9ce00d7 Compare August 14, 2026 03:27
@oferchen
oferchen enabled auto-merge (squash) August 14, 2026 04:02
@oferchen
oferchen merged commit 5ecd8c8 into master Aug 14, 2026
65 of 68 checks passed
@oferchen
oferchen deleted the fix/dest-root-operator-anchor branch August 14, 2026 05:54
oferchen added a commit that referenced this pull request Aug 24, 2026
…er tail (#7304)

* fix(fast_io): open an operator anchor plainly, confine only the peer tail

Upstream splits path resolution by who supplied the path. An absolute
basedir is operator-supplied and opened with a plain
openat(AT_FDCWD, path, O_RDONLY | O_DIRECTORY) - no O_NOFOLLOW, no
resolve flags (syscall.c:85-90 open_anchor_dirfd, reached from
syscall.c:3189-3193 under the comment "Absolute basedir:
operator-trusted"). Confinement applies to the peer-supplied remainder,
walked beneath that anchor (syscall.c:2891 ds_descend).

oc had no equivalent of the trusted-anchor open, so callers reached for
secure_open_dir and got RESOLVE_NO_SYMLINKS applied to a path the
operator chose. This adds the two halves upstream keeps separate:

open_trusted_dir() is the plain anchor open.

DirSandbox::open_dest_anchor() takes the anchor and the peer tail as
distinct arguments and resolves the tail beneath the anchor, so the two
trust levels cannot be fused into one string and given one policy.

The tail descent uses RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS, matching
the mask the peer-path parent anchor already uses
(at_syscalls/nested.rs:201) and upstream ds_descend, which follows a
relative in-tree symlink and refuses an escape. openat2_beneath now
takes the resolve mask as a parameter; the existing per-entry descent
keeps the mask it had.

* fix(fast_io): follow in-tree symlinks on descent, refuse only escapes

The per-entry descent refused every symlinked subdirectory inside the
destination tree. Upstream follows one: ds_descend() (syscall.c:2891)
splices a relative in-tree symlink target back into the walk and refuses
only an absolute target or a climb above the anchor.

The refusal did not come from the resolve mask, which is why it survived
an earlier attempt to relax it. openat2_beneath also set O_NOFOLLOW in
how.flags, and every caller passes a single component, so the leaf is the
whole path and O_NOFOLLOW refused it before any resolve flag was
consulted. Measured on Linux 7.0.0 against a relative in-tree symlink:

  +O_NOFOLLOW  BENEATH|NO_SYMLINKS    -> ENOTDIR
  +O_NOFOLLOW  BENEATH|NO_MAGICLINKS  -> ENOTDIR   (mask change alone: inert)
   no NOFOLLOW BENEATH|NO_MAGICLINKS  -> OK        (upstream behaviour)
   no NOFOLLOW BENEATH|NO_SYMLINKS    -> ELOOP

Dropping O_NOFOLLOW cannot widen what is reachable: RESOLVE_BENEATH is
retained, and a relative symlink leaving the anchor still fails with
EXDEV. RESOLVE_NO_SYMLINKS is not redundant in general - row 4 shows it
refusing where BENEATH alone does not - only here, where O_NOFOLLOW is
set and the path is one component.

openat_dir now carries the same mask as the peer-path parent anchor
(at_syscalls/nested.rs:201), so one policy covers both, and its rationale
comment applies to both rather than contradicting a sibling.

enter_rejects_symlink_child asserted the over-strict behaviour and became
enter_follows_in_tree_symlink_child, plus a negative control that pins an
escape to an escape errno rather than to "there was a symlink". Both fail
if O_NOFOLLOW is restored, verified by restoring it. The module doc
claimed the file confirmed symlink rejection at the descent open; that is
no longer the contract and it now describes the two opens separately.

The fixture must use a RELATIVE symlink target. An absolute target is
refused under RESOLVE_BENEATH even when it resolves inside the anchor,
and upstream refuses absolute targets too (syscall.c:2953), so an
absolute-target fixture passes for the wrong reason.

Also adds warn_log!, the emitter for a level oc had a sink for but no
macro. upstream: FWARNING is dispatched by rwrite() (log.c:341) and
carried to the peer for protocols >= 30 (rsync.h:285, rsync.h:296), so it
is not verbosity-gated. The (code N) at file(line) trailer upstream
renders at log.c:956 is deliberately left to the logcode funnel.

* fix(receiver): open a daemon module root plainly, confine only the peer tail

A daemon receiver could not serve a module whose configured root reaches
its target through a symlink. `path = /srv/backup` where `/srv` is a link
returned ELOOP and refused every transfer on Linux 5.6+, reporting a
chdir-symlink-race that was not happening.

The destination arrives here as one flattened string,
`module_root.join(peer_tail)`, built by resolve_receiver_dest_path in
client_args/path_resolution.rs. Fusing the halves loses the fact that
they are not equally trusted: the operator authored the root, the client
sent the tail. One resolve policy over the whole string applied the
tail's rule to the root as well.

Upstream keeps them in different mechanisms. open_anchor_dirfd opens the
anchor with a plain openat and records why at syscall.c:3189-3193
- "Absolute basedir: operator-trusted" - while ds_descend, syscall.c:2891,
walks the untrusted remainder. open_sandbox_for_dest_anchored now does
the same: plain open for the anchor, RESOLVE_BENEATH per tail component.

Re-anchoring the tail is what keeps this a fix rather than a hole.
Opening the root plainly and re-joining the tail into a path-based open
would let a symlinked tail component walk out of the module, so the tail
is walked from the anchor fd and a component that leaves it fails EXDEV.
Non-Normal components are refused rather than normalised away.

Scope: only a daemon connection with a resolved module root takes the new
path. Every other receiver keeps the existing open.

The canonicalize block in context.rs is deliberately NOT removed. It is
already gated to non-daemon, so the daemon path never reaches it, and it
rewrites dest_dir itself rather than only the sandbox open - removing it
would change the recorded destination on the hottest path. It becomes
redundant only once the non-daemon root also opens plainly, which is a
separate change.

Tests plant the symlink explicitly. A TempDir proves nothing about
symlinked ancestors on either CI platform, and for opposite reasons: on
macOS /tmp -> private/tmp gives every tempdir one, but the leaf-only
non-Linux arm never inspects interior components; on Linux CI tempdirs
sit under a real /tmp so the check is never reached. The platform that
has the condition cannot detect it and the platform that can never has
it. The symlinked-root test carries a Linux-only control asserting the
pre-fix path DID refuse the same layout, so it cannot pass vacuously on
a build that never had the bug.

Two existing tests pinned the old policy and were retargeted, not
loosened. Both plant ABSOLUTE symlink targets, which RESOLVE_BENEATH
refuses as escapes, so each now asserts EXDEV alongside the old errnos
and says so in its name. The refusal is unchanged - only which errno
reports it - and EXDEV is the stronger statement, naming an escape
rather than merely a symlink. The chdir-symlink-race sentinel assertions
that actually prove the attack failed are untouched. The relative-target
case neither file covered is now covered.

* fix(receiver): warn when a daemon loses its anchored destination dirfd

The soft fallback reported itself with debug_log! at level 2, which is
unreachable at every verbosity an operator can actually set, so a daemon
continuing without per-component confinement was unobservable.

Split the fallback by errno. ENOENT stays debug: a first-run push creates
the tail during the transfer and there is nothing to tell anyone. Anything
else means a daemon receiver just lost its anchored dirfd and will use
path-based syscalls instead, without the confinement its role is supposed
to carry - upstream confines exactly this role (use_secure_symlinks =
am_daemon && !am_chrooted, clientserver.c:1018), so say so.

Warning rather than a louder debug level because upstream does not
verbosity-gate this class: FWARNING is dispatched by rwrite() on its own
(log.c:341) and carried to the peer for protocols >= 30 (rsync.h:285,
rsync.h:296).

Delivery to stderr is NOT asserted by a test here - the emitter matches
what debug_log! already does, but that is an argument, not a measurement.

* test(logging): assert warn_log! reaches stderr instead of inferring it

The warning added for the daemon-lost-confinement case rested on an
argument: it routes the same way debug_log! does, and debug_log! reaches
operators. That reasoning has already been wrong twice in this crate -
once because debug_gte short-circuits before the message is formatted,
and once because the chosen level was unreachable at every verbosity an
operator can set. Both links are now asserted.

Link 1: warn_log! emits exactly one event carrying LogCode::Warning at
level 0. Asserting the count catches silence, which is the failure mode
the call site cares about; asserting level 0 catches the unreachable-
verbosity bug directly.

Link 2: LogCode::Warning resolves to MessageStream::Stderr across the
full StreamContext matrix, --quiet included. upstream: FWARNING shares
the f = stderr arm with FERROR (log.c:309-316), and only FINFO consults
quiet (log.c:317-320), so a warning is not suppressible the way an info
message is.

A third test is the control. It asserts Info is Suppressed under --quiet
and Stdout otherwise, so the router is shown to discriminate. Without it
both assertions above would pass on a build where message_stream
returned Stderr unconditionally, and would be evidence of nothing.

* docs(logging): retarget four FWARNING citations at the pinned 3.4.4

The emit_warning comment block was written against 3.5.0 while the
citation gate pins 3.4.4. All four line numbers resolve exactly at
3.5.0 and none at 3.4.4:

  log.c:341  -> 314   case FWARNING:
  rsync.h:285 -> 278  FERROR=3, FWARNING=4 (sent over socket, proto >= 30)
  rsync.h:296 -> 289  MSG_ERROR=FERROR, MSG_WARNING=FWARNING
  log.c:956  -> 909   rprintf(FWARNING, "rsync warning: ...")

log.c in 3.4.4 is 916 lines, so :956 could not resolve at all.

Only the last of these was gate-visible; the other three sit in prose
doc comments the string-anchor scan does not reach, and were wrong in
the same way.

* feat(fast_io): introduce the confinement policy seam (NoExclude arm)

The policy selects the resolution MECHANISM, not merely the call shape.
This lands the seam plus the arm that is already exercised; the manual
per-component walk lands with its oracle in tasks 599/600, because a
walk whose only consumer does not exist yet would be unreachable code.

ConfinementOracle is a trait in fast_io, taken as a type parameter with
a zero-sized NoExclude default, so an operator-trusted walk compiles the
check out entirely - mirroring upstream leaving ds.abspath unseeded for
a non-daemon caller (syscall.c:2989-2991).

open_dest_anchor now delegates to open_dest_anchor_with_policy, so the
seam is on the live daemon path from the first commit rather than
waiting for a future consumer.

Behaviour is unchanged on every currently-exercised path: the NoExclude
arm keeps RESOLVE_BENEATH | RESOLVE_NO_MAGICLINKS, which task 598
measured as already matching upstream (in-tree relative symlink
followed, escape refused).

Verified: RED was a missing-symbol failure; the new test then passed;
and a mutation pointing the symlink outside the anchor fails it with
EXDEV, so the assertion discriminates rather than passing vacuously.

* docs(logging): flip four FWARNING citations back to 3.5.0 lines

Master now pins the citation oracle at rsync 3.5.0
(tools/ci/upstream-3.5.0-lines.tsv). An earlier commit on this branch
retargeted these four at 3.4.4, which was correct under the old pin and
is wrong under the new one.

The citation gate CANNOT catch this, and that is why it is worth
stating. It checks that a cited file exists and that the line is within
the file, not that the line says what the comment claims. Every stale
3.4.4 number is comfortably in-bounds for 3.5.0's longer files, so the
gate returns exit 0 either way - measured, identical output:

  stale 3.4.4 citations, 3.5.0 pin -> exit 0, 7775 citations checked
  fixed 3.5.0 citations, 3.5.0 pin -> exit 0, 7775 citations checked

The evidence is therefore reading the target lines, not running the
gate. What each number points at in rsync 3.5.0:

  log.c:341    case FWARNING:                     <- what the comment claims
  log.c:314    int priority = ... LOG_WARNING     <- what it pointed at (syslog)
  rsync.h:285  FERROR=3, FWARNING=4 (proto >= 30) <- the socket rule
  rsync.h:296  MSG_ERROR=FERROR, MSG_WARNING=...  <- the alias
  log.c:956    rprintf(FWARNING, warning format)  <- the formatting site
  log.c:909    file = (struct file_struct *)bp    <- what it pointed at

Comment-only change. fmt clean; nextest -p logging 355 passed, 1 skipped.
oferchen added a commit that referenced this pull request Sep 2, 2026
`## [Unreleased]` last covered the #7304-#7522 era. Measured against the 60
most recently merged pull requests, 44 were absent; of the most recent 45,
43 were absent. Nothing from #7574 onward was recorded at all.

Each entry is derived from what the pull request actually landed - the merge
commit and the body - not from its title. Three cases where those differ:

  * #7616 ships far more than the doc-alias correction its body describes:
    the `upstream_version` pin moves to 3.5.0 and `--version` starts naming
    `quic`, `sd-notify`, `vmsplice` and `send_zc`.
  * #7618 also adds the pull-request rustdoc-link job its body says was
    filed separately, which is what closes the master-only-gate recurrence.
  * #7602's squash carries the closed #7597 as its first commit, so the
    directory-obstacle half is recorded under #7602.

#7587 is deliberately not recorded. Its merge commit is empty: the change
had already landed as #7563, which the section already names.

Entries extend the existing Keep a Changelog groups and the bold
sub-groupings. Clusters that are one story carry one entry with several
references: the FERROR_XFER routing and its two-phase drain (#7576, #7581),
the connection-FSM close edge and the accept loop that outlives a session
error (#7579, #7590), the three detaching daemon suites (#7578, #7588,
#7592), the io_uring and SEND_ZC work (#7593, #7600, #7610), the citation
retargets (#7601, #7603, #7604), and the accept-loop pin flake (#7615,
#7620).

Only `## [Unreleased]` is touched; every released section, including the
3.4.4 statements that were correct when written, is byte-identical.
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