Skip to content

fix: apply munge symlinks prefix/strip in transfer paths - #5527

Merged
oferchen merged 3 commits into
masterfrom
fix/uts-11-daemon-munge-symlinks
Jun 10, 2026
Merged

oferchen merged 3 commits into
masterfrom
fix/uts-11-daemon-munge-symlinks

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Task UTS-11 (#3574). The daemon's munge symlinks directive was parsed and
stored on ModuleDefinition::munge_symlinks: Option<bool>, but the actual
prefix/strip transform was missing from the transfer path. Push and pull
through a module configured with munge symlinks = yes silently bypassed
upstream's anti-escape guard - the on-disk symlink written by the receiver
never carried the /rsyncd-munged/ prefix, and the sender never stripped
it when reading source symlinks.

  • Wire ModuleRuntime::effective_munge_symlinks() into
    ServerConfig.munge_symlinks alongside the existing fake_super wiring
    (crates/daemon/src/daemon/sections/module_access/client_args.rs:292-297).
  • Sender: strip the prefix in GeneratorContext::create_entry after
    read_link() so the wire target matches the unmunged source path
    (crates/transfer/src/generator/file_list/entry.rs:82-94, 375-407).
  • Receiver: prepend the prefix in ReceiverContext::create_symlinks before
    the symlinkat write so the quick-check comparison and the create syscall
    both see the munged form
    (crates/transfer/src/receiver/directory/links.rs:75-86, 444-465).

Upstream reference

  • clientserver.c:992-1004 - daemon resolves munge_symlinks from
    lp_munge_symlinks() and the !use_chroot || module_dirlen auto default.
  • flist.c:222-226 - sender strips SYMLINK_PREFIX after readlink(),
    guarded by llen > SYMLINK_PREFIX_LEN.
  • flist.c:1122-1126 - receiver prepends SYMLINK_PREFIX to the wire
    target when storing the symlink in the file list.
  • rsync.h:36 - #define SYMLINK_PREFIX "/rsyncd-munged/" (15 bytes).

The strip helper mirrors the strict llen > SYMLINK_PREFIX_LEN guard so a
target whose entire content is the 15-byte prefix passes through
unchanged - matching upstream's strncmp branch byte-for-byte. The
receiver-side prepend uses OsStrExt::as_bytes on Unix so non-UTF-8
targets keep their raw bytes; the safe-link check continues to evaluate
the pre-munge wire target so the policy decision matches upstream
ordering.

Wiring audit findings

  • ModuleDefinition::munge_symlinks: Option<bool> and
    effective_munge_symlinks() (auto = !use_chroot) were already in
    place at crates/daemon/src/daemon/module_state/definition.rs:54-56, 273-275.
  • metadata::munge_symlink / unmunge_symlink /
    SYMLINK_MUNGE_PREFIX were already exported and exercised by the
    local-copy executor at
    crates/engine/src/local_copy/executor/special/symlink.rs:120-150, 402-409.
  • The missing wiring was the bridge between the parsed daemon directive
    and the transfer layer (ServerConfig.munge_symlinks + sender/receiver
    call sites).

Cross-platform

  • The receiver prefix helper is gated #[cfg(unix)]; the matching
    create_symlinks is already Unix-only with a no-op fallback for
    Windows.
  • The sender strip is portable: on Unix it operates on the raw OsStr
    bytes; on non-Unix it falls back to UTF-8 since read_link already
    rejects non-UTF-8 paths on those platforms.

Test plan

  • crates/transfer/src/generator/file_list/entry.rs::munge_strip_tests
    • prefix passes through when disabled
    • prefix stripped when enabled
    • unprefixed target untouched when enabled
    • exact-prefix target untouched (matches upstream's strict > guard)
  • crates/transfer/src/generator/file_list/entry.rs::munge_symlinks_tests
    • sender strips /rsyncd-munged/ before encoding the file list entry
    • sender preserves the prefix verbatim when munging is disabled
  • crates/transfer/src/receiver/tests/munge_symlinks.rs
    • receiver writes a prefixed symlink to disk when munging is enabled
    • receiver writes the wire target verbatim when munging is disabled
  • CI: fmt + clippy + nextest stable across Linux/macOS/Windows/musl.
  • CI: interop suite confirms no regression on existing
    daemon_safe_links_receive test (uses munge symlinks = false).

@github-actions github-actions Bot added the bug Something isn't working label Jun 10, 2026
oferchen added 3 commits June 10, 2026 14:10
Daemon modules with `munge symlinks = yes` were parsed correctly but the
prefix/strip logic was missing from the transfer path. The on-disk symlink
written by the receiver never carried the `/rsyncd-munged/` prefix, and the
sender never stripped it when reading source symlinks, so a push/pull
through the daemon silently bypassed upstream's anti-escape guard.

Wire the daemon's `effective_munge_symlinks()` into `ServerConfig`, strip
the prefix in `GeneratorContext::create_entry` after `read_link()`, and
prepend it in `ReceiverContext::create_symlinks` before the `symlinkat`
write so the quick-check comparison and the create syscall both see the
munged form.

Upstream reference:
- `clientserver.c:992-1004` - daemon resolves `munge_symlinks` from
  `lp_munge_symlinks()` and `!use_chroot` auto default
- `flist.c:222-226` - sender strips `SYMLINK_PREFIX` after `readlink()`
- `flist.c:1122-1126` - receiver prepends `SYMLINK_PREFIX` to wire target
- `rsync.h:36` - `SYMLINK_PREFIX "/rsyncd-munged/"` (15 bytes)

Strict-length guard mirrors `llen > SYMLINK_PREFIX_LEN` so a target whose
entire content is the prefix passes through unchanged. Receiver-side
prefix helper preserves non-UTF-8 bytes on Unix via `OsStrExt`; safe-link
evaluation continues to run against the pre-munge wire target so the
policy decision matches upstream ordering.

Regression tests cover both directions on Unix: receiver writes the
prefixed target to disk, sender restores the original target after
`readlink()`, plus negative controls verifying the bit is strictly
opt-in.
The up:symlinks standalone test sets `use chroot = false` without an
explicit `munge symlinks` directive. With munge-symlinks now wired into
the transfer path, the auto-default of `!use_chroot` enables munging and
the receiver writes `/rsyncd-munged/target.txt` instead of `target.txt`.
This mirrors upstream's clientserver.c:992-1004 policy:

    if ((munge_symlinks = lp_munge_symlinks(module_id)) < 0)
        munge_symlinks = !use_chroot || module_dirlen;

The parallel oc:symlinks test already sets `munge symlinks = false`
against the upstream daemon for the same reason. Match that config on
the oc-rsync daemon side so both directions exercise the non-munged
path.
The comprehensive interop daemon config used 'use chroot = false' without an explicit 'munge symlinks' directive. Under upstream's auto default (!use_chroot || module_dirlen) this resolves to munging on, so symlink fixtures arrived as /rsyncd-munged/hello.txt on the receiver and failed the up:symlinks / up:inc-recursive-symlinks quick-check against the source's bare hello.txt. Pin the directive to false so the shared rust daemon config matches the upstream sibling helper and the standalone symlink test configs already do.

upstream: clientserver.c:992-993 - munge_symlinks = !use_chroot when the per-module directive is unset.
@oferchen
oferchen force-pushed the fix/uts-11-daemon-munge-symlinks branch from ed519d7 to f424304 Compare June 10, 2026 11:10
@oferchen
oferchen merged commit c1de068 into master Jun 10, 2026
1 of 9 checks passed
@oferchen
oferchen deleted the fix/uts-11-daemon-munge-symlinks branch June 10, 2026 11:13
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix: apply munge symlinks prefix/strip in transfer paths

Daemon modules with `munge symlinks = yes` were parsed correctly but the
prefix/strip logic was missing from the transfer path. The on-disk symlink
written by the receiver never carried the `/rsyncd-munged/` prefix, and the
sender never stripped it when reading source symlinks, so a push/pull
through the daemon silently bypassed upstream's anti-escape guard.

Wire the daemon's `effective_munge_symlinks()` into `ServerConfig`, strip
the prefix in `GeneratorContext::create_entry` after `read_link()`, and
prepend it in `ReceiverContext::create_symlinks` before the `symlinkat`
write so the quick-check comparison and the create syscall both see the
munged form.

Upstream reference:
- `clientserver.c:992-1004` - daemon resolves `munge_symlinks` from
  `lp_munge_symlinks()` and `!use_chroot` auto default
- `flist.c:222-226` - sender strips `SYMLINK_PREFIX` after `readlink()`
- `flist.c:1122-1126` - receiver prepends `SYMLINK_PREFIX` to wire target
- `rsync.h:36` - `SYMLINK_PREFIX "/rsyncd-munged/"` (15 bytes)

Strict-length guard mirrors `llen > SYMLINK_PREFIX_LEN` so a target whose
entire content is the prefix passes through unchanged. Receiver-side
prefix helper preserves non-UTF-8 bytes on Unix via `OsStrExt`; safe-link
evaluation continues to run against the pre-munge wire target so the
policy decision matches upstream ordering.

Regression tests cover both directions on Unix: receiver writes the
prefixed target to disk, sender restores the original target after
`readlink()`, plus negative controls verifying the bit is strictly
opt-in.

* test: set munge symlinks = false in up:symlinks interop config

The up:symlinks standalone test sets `use chroot = false` without an
explicit `munge symlinks` directive. With munge-symlinks now wired into
the transfer path, the auto-default of `!use_chroot` enables munging and
the receiver writes `/rsyncd-munged/target.txt` instead of `target.txt`.
This mirrors upstream's clientserver.c:992-1004 policy:

    if ((munge_symlinks = lp_munge_symlinks(module_id)) < 0)
        munge_symlinks = !use_chroot || module_dirlen;

The parallel oc:symlinks test already sets `munge symlinks = false`
against the upstream daemon for the same reason. Match that config on
the oc-rsync daemon side so both directions exercise the non-munged
path.

* test: disable munge symlinks in shared rust daemon interop config

The comprehensive interop daemon config used 'use chroot = false' without an explicit 'munge symlinks' directive. Under upstream's auto default (!use_chroot || module_dirlen) this resolves to munging on, so symlink fixtures arrived as /rsyncd-munged/hello.txt on the receiver and failed the up:symlinks / up:inc-recursive-symlinks quick-check against the source's bare hello.txt. Pin the directive to false so the shared rust daemon config matches the upstream sibling helper and the standalone symlink test configs already do.

upstream: clientserver.c:992-993 - munge_symlinks = !use_chroot when the per-module directive is unset.
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