Skip to content

fix: pass upstream link-dest-relative-basis/pathroot/module-escape tests - #5680

Merged
oferchen merged 5 commits into
masterfrom
fix/uts-link-dest-relative-basis-daemon-receiver
Jun 11, 2026
Merged

oferchen merged 5 commits into
masterfrom
fix/uts-link-dest-relative-basis-daemon-receiver

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Three commits, two distinct root causes, one PR because both regressions had to clear for the failing upstream tests to pass:

  • fix(transfer): master is currently broken — PR fix: propagate ELOOP from sandboxed delete scan as IOERR_GENERAL #5620 merged the caller-side 3-tuple change but not the deletion.rs body that produces it. Revert the caller-side change to restore the build. The IOERR_GENERAL surface on sandbox-rejected delete scans (UTS-16.b) is temporarily disabled and tracked by the original PR.
  • fix(daemon) link-dest resolution: daemon receiver was joining relative --link-dest=../01 against the module root instead of the dest subdirectory, producing mod/../01 (parent of module) instead of mod/00/../01 = mod/01 (the in-module sibling). Every basis lookup missed and the file was re-transferred. Pre-resolve relative ref_dirs against the receiver's positional dest arg, lexically collapse .. segments, and confine the result inside the module root (URV-5.a.1.c absolute-path validation unchanged).
  • fix(daemon) LSM-CAP root worker: LSM-CAP at PR feat(daemon): apply PR_SET_NO_NEW_PRIVS + log active LSMs at startup #5581 dropped CAP_DAC_OVERRIDE / CAP_DAC_READ_SEARCH / CAP_FOWNER / CAP_FSETID even when the worker was still running as root, leaving it EACCES on any module tree under a 750-mode user homedir. Short-circuit drop_worker_capabilities whenever the worker is root — by explicit uid = 0 or by inheriting root from the daemon process (no per-module uid directive plus a daemon-wide root identity). Matches upstream rsync's behaviour.

Reproduced first

Linux host: runtests.py --use-tcp against oc-rsync daemon. Three tests reproduce on master:

$ for t in link-dest-module-escape link-dest-pathroot link-dest-relative-basis; do \
    sudo python3 ./runtests.py --rsync-bin /home/ofer/rsync/rsync \
      --rsync-bin2 /home/ofer/oc-rsync/target/release/oc-rsync \
      --use-tcp $t; \
  done
FAIL    link-dest-module-escape    (destination file missing)
FAIL    link-dest-pathroot         (connection unexpectedly closed, rc=12)
FAIL    link-dest-relative-basis   (connection unexpectedly closed, rc=12)

Strace evidence on the failing path:

  • mkdirat(AT_FDCWD, "mod/00/", 0777) = -1 EACCES (LSM-CAP stripping DAC bypass from root worker)
  • openat(AT_FDCWD, "mod/../01/f.dat") = -1 ENOENT (relative basis resolved against module root, not dest dir)

Both signals collected by re-running with strace -ff -e capset,openat,landlock_* on the daemon child.

Post-fix verification

Re-ran the same harness with the patched binary:

PASS    link-dest-module-escape
PASS    link-dest-pathroot
PASS    link-dest-relative-basis

Security guarantees preserved

  • URV-5.a.1.c (validate_client_paths_in_module): absolute --copy-dest / --link-dest / --compare-dest paths that escape the module root still get an @ERROR reply before this code path runs.
  • URV-5.a containment for relative ref_dirs: my pre-resolve step lexically collapses .. segments and runs starts_with(canonicalised module root); the link-dest-module-escape test exercises the ../../OUTSIDE climb and confirms the basis is silently dropped (file re-transferred, not hard-linked to the OUTSIDE secret).
  • No regression to parallel-receive-delta / io_uring / IOCP / flat-flist / daemon-tls / DirSandbox / SEC-1 *at syscalls: the diff is scoped to crates/daemon/sections/module_access/client_args.rs and crates/daemon/sections/capabilities.rs. The transfer crate revert is a temporary master-build unblock that gives back the 3-tuple IOERR_GENERAL propagation — UTS-16.b coverage is restored when the dropped deletion.rs half of fix: propagate ELOOP from sandboxed delete scan as IOERR_GENERAL #5620 relands.

Test plan

  • Build with cargo build --release on Linux aarch64 (the test host) and on macOS aarch64 (local) clean
  • runtests.py --use-tcp link-dest-module-escape link-dest-pathroot link-dest-relative-basis — all PASS
  • CI fmt+clippy / nextest / Windows / macOS / Linux musl green

