Repository navigation
fix: pass upstream link-dest-relative-basis/pathroot/module-escape tests - #5680
Merged
oferchen merged 5 commits intoJun 11, 2026
Merged
Conversation
oferchen
force-pushed
the
fix/uts-link-dest-relative-basis-daemon-receiver
branch
2 times, most recently
from
June 11, 2026 18:00
f7ae309 to
4d96698
Compare
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
force-pushed
the
fix/uts-link-dest-relative-basis-daemon-receiver
branch
from
June 11, 2026 18:30
4d96698 to
ba95fae
Compare
3 of 5 tasks
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three commits, two distinct root causes, one PR because both regressions had to clear for the failing upstream tests to pass:
deletion.rsbody 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.--link-dest=../01against the module root instead of the dest subdirectory, producingmod/../01(parent of module) instead ofmod/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).drop_worker_capabilitieswhenever the worker is root — by explicituid = 0or by inheriting root from the daemon process (no per-moduleuiddirective plus a daemon-wide root identity). Matches upstream rsync's behaviour.Reproduced first
Linux host:
runtests.py --use-tcpagainstoc-rsyncdaemon. Three tests reproduce on master: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:
Security guarantees preserved
validate_client_paths_in_module): absolute--copy-dest/--link-dest/--compare-destpaths that escape the module root still get an@ERRORreply before this code path runs...segments and runsstarts_with(canonicalised module root); thelink-dest-module-escapetest exercises the../../OUTSIDEclimb and confirms the basis is silently dropped (file re-transferred, not hard-linked to the OUTSIDE secret).crates/daemon/sections/module_access/client_args.rsandcrates/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 droppeddeletion.rshalf of fix: propagate ELOOP from sandboxed delete scan as IOERR_GENERAL #5620 relands.Test plan
cargo build --releaseon Linux aarch64 (the test host) and on macOS aarch64 (local) cleanruntests.py --use-tcp link-dest-module-escape link-dest-pathroot link-dest-relative-basis— all PASS