Skip to content

fix(matching): bound the equal-weak-checksum chain in the delta matcher - #7293

Merged
oferchen merged 2 commits into
masterfrom
fix/hash-search-chain-bound
Aug 13, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/hash-search-chain-bound

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Problem

The delta matcher's hash chain is populated from the peer-supplied signature. A crafted basis whose blocks all share one weak (rolling) checksum makes every source offset walk the entire chain, turning the scan into O(source_len * chain_len) — the quadratic-CPU DoS fixed upstream in rsync 3.5.0 as CVE-2026-70453.

oc has the defect. The two probe paths in crates/matching/src/index/mod.rs walked CompactLookup::find_all to exhaustion with no bound, and neither zsync-inspired structure helps here:

  • the BitHash prefilter admits, because the probed rolling sum is genuinely present in the basis;
  • the compact key (sum1 discriminator + sum2 bucket) does not discriminate, because every candidate carries exactly the probed sum.

Measured

Fixture: a basis of blocks crafted to share the all-zero window's rolling sum (0, 0) while differing in content, probed with an all-zero source so every offset hits the chain and never matches. Release build, 64 KiB source, aarch64:

basis blocks elapsed
control (4000 blocks, distinct rolling sums) 138 ms
500 colliding 373 ms
1000 colliding 474 ms
2000 colliding 684 ms
4000 colliding 1077 ms

Linear in chain length at fixed source size (~0.20 ms per 1000 blocks), i.e. O(source_len * chain_len). Extrapolating the measured ~3.15 ns per candidate step, a 1 GiB source against a 40000-block chain is on the order of tens of hours of pure CPU — matching the multi-hour hangs upstream reports.

Fix

Mirror upstream's rule from match.c exactly:

  • cap the candidates verified at a single source offset at MAX_CHAIN_LEN = 1024;
  • past the cap, report a non-match — the caller rolls the window forward a byte and the skipped data goes out as literal bytes. Never an error, never corruption.

The counter is placed after the prune skips, mirroring upstream's placement after its own chain unlink. That is what keeps the bound observably neutral: a duplicate basis block is still matched by the first live candidate rather than by walking past a thousand dead ones.

The two probe paths that each carried their own copy of the chain walk are collapsed onto a single walk_chain helper, so the rule (prune skips + bound + strong compare) has one home.

Neutrality

Delta output is unchanged for non-malicious input:

  • bound_is_inert_on_a_realistic_basis asserts that in a 10000-block pseudo-random basis the longest chain is far below the cap, and that an identical source still resolves to pure Copy tokens;
  • the crate's existing wire-parity and golden corpora (zsync_wire_parity, parallel_delta_wire_parity, seq_match_golden, block_matching_accuracy) are green;
  • crates/protocol is upstream of crates/matching in the dependency graph, so the protocol golden-byte tests cannot be affected by this change; engine and transfer, which do consume the matcher, are green.

Tests

New crates/matching/src/index/chain_bound_tests.rs, written over the class rather than one hand-picked case:

  • candidate_is_reachable_exactly_below_the_bound — sweeps the candidate's position across the boundary (0, 1, 2, 512, 1022, 1023, 1024, 1025, 1199); reachable exactly while position < MAX_CHAIN_LEN.
  • bound_holds_across_chain_lengths — sweeps chain length (1, 2, 16, 1023, 1024, 1025).
  • skipped_data_is_sent_literally_not_corrupted — the delta over a hostile basis is pure literal and apply_delta reproduces the source byte for byte.
  • bound_is_inert_on_a_realistic_basis — the neutrality check above.
  • crafted_blocks_collide_on_the_weak_checksum_only — validates the fixture construction itself (all blocks share the rolling sum, none share a strong sum, all land in one chain).
  • bound_matches_upstream_max_chain_len — pins the constant to upstream's literal 1024, so oc cannot drift to a limit upstream does not have.

Non-vacuity confirmed: with the bound removed, candidate_is_reachable_exactly_below_the_bound fails at position 1024 with Some(1024) instead of None.

Verification

cargo fmt --all -- --check                                                    clean
cargo clippy --locked --workspace --all-targets --all-features --no-deps
    -- -D warnings                                                            clean
cargo nextest run -p matching  --all-features    379 passed, 3 skipped
cargo nextest run -p engine    --all-features   4969 passed, 24 skipped
cargo nextest run -p transfer  --all-features   2715 passed, 3 skipped