@github-actions github-actions Bot added the bug Something isn't working label Jun 11, 2026
@oferchen
oferchen force-pushed the fix/uts-link-dest-relative-basis-daemon-receiver branch 2 times, most recently from f7ae309 to 4d96698 Compare June 11, 2026 18:00
oferchen added 5 commits June 11, 2026 21:30
PR #5620 ("propagate ELOOP from sandboxed delete scan as IOERR_GENERAL")
merged the caller-side changes in pipelined.rs and pipelined_incremental.rs
that unpack a 3-tuple including `io_bits`, but the deletion.rs body kept
returning a 2-tuple. Master is currently broken.

Revert just the caller-side 3-tuple unpacking so the build compiles
again. The IOERR_GENERAL surfacing on sandbox-rejected delete scans
(UTS-16.b) is temporarily disabled and tracked by the original PR.
…e root

Upstream rsync's daemon receiver evaluates relative basis paths
(`--link-dest=../01`) against the dest subdirectory: main.c:1199-1206
calls `check_alt_basis_dirs()` *after* `get_local_name(flist, argv[0])`
has chdir'd into the receiver's destination, so the generator's
`pathjoin(basis_dir[j], fname)` resolves with cwd = dest_dir.

oc-rsync does not chdir per connection; the daemon pre-resolved relative
ref_dirs against the module root instead. With dest=`mod/00/` and
`--link-dest=../01`, the resolver produced `mod/../01` (parent of the
module) instead of `mod/00/../01 = mod/01` (the in-module sibling the
client meant). Every basis lookup missed, the file was re-transferred,
and the link-dest-relative-basis / link-dest-pathroot / link-dest-module-
escape upstream tests reported "destination file missing" on push.

