Skip to content

fix(daemon): silently drop out-of-module --link-dest/--copy-dest paths - #5778

Merged
oferchen merged 1 commit into
masterfrom
fix/daemon-link-dest-outside-module-noop
Jun 14, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/daemon-link-dest-outside-module-noop

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • 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 (UNEXPECTED FAIL: standalone:link-dest / standalone:copy-dest, surfacing as link-dest push failed (exit=0) where the bash if ! negation masks the real upstream exit code).
  • Upstream rsync handles this differently: util1.c:1035 sanitize_path rewrites the path under the module root 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.
  • Align with upstream: drop out-of-module absolute alt-basis paths silently instead of aborting. The Landlock allowlist is still not widened for those paths so the kernel security guarantee is preserved, and the cfg.reference_directories retain block strips the 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 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

  • Build oc-rsync release in rsync-profile container against this branch.
  • Reproduce upstream rsync -av --link-dest=<dest>/../ref <src>/ rsync://daemon/interop end-to-end; daemon now accepts the basis and all destination files match the source. Same for --copy-dest.
  • Add 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.
  • CI interop / interop with upstream rsync job goes green for standalone:link-dest and standalone:copy-dest.
  • CI nextest (stable) green across the new daemon unit tests.

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
oferchen merged commit 96f7fe4 into master Jun 14, 2026
10 of 11 checks passed
@oferchen
oferchen deleted the fix/daemon-link-dest-outside-module-noop branch June 14, 2026 11:57
@github-actions github-actions Bot added the bug Something isn't working label Jun 14, 2026
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`.
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