Follow-up noted, deliberately not in scope

oc's consumed-block prune (ZSO-3) skips chain entries rather than unlinking them the way upstream unlinks its bypassed in-place entries. Those skipped entries stay on the chain and are re-walked on every later probe, so a basis with a very large run of genuinely duplicate blocks retains an unbounded walk over dead entries. That is an oc-only characteristic, distinct from CVE-2026-70453, and bounding it by counting skipped candidates would break output neutrality against upstream. The correct fix is to unlink consumed entries, which touches the &self-shared lookup structure — a separate change.

The signature that populates the matcher's hash chain is peer-supplied. A
crafted basis whose blocks all share one weak checksum turned the
per-offset chain walk into an O(source_len * chain_len) scan, so a hostile
peer could pin a sender CPU for hours (CVE-2026-70453).

Measured on the crafted fixture (release, 64 KiB source, aarch64): 373 ms
at 500 colliding blocks rising linearly to 1077 ms at 4000, against 138 ms
for a same-size basis with distinct rolling sums. The zsync BitHash
prefilter and the compact bucket key do not help here - every candidate
carries the probed rolling sum, so all of them are admitted.

Mirror upstream's rule from match.c: cap the candidates verified at one
source offset at MAX_CHAIN_LEN (1024) and treat an over-long chain as a
non-match, which rolls the window forward a byte and sends the skipped
data as literals. The counter sits after the prune skips, matching
upstream's placement after its own chain unlink, so a duplicate basis
block is still matched by the first live candidate and the bound stays
observably neutral on honest bases.

The two probe paths that walked the chain are collapsed onto one
walk_chain helper so the rule has a single home.