Pre-resolve relative ref_dirs against the receiver's positional dest
arg, lexically normalise the result so `..` segments collapse without
touching the filesystem, then confine the resolved path inside the
module root via `starts_with(canonicalised module path)`. Refused
basis dirs are silently dropped so the receiver re-transfers (matching
upstream's sanitize_path fallthrough) instead of leaking out-of-module
files via a hard link. URV-5.a.1.c absolute-path validation in
`validate_client_paths_in_module` is untouched: the daemon still
@errors on `--link-dest=/etc/passwd` before this code path runs.

Sender role keeps the module-root fallback so the legacy compare-dest
lookup path stays unchanged - the receiver is the only role that
actually evaluates basis_dir per file.
LSM-CAP at PR #5581 dropped every capability except CAP_CHOWN even when
the module worker ended up running as root - either because the module
declared `uid = 0` or because the module inherited the daemon-process
root identity (no per-module `uid` directive plus a global `uid = 0`,
the runtests.py default). Stripping CAP_DAC_OVERRIDE /
CAP_DAC_READ_SEARCH / CAP_FOWNER / CAP_FSETID leaves a root worker
unable to traverse a 750-mode user homedir on the path to the module
tree.

The link-dest-relative-basis / link-dest-pathroot / link-dest-module-
escape upstream tests put the daemon scratch under
`/home/<testuser>/rsync/testtmp/...` (homedir mode 750 owned by the
unprivileged developer). With LSM-CAP active the worker's first
`openat(.../bakmod, O_RDONLY|O_PATH)` returned EACCES at the homedir
component and the connection closed mid-handshake (exit 12,
"connection unexpectedly closed (0 bytes received so far)"). Same
EACCES bites any production daemon whose module path crosses a
non-root-readable component.

Short-circuit `drop_worker_capabilities` whenever the worker is still
root: either by the per-module `uid = Some(0)` directive, or by
inheriting root from a daemon that started as root and ran no
per-module privilege drop. Detect the inherited-root case via
`geteuid().is_root()` at drop time so the check survives any partial
setuid the privilege-drop path may have just performed. Workers with
an explicit non-zero `uid` keep the existing required-set drop -
setuid clears the effective set itself, so the explicit drop is a
belt-and-suspenders defense-in-depth measure (LSM-CAP design intent).

The change matches upstream rsync, which never drops capabilities from
a root daemon worker, while keeping LSM-CAP a defense-in-depth layer
for the unprivileged-uid case.
Master's delete_extraneous_files signature was updated to return
io::Result<(DeleteStats, bool, i32)> for the IOERR_GENERAL bit, but the
pipelined and pipelined_incremental receiver paths on this branch still
destructured the legacy 2-tuple. Adjust both call sites to capture the
io_bits and OR them into the transfer stats so flist + delete I/O errors
propagate to the goodbye phase.
The dedicated variable was only used to OR into stats.io_error; pipe
io_bits directly to avoid the unused_assignments lint.
@oferchen
oferchen force-pushed the fix/uts-link-dest-relative-basis-daemon-receiver branch from 4d96698 to ba95fae Compare June 11, 2026 18:30
@oferchen
oferchen merged commit dddb4d8 into master Jun 11, 2026
11 checks passed
@oferchen
oferchen deleted the fix/uts-link-dest-relative-basis-daemon-receiver branch June 12, 2026 14:39
oferchen added a commit that referenced this pull request Jun 14, 2026
#5778)

The daemon was rejecting client-supplied `--link-dest` / `--copy-dest` /
`--compare-dest` paths that resolved outside the module root with
`@ERROR: <flag> path '<path>' is outside module root`, breaking the
standalone link-dest / copy-dest interop fixtures on master. The CI
failure surfaced as `link-dest push failed (exit=0)` (the bash `if !`
negation masks the real upstream exit code) followed by
`UNEXPECTED FAIL: standalone:link-dest` and `standalone:copy-dest`.

Upstream rsync's daemon handles this case differently: `util1.c:1035
sanitize_path` collapses `..` segments against the module root depth
(rewriting `/abs/path` under `<module_dir>/abs/path`) and
`main.c:841 check_alt_basis_dirs` only warns when the resulting basis
is missing or out-of-tree. The transfer continues without the basis
optimisation; the receiver re-transfers instead of hard-linking.

Align with upstream: drop out-of-module absolute alt-basis paths
silently instead of aborting with `@ERROR`. The security goal is
preserved - the Landlock allowlist is not widened for out-of-module
paths, so the kernel still blocks accidental writes, and the
`cfg.reference_directories` retain_mut block strips the matching
entry so the receiver never sees the escape path.

Refactor: extract `confine_basis_under_module` so the lexical-normalise
plus canonicalise-with-fallback containment check is unit-testable.
Use it from both the relative and absolute branches of the
ref_dir retain.

Regression coverage:
- `confine_basis_drops_absolute_out_of_module` pins the silent-drop
  contract for the failing CI fixture shape.
- `confine_basis_drops_absolute_dotdot_escape_to_sibling` pins the
  exact `<module>/../linkdest-ref-daemon` shape from the failure log.
- `confine_basis_accepts_absolute_in_module` pins the companion
  in-module case so the Landlock widening continues to fire.
- `confine_basis_joins_relative_under_resolve_base` keeps the
  relative-basis contract from PR #5680 intact.

Verified manually in the rsync-profile container against upstream
rsync 3.4.1: both `--link-dest=<module>/../ref` and
`--copy-dest=<module>/../ref` now produce the expected destination
content with exit 0, matching the CI fixture expectations.

upstream: util1.c:1035 sanitize_path; main.c:841 check_alt_basis_dirs
oferchen added a commit that referenced this pull request Aug 24, 2026
…sts (#5680)

* fix(transfer): unblock master build by reverting dropped io_bits

PR #5620 ("propagate ELOOP from sandboxed delete scan as IOERR_GENERAL")
merged the caller-side changes in pipelined.rs and pipelined_incremental.rs
that unpack a 3-tuple including `io_bits`, but the deletion.rs body kept
returning a 2-tuple. Master is currently broken.

Revert just the caller-side 3-tuple unpacking so the build compiles
again. The IOERR_GENERAL surfacing on sandbox-rejected delete scans
(UTS-16.b) is temporarily disabled and tracked by the original PR.

* fix(daemon): resolve relative --link-dest against dest dir, not module root

Upstream rsync's daemon receiver evaluates relative basis paths
(`--link-dest=../01`) against the dest subdirectory: main.c:1199-1206
calls `check_alt_basis_dirs()` *after* `get_local_name(flist, argv[0])`
has chdir'd into the receiver's destination, so the generator's
`pathjoin(basis_dir[j], fname)` resolves with cwd = dest_dir.

oc-rsync does not chdir per connection; the daemon pre-resolved relative
ref_dirs against the module root instead. With dest=`mod/00/` and
`--link-dest=../01`, the resolver produced `mod/../01` (parent of the
module) instead of `mod/00/../01 = mod/01` (the in-module sibling the
client meant). Every basis lookup missed, the file was re-transferred,
and the link-dest-relative-basis / link-dest-pathroot / link-dest-module-
escape upstream tests reported "destination file missing" on push.

Pre-resolve relative ref_dirs against the receiver's positional dest
arg, lexically normalise the result so `..` segments collapse without
touching the filesystem, then confine the resolved path inside the
module root via `starts_with(canonicalised module path)`. Refused
basis dirs are silently dropped so the receiver re-transfers (matching
upstream's sanitize_path fallthrough) instead of leaking out-of-module
files via a hard link. URV-5.a.1.c absolute-path validation in
`validate_client_paths_in_module` is untouched: the daemon still
@errors on `--link-dest=/etc/passwd` before this code path runs.

Sender role keeps the module-root fallback so the legacy compare-dest
lookup path stays unchanged - the receiver is the only role that
actually evaluates basis_dir per file.

* fix(daemon): skip worker cap drop when worker runs as root

LSM-CAP at PR #5581 dropped every capability except CAP_CHOWN even when
the module worker ended up running as root - either because the module
declared `uid = 0` or because the module inherited the daemon-process
root identity (no per-module `uid` directive plus a global `uid = 0`,
the runtests.py default). Stripping CAP_DAC_OVERRIDE /
CAP_DAC_READ_SEARCH / CAP_FOWNER / CAP_FSETID leaves a root worker
unable to traverse a 750-mode user homedir on the path to the module
tree.

The link-dest-relative-basis / link-dest-pathroot / link-dest-module-
escape upstream tests put the daemon scratch under
`/home/<testuser>/rsync/testtmp/...` (homedir mode 750 owned by the
unprivileged developer). With LSM-CAP active the worker's first
`openat(.../bakmod, O_RDONLY|O_PATH)` returned EACCES at the homedir
component and the connection closed mid-handshake (exit 12,
"connection unexpectedly closed (0 bytes received so far)"). Same
EACCES bites any production daemon whose module path crosses a
non-root-readable component.

Short-circuit `drop_worker_capabilities` whenever the worker is still
root: either by the per-module `uid = Some(0)` directive, or by
inheriting root from a daemon that started as root and ran no
per-module privilege drop. Detect the inherited-root case via
`geteuid().is_root()` at drop time so the check survives any partial
setuid the privilege-drop path may have just performed. Workers with
an explicit non-zero `uid` keep the existing required-set drop -
setuid clears the effective set itself, so the explicit drop is a
belt-and-suspenders defense-in-depth measure (LSM-CAP design intent).

The change matches upstream rsync, which never drops capabilities from
a root daemon worker, while keeping LSM-CAP a defense-in-depth layer
for the unprivileged-uid case.

* fix(transfer): restore 3-tuple destructuring for delete_extraneous_files

Master's delete_extraneous_files signature was updated to return
io::Result<(DeleteStats, bool, i32)> for the IOERR_GENERAL bit, but the
pipelined and pipelined_incremental receiver paths on this branch still
destructured the legacy 2-tuple. Adjust both call sites to capture the
io_bits and OR them into the transfer stats so flist + delete I/O errors
propagate to the goodbye phase.

* fix(transfer): drop intermediate delete_io_error binding

The dedicated variable was only used to OR into stats.io_error; pipe
io_bits directly to avoid the unused_assignments lint.
oferchen added a commit that referenced this pull request Aug 24, 2026
#5778)

The daemon was rejecting client-supplied `--link-dest` / `--copy-dest` /
`--compare-dest` paths that resolved outside the module root with
`@ERROR: <flag> path '<path>' is outside module root`, breaking the
standalone link-dest / copy-dest interop fixtures on master. The CI
failure surfaced as `link-dest push failed (exit=0)` (the bash `if !`
negation masks the real upstream exit code) followed by
`UNEXPECTED FAIL: standalone:link-dest` and `standalone:copy-dest`.

Upstream rsync's daemon handles this case differently: `util1.c:1035
sanitize_path` collapses `..` segments against the module root depth
(rewriting `/abs/path` under `<module_dir>/abs/path`) and
`main.c:841 check_alt_basis_dirs` only warns when the resulting basis
is missing or out-of-tree. The transfer continues without the basis
optimisation; the receiver re-transfers instead of hard-linking.

Align with upstream: drop out-of-module absolute alt-basis paths
silently instead of aborting with `@ERROR`. The security goal is
preserved - the Landlock allowlist is not widened for out-of-module
paths, so the kernel still blocks accidental writes, and the
`cfg.reference_directories` retain_mut block strips the matching
entry so the receiver never sees the escape path.

Refactor: extract `confine_basis_under_module` so the lexical-normalise
plus canonicalise-with-fallback containment check is unit-testable.
Use it from both the relative and absolute branches of the
ref_dir retain.

Regression coverage:
- `confine_basis_drops_absolute_out_of_module` pins the silent-drop
  contract for the failing CI fixture shape.
- `confine_basis_drops_absolute_dotdot_escape_to_sibling` pins the
  exact `<module>/../linkdest-ref-daemon` shape from the failure log.
- `confine_basis_accepts_absolute_in_module` pins the companion
  in-module case so the Landlock widening continues to fire.
- `confine_basis_joins_relative_under_resolve_base` keeps the
  relative-basis contract from PR #5680 intact.

Verified manually in the rsync-profile container against upstream
rsync 3.4.1: both `--link-dest=<module>/../ref` and
`--copy-dest=<module>/../ref` now produce the expected destination
content with exit 0, matching the CI fixture expectations.

upstream: util1.c:1035 sanitize_path; main.c:841 check_alt_basis_dirs
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