Skip to content

fix(receiver): honour --force so a populated directory obstacle is cleared - #7625

Merged
oferchen merged 5 commits into
masterfrom
fix/force-del-recurse-obstacle
Sep 2, 2026
Merged

oferchen merged 5 commits into
masterfrom
fix/force-del-recurse-obstacle

Conversation

@oferchen

@oferchen oferchen commented Sep 2, 2026 •

Copy link
Copy Markdown
Owner

What upstream does

generator.c:1629 (recv_generator, feeding the DEL_FOR_FILE removal at :2149) and generator.c:2481 (atomic_create) both compute

int del_opts = delete_mode || force_delete ? DEL_RECURSE : 0;

and hand it to delete_item(), which passes it straight to delete_dir_contents(). With DEL_RECURSE the contents of a directory standing where a non-directory has to be written are removed and the directory is rmdir'd; without it the same call only probes emptiness (delete.c:115-118) and returns DR_NOT_EMPTY.

The recursion strips DEL_MAKE_ROOM (delete.c:126-127), so every child reaches the log_delete() / stats.deleted_* block at delete.c:241-256 and is itemized, counted, backed up under --backup and capped by --max-delete like a delete-pass victim - while the obstacle directory itself keeps the flag and stays silent and uncounted.

The same force_delete is the second term of the write_del_stats() gate at generator.c:2868 and :2913, and server_options() forwards the flag as a long arg at options.c:3014-3015.

What oc did

--force never reached a consumer:

  • the stdio server arg parser recognised it and threw it away ("--force" => {}), with no field on ParsedServerFlags;
  • the daemon's own long-form parser (apply_long_form_args) had no arm for it at all - a second parser, a second silent drop;
  • a pull never bridged ClientConfig::force_replacements() onto the local receiver config;
  • and the obstacle arm never consulted flags.delete either, so it always took the bare-rmdir branch.

MEASURED against the pinned rsync 3.5.0 over a real --server child (source symlink, destination a populated directory):

flags rsync 3.5.0 oc before oc after
(none) 23, refused 23 23
--force 0, replaced 23 0, replaced
--delete 0, replaced 23 0, replaced
--force --delete 0, replaced 23 0, replaced

Under -v --stats, 3.5.0 prints one deleting obstacle/occupant and reports Number of deleted files: 1 (reg: 1). oc now matches.

The fix

  • ParsedServerFlags::force, set by both server-arg parsers and bridged onto the local receiver on a pull through apply_common_server_flags (on a pull the client itself is the receiver, so the flag it forwards to the remote sender must also land locally).
  • One owner for the rule: ReceiverContext::del_recurse() is upstream's expression verbatim, and clear_obstacle_dir_contents is the only recursion. It reuses the delete pass's own per-entry walk - extracted from remove_entry as remove_dir_contents - so a nested mount point, --max-delete and --backup behave the same whichever caller peeled the directory, and each child is itemized and counted while the obstacle node stays silent.
  • The receiver's NDX_DEL_STATS gate becomes delete_mode || force_delete, closing the half of generator.c:2868/:2913 the code already carried a note about as unwired.
  • DeleteStats::merge gives the per-counter fold one owner; the generator's accumulate_delete_stats now delegates to it.

Mutation proof

tests/directory_obstacle_removal.rs gains 6 cells (4 positive, 2 controls). All run over a real --server child through an rsh shim, because a local transfer takes the engine's local-copy executor and exercises none of this path.

mutation result
del_recurse() → false 4 new cells RED, both controls and all 8 pre-existing cells green
del_recurse() → self.config.flags.delete only the 3 --force cells RED, the --delete cell green
restore "--force" => {} in the parser, production code otherwise intact the same 3 cells RED - the parse-layer wiring is load-bearing
everything restored 14/14 green

The two controls are the non-vacuity half: with neither flag the same fixture still refuses at 23 with the contents intact, so a change that recursed unconditionally would turn them red.

Adjacent finding, not fixed here

receiver/directory/missing_args.rs removes a --delete-missing-args destination directory recursively and silently, unconditionally. Upstream passes the same del_opts at generator.c:1753, and --delete-missing-args does not set delete_mode (options.c:742), so without --delete/--force upstream refuses a populated one and, with them, itemizes every child. Filed separately rather than folded in: it needs its own measurement and a writer threaded into that call site.


Second defect, found by the fix: a security cell that was green VACUOUSLY

Wiring --force turned the first commit red on the pinned 3.5.0 cell malicious-dot-file-delete-scope. Attribution against the exact merge-base, same host, same command: base PASS, head FAIL. Introduced, not inherited.

