Skip to content

fix(transfer): parse compact -K to honour --keep-dirlinks on receiver - #5853

Merged
oferchen merged 1 commit into
masterfrom
fix/uts-symlink-dirlink-basis-multibasis-precedence
Jun 17, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/uts-symlink-dirlink-basis-multibasis-precedence

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

The server-side compact flag parser silently dropped the K byte the client emits whenever --keep-dirlinks is active. With the flag absent from ParsedServerFlags, the receiver constructed MetadataOptions with keep_dirlinks: false, so the dirfd-anchored chmod bypass added in PR #5793 never engaged: every per-file chmod through a destination dir-symlink ($HOME/dir/file when dir -> real-dir) was refused with ELOOP/ENOTDIR before any delta could land. Every basis-symlink scenario in testsuite/symlink-dirlink-basis.test (Issue #715, eight topologies covering basic / nested / --backup / --inplace / top-level / proto-28 / --partial-dir) bottoms out on this same gap.

Root cause

crates/transfer/src/flags.rs mapped every transfer byte except K and k to a structured field. The unknown-byte catch-all swallowed both, so flags.keep_dirlinks was permanently false no matter what the client sent.

Downstream, crates/transfer/src/receiver/transfer/setup.rs built MetadataOptions from self.config.flags without calling with_keep_dirlinks. Even after fixing the parser, the receiver would still take the strict chmod path because the bypass is gated on options.keep_dirlinks().

Fix

  1. Add keep_dirlinks: bool (and copy_dirlinks: bool for parity with the sender-side k) to ParsedServerFlags.
  2. Decode K and k in parse_transfer_flag with upstream: options.c:687,688 references.
  3. Chain .with_keep_dirlinks(self.config.flags.keep_dirlinks) into the receiver's MetadataOptions construction so chmod_path_honoring_keep_dirlinks (crates/metadata/src/apply/permissions.rs:451) routes past the dirfd sandbox when the symlinked parent would otherwise surface ELOOP/ENOTDIR.

The default code path (--keep-dirlinks off) is unchanged: secure_chmod_at and the dirfd sandbox keep the SEC-1 / CVE-29518 guard intact for every other transfer.

Upstream reference

  • options.c:688 {"keep-dirlinks", 'K', POPT_ARG_NONE, &keep_dirlinks, 0, 0, 0}
  • generator.c:1344 link_stat(fname, &sx.st, keep_dirlinks && is_dir)

Test plan

  • New unit tests parses_keep_dirlinks_flag, keep_dirlinks_not_set_by_default, and parses_copy_dirlinks_flag pin the new bytes in the compact server flag parser.
  • Upstream Testsuite job runs testsuite/symlink-dirlink-basis.test end-to-end (all eight topologies) over lsh.sh. Marked DRAFT pending that signal.
  • Existing keep_dirlinks_bypasses_secure_chmod_sandbox and keep_dirlinks_bypass_is_cross_platform_safe in crates/metadata/src/apply/tests.rs continue to assert the bypass landing site is wired correctly.
  • CI verifies fmt, clippy, and the full nextest matrix on Linux / macOS / Windows.

@github-actions github-actions Bot added the bug Something isn't working label Jun 16, 2026
@oferchen
oferchen force-pushed the fix/uts-symlink-dirlink-basis-multibasis-precedence branch 3 times, most recently from 1e3812e to a27baba Compare June 17, 2026 09:43
@oferchen
oferchen marked this pull request as ready for review June 17, 2026 12:38
The server-side compact flag parser silently dropped the 'K' byte the
client emits whenever `--keep-dirlinks` is active. With the flag absent
from `ParsedServerFlags`, the receiver constructed `MetadataOptions`
with `keep_dirlinks: false`, so the dirfd-anchored chmod bypass added
in PR #5793 never engaged: every per-file chmod through a destination
dir-symlink (`$HOME/dir/file` when `dir -> real-dir`) was refused with
ELOOP/ENOTDIR before any delta could land. Every basis-symlink scenario
in `testsuite/symlink-dirlink-basis.test` (Issue #715, eight topologies
covering basic / nested / --backup / --inplace / top-level / proto-28
/ --partial-dir) bottoms out on this same gap.

