Repository navigation
fix(daemon): silently drop out-of-module --link-dest/--copy-dest paths - #5778
Merged
Merged
Conversation
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
1 of 3 tasks
oferchen
added a commit
that referenced
this pull request
Jun 17, 2026
Pin the daemon's `--link-dest` / `--copy-dest` / `--compare-dest` path-validation invariant against four module-escape scenarios drawn from the upstream `alt-dest-symlink-race.test` / `link-dest-module- escape` security pin: - relative `--link-dest=../etc/passwd` from a dest at the module root must be silently dropped (lexical climb past the module root); - relative in-module sibling `--link-dest=../01` from `dest/00/` must survive as a legitimate basis (positive control matching upstream `main.c:1199-1206`); - an in-module symlink `mod/cd -> /outside` used as `--link-dest=cd` must canonicalise out of the module root and be dropped (the exact attack shape from upstream `alt-dest-symlink-race.test`); - an absolute `--link-dest` pointing outside the module root must be dropped (canonicalise-with-lexical-fallback branch). The tests exercise `confine_basis_under_module`, the daemon-side defence introduced in PR #5778 / extended via URV-5.b.1.c. They lock in the silent-drop contract upstream `util1.c:1035 sanitize_path` and `main.c:841 check_alt_basis_dirs` model, guarding against a future regression to either a hard `@ERROR` reject or admission of the escape into `cfg.reference_directories`.
oferchen
added a commit
that referenced
this pull request
Jun 17, 2026
Pin the daemon's `--link-dest` / `--copy-dest` / `--compare-dest` path-validation invariant against four module-escape scenarios drawn from the upstream `alt-dest-symlink-race.test` / `link-dest-module- escape` security pin: - relative `--link-dest=../etc/passwd` from a dest at the module root must be silently dropped (lexical climb past the module root); - relative in-module sibling `--link-dest=../01` from `dest/00/` must survive as a legitimate basis (positive control matching upstream `main.c:1199-1206`); - an in-module symlink `mod/cd -> /outside` used as `--link-dest=cd` must canonicalise out of the module root and be dropped (the exact attack shape from upstream `alt-dest-symlink-race.test`); - an absolute `--link-dest` pointing outside the module root must be dropped (canonicalise-with-lexical-fallback branch). The tests exercise `confine_basis_under_module`, the daemon-side defence introduced in PR #5778 / extended via URV-5.b.1.c. They lock in the silent-drop contract upstream `util1.c:1035 sanitize_path` and `main.c:841 check_alt_basis_dirs` model, guarding against a future regression to either a hard `@ERROR` reject or admission of the escape into `cfg.reference_directories`.
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
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Pin the daemon's `--link-dest` / `--copy-dest` / `--compare-dest` path-validation invariant against four module-escape scenarios drawn from the upstream `alt-dest-symlink-race.test` / `link-dest-module- escape` security pin: - relative `--link-dest=../etc/passwd` from a dest at the module root must be silently dropped (lexical climb past the module root); - relative in-module sibling `--link-dest=../01` from `dest/00/` must survive as a legitimate basis (positive control matching upstream `main.c:1199-1206`); - an in-module symlink `mod/cd -> /outside` used as `--link-dest=cd` must canonicalise out of the module root and be dropped (the exact attack shape from upstream `alt-dest-symlink-race.test`); - an absolute `--link-dest` pointing outside the module root must be dropped (canonicalise-with-lexical-fallback branch). The tests exercise `confine_basis_under_module`, the daemon-side defence introduced in PR #5778 / extended via URV-5.b.1.c. They lock in the silent-drop contract upstream `util1.c:1035 sanitize_path` and `main.c:841 check_alt_basis_dirs` model, guarding against a future regression to either a hard `@ERROR` reject or admission of the escape into `cfg.reference_directories`.
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
--link-dest/--copy-dest/--compare-destpaths 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 (UNEXPECTED FAIL: standalone:link-dest/standalone:copy-dest, surfacing aslink-dest push failed (exit=0)where the bashif !negation masks the real upstream exit code).util1.c:1035 sanitize_pathrewrites the path under the module root andmain.c:841 check_alt_basis_dirsonly warns when the resulting basis is missing or out-of-tree. The transfer continues without the basis optimisation.cfg.reference_directoriesretain block strips the entry so the receiver never sees the escape path.confine_basis_under_moduleso the lexical-normalise plus canonicalise-with-fallback containment check is unit-testable and shared between the relative and absolute branches of the ref_dir retain.Root cause
PR #5680 introduced a hard-reject for any
--link-dest/--copy-dest/ etc. path whose canonical form did not start with the module root. The standalone interop fixtures (tools/ci/run_interop.sh::test_link_dest,test_copy_dest) legitimately point at a sibling of the module path (${dest}/../linkdest-ref-daemon), which canonicalises outside the module root and so triggered the reject. Upstream rsync never aborts on this path - it sanitises the basis into a module-internal location and warns when the result is missing, leaving the transfer to fall through to a normal copy. The fix drops the reject and follows that contract.Test plan
rsync-profilecontainer against this branch.rsync -av --link-dest=<dest>/../ref <src>/ rsync://daemon/interopend-to-end; daemon now accepts the basis and all destination files match the source. Same for--copy-dest.confine_basis_*unit tests covering the silent-drop contract for the absolute out-of-module case, the..sibling escape shape from the failure log, the in-module Landlock-widening case, and the relative-basis contract from PR fix: pass upstream link-dest-relative-basis/pathroot/module-escape tests #5680.interop / interop with upstream rsyncjob goes green forstandalone:link-destandstandalone:copy-dest.nextest (stable)green across the new daemon unit tests.