But the base passed for the wrong reason. grep finds upstream's guard nowhere on master - oc has never had it. The cell was green only because --force was parsed-and-discarded, so the DEL_RECURSE recursion was dead code and there was nothing to exploit. Nothing ever rejected the forged entry. Wiring --force did not create the hole; it removed the accident that was hiding it.

That is the shape worth remembering: a security test can be green because the mechanism it guards is unreachable, and it goes red the moment that mechanism starts working. A passing security cell is not evidence of a defence.

The attack

. is the receiver's synthetic transfer-root entry and is exempted from the requested-name filter. A sender that encodes . with regular-file mode therefore gets an unfiltered entry whose destination path is the transfer root. Every make-way site then sees a directory standing where a non-directory must be written and, under --force or --delete, clears it recursively - erasing receiver-owned files that were never part of the requested transfer. --delete is not needed.

The fix

Upstream refuses the entry at decode, in recv_file_entry(), with a comment naming this exact attack:

/* "." is the synthetic transfer root.  Reinterpreting it as a file lets
 * --force recursively remove the real destination directory before the
 * receiver creates that file. */
if ((!strcmp(thisname, ".") || !strcmp(thisname, "/.")) && !S_ISDIR(mode)) {
        rprintf(FERROR, "ERROR: rejecting non-directory transfer-root entry: %s\n", thisname);
        exit_cleanup(RERR_PROTOCOL);
}
                                                   -- flist.c:1127-1134

Ported onto the entry-decode path (crates/protocol/src/flist/read/mod.rs, read_entry()), after the name is cleaned - upstream's thisname at :1130 has already been through clean_fname() at :768-772 - and therefore ahead of the filter re-check that exempts the root. Both spellings . and /.; RERR_PROTOCOL (exit 2), not the RERR_UNSUPPORTED its two neighbouring guards use. It is a type check, not a scope narrowing: del_opts stays unconditional, which is why the honest single-file --force control is unaffected.

Placement is on the decode path rather than the receiver's re-check because that is where upstream puts it, and it protects every consumer. Role check by enumeration, not inference: the receiver and --read-batch decode a flist; the sender/generator and local-copy paths construct no FileListReader at all, so the guard cannot over-apply to them. (Upstream replays a batch through the same recv_file_entry, so including it is faithful.)

Mutation proof

arm outcome
guard in PASS - receiver rejected a non-directory encoding of its synthetic transfer-root entry
guard out FAIL - malicious sender encoded the special "." root as a regular file and made --force recursively erase the destination root

The guard-out failure is the sentinel assertion, not the cell's built-in honest---force control - so the control stayed green in both arms, separating "rejected the forgery" from "stopped honouring --force". Reader-level cells added: every non-directory S_IFMT on . refused as a protocol violation; a directory . still accepted (non-vacuity - the synthetic root is in nearly every recursive transfer).

Manifest row flipped, and what its green does NOT mean

The guard also flips proto-parent-ndx-empty-dirflist from fail to pass, so its stale fail row became the sole remaining mismatch on both TCP legs. Flipped on CI evidence (run 33642598146, jobs 100298359039 and 100298359185), not a workstation run. Direction matters: this records an absent defence that now exists, the inverse of re-baselining a regression to green.

WARNING: that row is green on the strength of the outermost of three layers - the entry is refused at decode. It is not evidence that the uninitialised-heap read behind it is defended. For oc, layers 2 and 3 are exonerated rather than outstanding: they defend a C memory-layout hazard oc does not have (no dir_flist; the equivalent index is a flat i32 already defaulted to -1; peer-supplied parent indices already rejected by DirectoryTree::try_add_directory with safe Vec indexing behind it, covered by the SEC-4 / CVE-2026-43620 tests). Full record, including a coupling claim I filed and then retracted when tracing disproved it: #7628.

@github-actions github-actions Bot added the bug Something isn't working label Sep 2, 2026
…eared

Upstream computes `int del_opts = delete_mode || force_delete ? DEL_RECURSE : 0`
at generator.c:1629 (recv_generator, feeding the DEL_FOR_FILE removal at :2149)
and again at generator.c:2481 (atomic_create), then hands it to delete_item(),
which passes it to delete_dir_contents(). With DEL_RECURSE the contents of a
directory standing where a non-directory has to be written are removed and the
directory is rmdir'd; without it the same call only probes emptiness
(delete.c:115-118) and returns DR_NOT_EMPTY.