Wire `K` and `k` into the compact flag parser and propagate the parsed
`keep_dirlinks` into the receiver's `MetadataOptions` via
`with_keep_dirlinks`, matching upstream `generator.c:1344`'s
`link_stat(fname, &sx.st, keep_dirlinks && is_dir)`.

upstream: options.c:688 / generator.c:1344
@oferchen
oferchen force-pushed the fix/uts-symlink-dirlink-basis-multibasis-precedence branch from 3ab5166 to dd90821 Compare June 17, 2026 12:39
@oferchen
oferchen merged commit 49316d2 into master Jun 17, 2026
8 of 9 checks passed
@oferchen
oferchen deleted the fix/uts-symlink-dirlink-basis-multibasis-precedence branch June 17, 2026 12:50
oferchen added a commit that referenced this pull request Jun 17, 2026
Pins the receiver-side wiring that the upstream rsync 3.4.4 testsuite
`symlink-dirlink-basis` test exercises against -K/--keep-dirlinks. The
chmod dirfd-sandbox bypass (#5793) plus the compact `K` flag parser
wire-up (#5853) close the failure; this test file is the regression
coverage for both halves together.

Each test mirrors one of the eight Test N scenarios in
`testsuite/symlink-dirlink-basis.test` (Issue #715): basic, compressed,
nested, --backup, --inplace, top-level (negative control), proto28
--partial-dir, and proto28 basic. The negative control catches a
parser regression that would silently set keep_dirlinks for the
non-symlinked top-level case.

Pins both halves of the chain:
- ParsedServerFlags::parse recognises the compact `K` byte from the
  server-side flag string the client emits in every topology.
- The parsed flag survives MetadataOptions::with_keep_dirlinks, which
  is what chmod_path_honoring_keep_dirlinks consults at apply time.

Upstream sources of truth:
- target/interop/upstream-src/rsync-3.4.4/testsuite/symlink-dirlink-basis.test
- target/interop/upstream-src/rsync-3.4.1/options.c:688 (-K mapping)
- target/interop/upstream-src/rsync-3.4.1/generator.c:1344
  (link_stat(fname, &sx.st, keep_dirlinks && is_dir))
oferchen added a commit that referenced this pull request Jun 17, 2026
Pins the receiver-side wiring that the upstream rsync 3.4.4 testsuite
`symlink-dirlink-basis` test exercises against -K/--keep-dirlinks. The
chmod dirfd-sandbox bypass (#5793) plus the compact `K` flag parser
wire-up (#5853) close the failure; this test file is the regression
coverage for both halves together.

Each test mirrors one of the eight Test N scenarios in
`testsuite/symlink-dirlink-basis.test` (Issue #715): basic, compressed,
nested, --backup, --inplace, top-level (negative control), proto28
--partial-dir, and proto28 basic. The negative control catches a
parser regression that would silently set keep_dirlinks for the
non-symlinked top-level case.

Pins both halves of the chain:
- ParsedServerFlags::parse recognises the compact `K` byte from the
  server-side flag string the client emits in every topology.
- The parsed flag survives MetadataOptions::with_keep_dirlinks, which
  is what chmod_path_honoring_keep_dirlinks consults at apply time.

Upstream sources of truth:
- target/interop/upstream-src/rsync-3.4.4/testsuite/symlink-dirlink-basis.test
- target/interop/upstream-src/rsync-3.4.1/options.c:688 (-K mapping)
- target/interop/upstream-src/rsync-3.4.1/generator.c:1344
  (link_stat(fname, &sx.st, keep_dirlinks && is_dir))
oferchen added a commit that referenced this pull request Jun 17, 2026
… (#5871)

Pins the receiver-side wiring that the upstream rsync 3.4.4 testsuite
`symlink-dirlink-basis` test exercises against -K/--keep-dirlinks. The
chmod dirfd-sandbox bypass (#5793) plus the compact `K` flag parser
wire-up (#5853) close the failure; this test file is the regression
coverage for both halves together.

Each test mirrors one of the eight Test N scenarios in
`testsuite/symlink-dirlink-basis.test` (Issue #715): basic, compressed,
nested, --backup, --inplace, top-level (negative control), proto28
--partial-dir, and proto28 basic. The negative control catches a
parser regression that would silently set keep_dirlinks for the
non-symlinked top-level case.

Pins both halves of the chain:
- ParsedServerFlags::parse recognises the compact `K` byte from the
  server-side flag string the client emits in every topology.
- The parsed flag survives MetadataOptions::with_keep_dirlinks, which
  is what chmod_path_honoring_keep_dirlinks consults at apply time.

Upstream sources of truth:
- target/interop/upstream-src/rsync-3.4.4/testsuite/symlink-dirlink-basis.test
- target/interop/upstream-src/rsync-3.4.1/options.c:688 (-K mapping)
- target/interop/upstream-src/rsync-3.4.1/generator.c:1344
  (link_stat(fname, &sx.st, keep_dirlinks && is_dir))
oferchen added a commit that referenced this pull request Aug 24, 2026
…#5853)

The server-side compact flag parser silently dropped the 'K' byte the
client emits whenever `--keep-dirlinks` is active. With the flag absent
from `ParsedServerFlags`, the receiver constructed `MetadataOptions`
with `keep_dirlinks: false`, so the dirfd-anchored chmod bypass added
in PR #5793 never engaged: every per-file chmod through a destination
dir-symlink (`$HOME/dir/file` when `dir -> real-dir`) was refused with
ELOOP/ENOTDIR before any delta could land. Every basis-symlink scenario
in `testsuite/symlink-dirlink-basis.test` (Issue #715, eight topologies
covering basic / nested / --backup / --inplace / top-level / proto-28
/ --partial-dir) bottoms out on this same gap.

Wire `K` and `k` into the compact flag parser and propagate the parsed
`keep_dirlinks` into the receiver's `MetadataOptions` via
`with_keep_dirlinks`, matching upstream `generator.c:1344`'s
`link_stat(fname, &sx.st, keep_dirlinks && is_dir)`.

upstream: options.c:688 / generator.c:1344
oferchen added a commit that referenced this pull request Aug 24, 2026
… (#5871)

Pins the receiver-side wiring that the upstream rsync 3.4.4 testsuite
`symlink-dirlink-basis` test exercises against -K/--keep-dirlinks. The
chmod dirfd-sandbox bypass (#5793) plus the compact `K` flag parser
wire-up (#5853) close the failure; this test file is the regression
coverage for both halves together.

Each test mirrors one of the eight Test N scenarios in
`testsuite/symlink-dirlink-basis.test` (Issue #715): basic, compressed,
nested, --backup, --inplace, top-level (negative control), proto28
--partial-dir, and proto28 basic. The negative control catches a
parser regression that would silently set keep_dirlinks for the
non-symlinked top-level case.

Pins both halves of the chain:
- ParsedServerFlags::parse recognises the compact `K` byte from the
  server-side flag string the client emits in every topology.
- The parsed flag survives MetadataOptions::with_keep_dirlinks, which
  is what chmod_path_honoring_keep_dirlinks consults at apply time.

Upstream sources of truth:
- target/interop/upstream-src/rsync-3.4.4/testsuite/symlink-dirlink-basis.test
- target/interop/upstream-src/rsync-3.4.1/options.c:688 (-K mapping)
- target/interop/upstream-src/rsync-3.4.1/generator.c:1344
  (link_stat(fname, &sx.st, keep_dirlinks && is_dir))
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