Tests sweep the class rather than one case: the candidate's position
across the boundary, the bound across chain lengths, delta correctness
when the bound is reached, and an inertness check that no chain in a
10000-block realistic basis comes near the cap.
@github-actions github-actions Bot added the bug Something isn't working label Aug 13, 2026
@oferchen
oferchen enabled auto-merge (squash) August 13, 2026 18:19
@oferchen
oferchen merged commit f956c37 into master Aug 13, 2026
16 checks passed
@oferchen
oferchen deleted the fix/hash-search-chain-bound branch August 13, 2026 19:29
oferchen added a commit that referenced this pull request Aug 21, 2026
…te (#7423)

The changelog had not been touched since 2026-08-13 (#7279) while ~140 PRs
merged, and several factual claims in README/SECURITY had drifted far enough
to mislead an operator. Each correction below was verified against the tree,
not inferred.

CHANGELOG: fill in Unreleased for everything merged since #7279, grouped by
Security / Added / Changed / Fixed / Testing and CI / Documentation.

SECURITY:
- The 3.5.0 divergence figure said 133. The committed expect manifests say
  43 + 62 on the two full-corpus legs (64 distinct) and 89 across all four.
  Replaced the estimate with the per-leg table and the manifest mechanism.
- The CI paragraph described the 3.5.0 suite as a separate nightly job. It
  is now the required gate, four legs, on every pull request.
- CVE-2026-53791: the placeholder-peer-address prerequisite is fixed
  (#7303), not pending. CVE-2026-70452, -70463 and -70453 are fixed
  (#7314, #7345, #7293) and were still listed as under audit.
- The new-defensive-surface paragraph listed all eight 3.5.0 additions as
  being adopted; four have shipped and two directives have not.
- The fuzz list named 24 targets including "rsyncd_conf", which does not
  exist in fuzz/fuzz_targets. There are 26; added the three real ones that
  were missing.
- The buffer-pool hardening note claimed recycle_buffer guards buf_id with
  a debug assertion and warned against exposing io_uring to untrusted
  input. The check is a real release-mode bound returning
  BufferIdOutOfRange before any state is mutated, so the warning was false.

README:
- Status and interop sections listed 3.5.0 as built-and-cached ahead of
  gating; run_interop.sh has it in the gating version list, and the
  protocol table row still said "not yet gating".
- Added the current 3.5.0 testsuite outcomes rather than only describing
  the mechanism, so the 64 open divergences are stated plainly.
- The CVE line stopped at the 2024 batch; the 3.4.3 batch is closed and
  3.5.0 is partially closed and tracked.
- The spill CLI flags were described as planned for STN-11; both exist.
- The OC_RSYNC_BUFFER_POOL variables were attributed to the io_uring
  registered pool. All three live in crates/engine/src/local_copy/
  buffer_pool/ and tune the engine pool; the io_uring pool is a
  different, static one.
- The bgid note advised monitoring for exhaustion that measurement shows
  does not occur.
- Fixed a broken link: compressed_token/zstd_codec is a directory.
- Listed the shipped 3.5.0 option surface in the feature table.
oferchen added a commit that referenced this pull request Aug 24, 2026
…er (#7293)

The signature that populates the matcher's hash chain is peer-supplied. A
crafted basis whose blocks all share one weak checksum turned the
per-offset chain walk into an O(source_len * chain_len) scan, so a hostile
peer could pin a sender CPU for hours (CVE-2026-70453).

Measured on the crafted fixture (release, 64 KiB source, aarch64): 373 ms
at 500 colliding blocks rising linearly to 1077 ms at 4000, against 138 ms
for a same-size basis with distinct rolling sums. The zsync BitHash
prefilter and the compact bucket key do not help here - every candidate
carries the probed rolling sum, so all of them are admitted.

Mirror upstream's rule from match.c: cap the candidates verified at one
source offset at MAX_CHAIN_LEN (1024) and treat an over-long chain as a
non-match, which rolls the window forward a byte and sends the skipped
data as literals. The counter sits after the prune skips, matching
upstream's placement after its own chain unlink, so a duplicate basis
block is still matched by the first live candidate and the bound stays
observably neutral on honest bases.

The two probe paths that walked the chain are collapsed onto one
walk_chain helper so the rule has a single home.

Tests sweep the class rather than one case: the candidate's position
across the boundary, the bound across chain lengths, delta correctness
when the bound is reached, and an inertness check that no chain in a
10000-block realistic basis comes near the cap.
oferchen added a commit that referenced this pull request Aug 24, 2026
…te (#7423)

The changelog had not been touched since 2026-08-13 (#7279) while ~140 PRs
merged, and several factual claims in README/SECURITY had drifted far enough
to mislead an operator. Each correction below was verified against the tree,
not inferred.

CHANGELOG: fill in Unreleased for everything merged since #7279, grouped by
Security / Added / Changed / Fixed / Testing and CI / Documentation.

SECURITY:
- The 3.5.0 divergence figure said 133. The committed expect manifests say
  43 + 62 on the two full-corpus legs (64 distinct) and 89 across all four.
  Replaced the estimate with the per-leg table and the manifest mechanism.
- The CI paragraph described the 3.5.0 suite as a separate nightly job. It
  is now the required gate, four legs, on every pull request.
- CVE-2026-53791: the placeholder-peer-address prerequisite is fixed
  (#7303), not pending. CVE-2026-70452, -70463 and -70453 are fixed
  (#7314, #7345, #7293) and were still listed as under audit.
- The new-defensive-surface paragraph listed all eight 3.5.0 additions as
  being adopted; four have shipped and two directives have not.
- The fuzz list named 24 targets including "rsyncd_conf", which does not
  exist in fuzz/fuzz_targets. There are 26; added the three real ones that
  were missing.
- The buffer-pool hardening note claimed recycle_buffer guards buf_id with
  a debug assertion and warned against exposing io_uring to untrusted
  input. The check is a real release-mode bound returning
  BufferIdOutOfRange before any state is mutated, so the warning was false.

README:
- Status and interop sections listed 3.5.0 as built-and-cached ahead of
  gating; run_interop.sh has it in the gating version list, and the
  protocol table row still said "not yet gating".
- Added the current 3.5.0 testsuite outcomes rather than only describing
  the mechanism, so the 64 open divergences are stated plainly.
- The CVE line stopped at the 2024 batch; the 3.4.3 batch is closed and
  3.5.0 is partially closed and tracked.
- The spill CLI flags were described as planned for STN-11; both exist.
- The OC_RSYNC_BUFFER_POOL variables were attributed to the io_uring
  registered pool. All three live in crates/engine/src/local_copy/
  buffer_pool/ and tune the engine pool; the io_uring pool is a
  different, static one.
- The bgid note advised monitoring for exhaustion that measurement shows
  does not occur.
- Fixed a broken link: compressed_token/zstd_codec is a directory.
- Listed the shipped 3.5.0 option surface in the feature table.
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