oc could not reach either term. `--force` was recognised by the stdio server arg
parser and thrown away (`"--force" => {}`) with no field on ParsedServerFlags,
the daemon's own long-form parser had no arm for it at all, and the obstacle arm
never consulted `flags.delete` either - so it always took the bare-rmdir branch.

MEASURED against the pinned rsync 3.5.0 over a real `--server` child (source
symlink, destination populated directory):

  flags            | 3.5.0        | oc before | oc after
  -----------------|--------------|-----------|---------
  (none)           | 23, refused  | 23        | 23
  --force          | 0, replaced  | 23        | 0, replaced
  --delete         | 0, replaced  | 23        | 0, replaced
  --force --delete | 0, replaced  | 23        | 0, replaced

Under `-v --stats` 3.5.0 prints one `deleting obstacle/occupant` and reports
`Number of deleted files: 1 (reg: 1)`; oc now matches byte for byte.

The fix:

- `ParsedServerFlags::force`, set by BOTH server-arg parsers (the stdio one in
  cli/src/frontend/server/flags.rs and the daemon's apply_long_form_args) and
  bridged onto the local receiver on a pull via apply_common_server_flags, since
  there the client itself is the receiver.
- One owner for the rule: `ReceiverContext::del_recurse()` is upstream's
  expression verbatim, and `clear_obstacle_dir_contents` is the only recursion.
  It reuses the delete pass's own per-entry walk (extracted as
  `remove_dir_contents`), so a nested mount point, `--max-delete` and `--backup`
  behave the same whichever caller peeled the directory, and each child is
  itemized and counted the way delete.c:126-127 requires by stripping
  DEL_MAKE_ROOM - while the obstacle node itself stays silent and uncounted.
- The goodbye `NDX_DEL_STATS` gate becomes `delete_mode || force_delete`,
  closing the second half of generator.c:2868/2913 that the code already flagged
  as unwired.

Mutation-proved. Reverting `del_recurse()` to `false` turns 4 of the 6 new cells
red; keeping only the `delete` term turns the 3 `--force` cells red and leaves
the `--delete` cell green; restoring `"--force" => {}` in the parser alone turns
the same 3 red - so the parse-layer wiring is load-bearing and not a no-op fix.
The two control cells (no flag: still refused at 23 with the contents intact)
stay green throughout, which is what separates "reads the flag" from "always
removes the subtree".
@oferchen
oferchen force-pushed the fix/force-del-recurse-obstacle branch from 83adaea to e9a792b Compare September 2, 2026 13:41
Wiring `--force` made an attack shape reachable that oc had no defense
against, because oc never ported upstream's guard for it.

`.` is the receiver's SYNTHETIC transfer-root entry and is exempted from the
requested-name filter checks. A malicious sender that encodes `.` with
regular-file mode therefore gets an unfiltered entry whose destination path IS
the transfer root. Every make-way site then sees a directory standing where a
non-directory must be written and, under `--force` or `--delete`, clears it
recursively - erasing receiver-owned files that were never part of the
requested transfer. No `--delete` is needed.

Upstream refuses the entry at decode time, in `recv_file_entry()`, with a
comment naming this exact attack:

    /* "." is the synthetic transfer root.  Reinterpreting it as a file lets
     * --force recursively remove the real destination directory before the
     * receiver creates that file. */
    if ((!strcmp(thisname, ".") || !strcmp(thisname, "/.")) && !S_ISDIR(mode)) {
            rprintf(FERROR, "ERROR: rejecting non-directory transfer-root entry: %s\n",
                    thisname);
            exit_cleanup(RERR_PROTOCOL);
    }
                                                       -- flist.c:1127-1134

Ported verbatim onto the entry-decode path, immediately after the name is
cleaned - upstream's `thisname` at :1130 has already been through
`clean_fname()` at :768-772 - and therefore ahead of the filter re-check that
exempts the root (`receiver/file_list/filter_recheck.rs`). Four details are
load-bearing:

- Placement is on the DECODE path, not in the obstacle arm. Upstream refuses
  the flist entry, which is why an honest single-file `--force` transfer is
  unaffected; gating the obstacle arm instead would either break that control
  or leave the forged entry live for every other consumer (mkdir, rename,
  backup).
- BOTH spellings, `.` and `/.`. The existing filter-exemption tests only `.`,
  so `/.` would walk straight past a guard that copied it.
- `RERR_PROTOCOL` (exit 2), NOT `RERR_UNSUPPORTED` (exit 4). The two
  neighbouring guards in the same upstream function use RERR_UNSUPPORTED and
  this one deliberately does not, so it must not reuse the
  `io::ErrorKind::Unsupported` mapping the filter re-check returns.
- A directory is the only legitimate encoding of this name, so the guard is a
  TYPE check, not a scope narrowing: `del_opts` stays unconditional.

Mutation-proved against the pinned 3.5.0 testsuite cell
`malicious-dot-file-delete-scope`, which plants `dest/private/must-survive`
outside the requested leaf and carries its own honest `--force` single-file
control:

  guard in  -> PASS, "receiver rejected a non-directory encoding of its
               synthetic transfer-root entry"
  guard out -> FAIL, "malicious sender encoded the special "." root as a
               regular file and made --force recursively erase the
               destination root"

The guard-out failure is the SENTINEL assertion, not the control assertion, so
the honest `--force` control stayed green in both arms - which is what
separates "rejected the forgery" from "stopped honouring --force".

Also adds reader-level unit tests: every non-directory S_IFMT on `.` is
refused as a protocol violation, and a directory `.` is still accepted (the
non-vacuity control - the synthetic root is present in nearly every recursive
transfer).

Side effect, in the safe direction: `proto-parent-ndx-empty-dirflist` now
PASSES. That test forges the same non-directory `.` to reach an
uninitialised-heap read, and its own header names this guard as the first of
three layers that stop it. Its manifest row still reads `fail` and needs to
become `pass`; left untouched here.
…tion

`clippy::doc_lazy_continuation` on `read_entry_rejects_non_directory_transfer_root`,
five consecutive lines.

The cause is a dash at the start of a doc line. The note reads
"... was parsed-and-discarded\n/// - which made upstream's ... cell pass
VACUOUSLY", and markdown parses that leading `- ` as a LIST BULLET, which turns
every following line of the paragraph into an unindented continuation of a list
item that was never meant to be one.

Reflowed so the dash falls mid-line; the wording is unchanged except for
replacing that one dash with a comma. The note itself is the point of the
comment - it records that the upstream cell passed VACUOUSLY on master because
the recursion was dead code rather than because anything rejected the forged
entry - so it is reformatted, never trimmed to satisfy the lint.

The genuine `# Upstream Reference` list below it is a real list and already
indents its continuations three spaces; it was not the trigger and is untouched.
…P manifests

The transfer-root guard added in this branch
(`crates/protocol/src/flist/read/mod.rs`, `read_entry()`) flips this cell from
fail to pass, so the manifest rows that still expect `fail` are stale and are
the sole remaining expected-result mismatch on the TCP legs.

Justified by CI, not by a workstation run. Run 33642598146, both TCP legs,
each reporting exactly one expected-result mismatch and the same one:

    job 100298359039  upstream-testsuite-tcp / upstream testsuite
        102 passed / 20 failed / 33 skipped
        proto-parent-ndx-empty-dirflist: expected fail, got pass (xpass)

    job 100298359185  upstream-testsuite-tcp / upstream testsuite (root)
        114 passed / 26 failed / 15 skipped
        proto-parent-ndx-empty-dirflist: expected fail, got pass (xpass)

Both legs also report `PASS malicious-dot-file-delete-scope`, which is no
longer a mismatch at all - the defect this branch fixes. One row per manifest
is flipped, and the two `.tcp.txt` files are the only ones carrying it: the
non-TCP manifests list the cell as `skip` (it needs a real TCP daemon), and the
non-TCP root leg passed unchanged.

A same-host A/B had already shown base `fail` -> head `pass`; both CI legs
reproduce it, so the flip is causal rather than environmental.

Direction matters: this records an absent defence that now EXISTS. It is not
the re-baseline direction, which would encode a regression as expected. The
`malicious-dot-file-delete-scope` row stays `pass` and now passes because the
forged entry is refused, not because the recursion is dead code.

⚠ WHAT THIS GREEN ROW DOES NOT MEAN. The cell's own header names THREE layers
that stop its attack, and this row is green on the strength of the FIRST alone:
the entry is refused at decode. It is not evidence that the uninitialised-heap
read behind it is defended.

For oc specifically, layers 2 and 3 are exonerated rather than outstanding -
they defend a C memory-layout hazard oc does not have. `dir_flist` has no
oc counterpart (`crates/transfer/src/generator/ndx_map.rs`: "oc has no separate
`dir_flist`"); the equivalent index is a flat `i32` into one list, already set
to `-1` unless slot 0 is present and named `.`
(`crates/transfer/src/generator/file_list/inc_recurse.rs`); and peer-supplied
parent indices are already rejected by `DirectoryTree::try_add_directory` with
safe `Vec` indexing behind it, covered by the SEC-4 / CVE-2026-43620 tests in
`crates/protocol/src/flist/dir_tree.rs`. See #7628 for the full record,
including a retracted false alarm about a cross-module coupling that tracing
disproved.
@oferchen
oferchen merged commit 029c2c5 into master Sep 2, 2026
73 checks passed
@oferchen
oferchen deleted the fix/force-del-recurse-obstacle branch September 2, 2026 20:39
oferchen added a commit that referenced this pull request Sep 2, 2026
… merged PRs (#7634)

* docs(rustdoc): reach the public items rustdoc could not see, and gate the class

Two halves of the same question - is what a public item says actually reachable
from `cargo doc`?

Half 1: seven `//` comment blocks documented a `pub` item, so their text never
reached the generated docs. Found positionally, not by content: a `//` run whose
next non-attribute line declares a `pub` item. A census keyed on comment CONTENT
is false-positive dominated; this one is mechanical.

Nine sites matched; two are DELIBERATELY left as `//`, because they document the
`#[cfg_attr]` / `#[allow]` attribute directly beneath them rather than the item -
`local_copy/overrides.rs` and `local_copy/plan/report.rs`. Promoting those would
attach a lint rationale to a public surface as if it described the surface.

Text is preserved verbatim, upstream citations included (`generator.c:2149` on
the obstacle module). The only rewrite is `socket_options/consts.rs`, where one
group note covered two constants: split per item, matching the file's own house
style where every other const already carries `///`.

Half 2: five intra-doc links could not resolve in a DEFAULT build, and the
existing gate is structurally unable to see them.

  crates/fast_io/src/lib.rs, ewma.rs (x4)  -> `adaptive_dispatch`, gated by the
                                              off-by-default
                                              `adaptive-basis-dispatch` feature
  crates/rsync_io/.../sync_bridge.rs       -> `crate::channel_adapter`, gated by
                                              the off-by-default `async-ssh`
                                              feature
  crates/fast_io/src/confinement.rs        -> `PinnedRoot`, a PRIVATE struct

plus one already on the branch in `module_list/types.rs`, where the link was
`Transport::Quic` (the `quic` feature) and its surrounding prose still described
the variant as unbuilt.

Every crate denies `rustdoc::broken_intra_doc_links`, so each of these is a hard
`cargo doc` failure, not a warning. MEASURED on the pristine base:

    cargo doc --no-deps --workspace   ->  7 errors, `fast_io` and `rsync_io`
                                          could not be documented
    cargo doc --no-deps --workspace --all-features  ->  clean

That gap is the whole point. Under `--all-features` the gated items EXIST, so
the link resolves and the gate is green; in a default build the item is not
compiled at all. `ci.yml`'s `rustdoc-links` job runs only `--all-features`,
deliberately mirroring `pages.yml` - which is right for the question Pages asks
and cannot ask this one. So the fix is paired with a SECOND step on default
features, and neither subsumes the other: `crates/fast_io/src/io_uring` is
`cfg(all(target_os = "linux", feature = "io_uring"))` and only the all-features
run compiles it.

The names stay in backticks with the reason stated at each site, rather than
being deleted or the links made conditional - the prose still says what it said,
and the next reader learns why it is not a link.

After: both invocations document all 25 crates cleanly, 0 errors. fmt clean;
clippy on the five touched crates reports no new diagnostics.

* docs(changelog): record the ten pull requests merged since the last sweep

#7624 brought the Unreleased section up to #7620 and then stopped being true:
#7621-#7632 landed after it, of which #7624 is itself that changelog pass and
#7628 was never merged. Ten entries were missing.

Each is placed in the subsection its change belongs to rather than appended in
number order, and #7625 is SPLIT across two, because it is two changes: wiring
`--force` is a receiver fix, and the synthetic-transfer-root guard that wiring
made necessary is a peer-supplied input bound. Filing it once under either
heading would have hidden whichever half the reader was looking for.

  Security / peer-supplied input bounds   #7625 (guard half), #7630
  Fixed / transfer and receiver           #7622, #7625 (--force half), #7627
  Fixed / daemon                          #7629
  Testing and CI                          #7621, #7623, #7632
  Documentation                           #7626, #7631

Wording is taken from each merge commit's own body, not from its title - the
titles compress away the part a reader needs. #7629's title says "keep a dead
name converter apart from an unknown name"; what makes it worth an entry is that
five outcomes collapsed into one `None` and the merge failed OPEN on exactly the
mechanism an operator installs to take ownership decisions away from the peer.
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