Skip to content

chore(citations): retarget upstream citations at rsync 3.5.0 - #7305

Merged
oferchen merged 3 commits into
masterfrom
chore/citations-3.5.0
Aug 14, 2026
Merged

oferchen merged 3 commits into
masterfrom
chore/citations-3.5.0

Conversation

@oferchen

@oferchen oferchen commented Aug 13, 2026 •

Copy link
Copy Markdown
Owner

Why

tools/ci/citation_drift_audit.py pinned rsync 3.4.4. Flipping VER alone turns most
of the repo red: measured at 3.5.0 against the unmodified corpus, 453 of 495
string-anchored citations drift (91%), against 29 of 495 (5%) at 3.4.4. The
retarget is the task; the flip is one line.

This brings task U350-7e forward out of the "flip the pin last" staging. It is safe to
land early because it changes no code and no gate semantics: the audit is a comment
checker, the 3.5.0 source is already fetched and cached by CI (#7278, #7290), and
nothing else yet reads 3.5.0 as its oracle. Leaving it until last would instead mean
carrying a corpus known to be 91% wrong against the version we are moving to.

How the retarget was decided

The tool is string-anchored, not line-exact: it finds a quoted C string from the
comment and flags the citation only if the cited line is more than 4 away. Retargeting
is therefore not arithmetic on line numbers. Each citation was resolved by ordinal
mapping
- find which occurrence of the anchor the citation matched at 3.4.4, and use
that same occurrence index at 3.5.0. That is only sound when the anchor occurs equally
often in both versions.

class n action
already within 4 at 3.5.0 42 untouched
ordinal map (equal occurrence counts) 418 retargeted
already drifted at 3.4.4, unique 3.5.0 anchor 21 retargeted (also fixes pre-existing drift)
anchor matches >1 line, counts differ 6 left, false positive
already drifted at 3.4.4, anchor not unique 8 left, false positive
anchor resolves nowhere at 3.5.0 4 left, see unresolved below

Range citations. file.c:START-END carries END outside the token the CITE regex
matches, so a first pass moves START and leaves END stale - producing inverted ranges
like exclude.c:1381-1237. 122 range ENDs were shifted by the same delta as their
start. Verified: 5896 range citations in the tree, 0 inverted.

The gate accepted a backwards range

This is a property of the checker, not a note about the sweep. CITE matches only
file.c:START, so nothing in the tool ever looked at END. A retarget that moves
START leaves END on the old pin and yields exclude.c:1381-1237 - and every other
check here audits that perfectly clean. It happened 116 times and was caught by
reading the diff, not by the gate.

The invariant is now asserted: END >= START. It fails in every mode, including
--write-baseline, and is deliberately not ratcheted - there is no such thing as an
accepted backwards range. Non-vacuity checked by injecting one:

filters: string-anchored=3 suspected-drift=0 (0%) unresolved=8 BACKWARDS-RANGES=1
  ! crates/filters/src/rule.rs:93: exclude.c:1381-1237 runs backwards
FAIL: 1 citation range(s) run backwards.

exit 1 with the injected range, exit 0 once removed.

Result

Drift 453 -> 14 of 495 anchored citations (91% -> 3%). Per crate: cli 3, core 3,
daemon 2, transfer 6, everything else 0. --ratchet passes against the lowered
baseline.

The 14 left in place, and why

Every one is an anchor matching more than one upstream line, which is the
false-positive class the tool's own docstring warns about - it cannot localise the
citation, so its verdict is not evidence. Moving these line numbers to satisfy the
heuristic would be worse than the drift.

citation anchor matches at 3.5.0
exclude.c:1213 x2 Unknown filter rule 1363, 1675
options.c:2768 --log-format= 2939, 2941, 2943
options.c:2850/2852 x2 if (am_sender) 2807, 2991, 3082
clientserver.c:382 rprintf(FERROR, " 13 sites
clientserver.c:831/847 x2 use chroot 888, 1490
flist.c:1667 return NULL 20 sites
flist.c:1846 x2 link_stat 20 sites
generator.c:1679 else if (basis_dir[0] != NULL) 1978, 2064
generator.c:1351 statret == 0 3 sites
log.c:845 deleting 3 sites

Fixing them means giving the comment a distinctive anchor, not moving a correct
line number. Recorded in the baseline under _5_350_flip.

Blind spot now closed

The tool dropped a citation in silence when no anchor resolved (if not locs: continue), counting it as neither checked nor drifted. That is exactly where a version
bump hides "the code this cites no longer exists". Such citations are now counted and
listed as unresolved. There are 291 occurrences / 251 distinct at 3.5.0. 4 of
them resolved cleanly at 3.4.4 and no longer resolve at all, so they are the ones a
reader should look at first:

  • metadata/src/options/accessors.rs:107 and options/mod.rs:44 - generator.c:1356,
    anchor link_stat(fname, &sx.st, keep_dirlinks && is_dir)
  • rsync_io/src/ssh/stall.rs:59 - io.c:1151, anchor allowed_lull = (io_timeout + 1) / 2
  • transfer/src/receiver/quick_check.rs:1031 - generator.c:965, anchor
    link_stat(cmpbuf, &sxp->st, 0)

unresolved is reported, not gated - a paraphrased quote lands there too.

Verification

--write-baseline output was not taken on trust. Eight retargets, one per crate, were
read by hand against the 3.5.0 source; all eight land exactly on the quoted code:

options.c:1825      bwlimit = (size + 512) / 1024;
flist.c:168         flist_csum_len = csum_len_for_type(file_sum_nni->num, 1);
clientserver.c:837  io_printf(f_out, "@ERROR: invalid uid %s\n", p);
exclude.c:1381      case '-':
log.c:272           FILE *f = msgs2stderr == 1 ? stderr : stdout;
util1.c:1653        if (modify_window < 0)
generator.c:1738    #ifdef SUPPORT_ACLS
checksum.c:394      if (checksum_seed) {

The claim, not just the string, was checked on filters/src/rule.rs:575
(exclude.c:1381-1391): 1381 is case '-' and the following lines are the merge-file
FILTRULE_MERGE_FILE / NO_PREFIXES handling the comment describes, with the same
10-line span as the original 1227-1237.

Not done here (deliberate)

  • Scope stays crates/*/src/**/*.rs. Extending to tests and tools/ is task
    U350-7f / VAL-2 and belongs in its own change.
  • The anchor filter is unchanged. 101 of 495 anchors are non-unique and 35 match
    more than 3 lines (goto cleanup x34, link_stat x20, io_error |= IOERR_GENERAL
    x19). The generator is %-truncation: "link_stat %s failed" passes the filter
    because it contains a space and a %, then .split('%')[0] reduces it to the bare
    identifier link_stat, and the post-filter only checks len >= 8. Tightening this
    would cut the false-positive rate but also shrink the gate's denominator, so it is a
    separate decision rather than a side effect of a retarget. Worth its own task.
  • HIGH was checked against 3.5.0; no cited file in it was renamed or removed.

The pin was in two places, not one

The task named VER. There is a second, independent pin behind the required
nextest (stable) cell: xtask/src/commands/citations.rs asserts that every citation
names a file and line the pinned release actually has, via its own MANIFEST_PATH and
PINNED_SOURCE_DIR. Retargeting the corpus onto 3.5.0 line numbers while that gate
still read 3.4.4 makes the two contradict each other:

manifest the hard gate reads violations over the retargeted corpus
upstream-3.4.4-lines.tsv (as this PR first stood) 80
upstream-3.5.0-lines.tsv (this commit) 0

Same corpus, same checker, only the manifest differs - which is the non-vacuity proof
for the fix. Example: crates/cli/src/frontend/server/daemon.rs:132 cites
main.c:1948, and 3.4.4's main.c is 1879 lines.

The workflow was the third place: citation-drift.yml fetched only the 3.4.4 tarball,
so the audit would have aborted with upstream source missing: .../rsync-3.5.0. That
half fails loudly rather than reporting zero citations checked, so it was never a
vacuous-green risk - but it was still a red.

Now moved together: both constants, the regenerated manifest (494 files), the workflow
cache path / key / fetch URL / job name, and CONTRIBUTING.md. Both the module doc and
CONTRIBUTING now state that the two pins move in the same change, because a half-moved
pin is exactly what makes them disagree.

manifest_matches_the_pinned_source proven non-vacuous. It skips where the source
tree is absent, and this manifest was generated outside the tool, so a green could have
meant "skipped": injecting one wrong line count for io.c gives FAIL (rc=100);
restoring gives a byte-identical file and rc=0.

Four unresolved investigated (task 651)

Folded in here rather than split out - same corpus.

  • rsync_io/src/ssh/stall.rs - io.c:1151 -> io.c:1281. 3.5.0 hardened
    set_io_timeout with a negative clamp, int64 widening and an INT_MAX/5 cap.
    oc needs none of it: Duration is unsigned so a negative interval is
    unrepresentable, stall_poll_interval clamps both ends, and signature_read_lull_mod
    saturates twice. Measured: --timeout=-1 exits 1 at parse; a huge value flows into
    u64 Duration arithmetic that cannot overflow. The comment now records why no change
    is needed rather than implying a gap.
  • metadata/src/options/{mod,accessors}.rs and
    transfer/src/receiver/quick_check.rs - left as-is. All three cite the
    path-based link_stat that 3.5.0 replaced with basis_link_stat() and the
    dirfd-anchored gen_entry_stat(). That is the confinement/anchoring model owned by
    the U350-4 resolver work, so retargeting them to point at code oc does not implement
    would make the comments less true. They stay unresolved until that lands.

Also fixed while there: stall.rs cited io.c:179 with the anchor
if (!io_timeout) return; - two joined C source lines, so that string exists in no
rsync release and the citation could never resolve at any version. Retargeted to
io.c:226 (verified by reading both trees: identical comment block, pure line shift)
and reworded to a single line. A line-spanning anchor is permanently unverifiable and
is a different class from the non-uniqueness noted above.

Verified locally

cargo xtask citations rc=0 (7754 citations, 4920 files) - cargo nextest -p xtask -E 'test(citation) or test(manifest)' rc=0, 24 passed - citation_drift_audit.py --ratchet rc=0 - cargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warnings rc=0 - rustfmt --edition 2024 --check rc=0.

@github-actions github-actions Bot added the chore label Aug 14, 2026
The audit pinned 3.4.4. Flipping VER alone turns most of the repo red: at
3.5.0 the corpus measured 453 suspected-drift out of 495 string-anchored
citations (91%). The retarget is the work; the flip is one line.

Citations were moved by ordinal mapping rather than arithmetic: for each
flagged citation, find the anchor's occurrence index at 3.4.4 and use the
same index at 3.5.0. That is only sound when the anchor occurs equally
often in both versions, so 418 citations qualified; a further 21 were
already drifted at 3.4.4 and had a unique 3.5.0 anchor, making their
correct line unambiguous. 122 range ENDs were shifted by the same delta as
their start - the CITE regex matches only `file.c:START`, so a first pass
that moves START alone leaves `exclude.c:1381-1237` behind.

Drift falls 453 -> 14 of 495. Every one of the 14 remaining is an anchor
that matches more than one upstream line, so the tool cannot localise it
and its verdict is not evidence; they are recorded in the baseline as
false positives, not as unfixed drift.

Two tool changes come with the flip:

* every hit is printed, not the first 12 - a sweep driven by a truncated
  list is the sweep that leaves the rest behind;
* citations whose anchors resolve nowhere are counted and listed as
  `unresolved` instead of being dropped in silence. That silence is where
  a version bump hides "the code this cites no longer exists": 211 such
  citations exist at 3.5.0, four of which resolved cleanly at 3.4.4.
`CITE` matches only `file.c:START`, so nothing in this tool ever looked at
END. A retarget that moves START therefore leaves END on the old pin and
produces `exclude.c:1381-1237` - which every other check here audits
perfectly clean. That happened 116 times in the 3.5.0 sweep and was caught
by hand, not by the gate.

Assert the structural invariant instead: END >= START. It fails in every
mode including --write-baseline and is deliberately not ratcheted, because
there is no such thing as an accepted backwards range.

Non-vacuity checked by injecting one: the tool reports the file, line and
offending token and exits 1; removing it returns to exit 0.
The tree carries two independent citation checks against two independently
pinned upstream releases, and the 3.5.0 retarget moved only one of them.

`xtask/src/commands/citations.rs` is the hard gate: it runs under the
required `nextest` cell and asserts every citation names a file and line the
pinned release actually has. It pinned 3.4.4 via its own MANIFEST_PATH and
PINNED_SOURCE_DIR, so the retargeted citations named 80 lines that release
does not have - `daemon.rs:132` cites `main.c:1948`, and 3.4.4's `main.c` is
1879 lines. Against the regenerated 3.5.0 manifest the same corpus reports 0.

`.github/workflows/citation-drift.yml` fetched only the 3.4.4 tarball, so the
audit would have aborted on a missing source tree. That half failed loudly
rather than silently, but it still failed.

Regenerates the manifest as upstream-3.5.0-lines.tsv (494 files), repoints
the workflow and its job name, and records in both the module doc and
CONTRIBUTING that the two pins move together: they read the same comments
against different trees, so a half-moved pin makes them contradict.

Also retargets three citations in the io_timeout family that the audit could
not resolve. io.c:1151 -> io.c:1281 for the allowed_lull derivation, and
io.c:179 -> io.c:226 for the early-return guard, whose anchor additionally
quoted two joined C lines and so matched nothing anywhere; it now quotes one.
3.5.0 hardened set_io_timeout against a negative or INT_MAX timeout, which oc
does not need - Duration is unsigned and the interval is clamped at both ends
- so the note records why rather than implying a gap.
@oferchen
oferchen force-pushed the chore/citations-3.5.0 branch from 6ef5c54 to b93c21f Compare August 14, 2026 03:16
@oferchen
oferchen merged commit 21c4655 into master Aug 14, 2026
2 of 24 checks passed
@oferchen
oferchen deleted the chore/citations-3.5.0 branch August 14, 2026 03:16
oferchen added a commit that referenced this pull request Aug 14, 2026
The pinned upstream source moved from 3.4.4 to 3.5.0 in #7305, which
changed `PINNED_SOURCE_DIR` and the line manifest the citation gate
resolves against. This branch was written before that landed, so its
`clientserver.c:1559` citation named the 3.4.4 line:

    3.4.4  1559:  return start_daemon(STDIN_FILENO, STDIN_FILENO);
    3.5.0  1738:  return start_daemon(STDIN_FILENO, STDIN_FILENO);

Both occurrences now name 1738. Measured with
`tools/ci/citation_drift_audit.py --ratchet`: daemon goes 3 -> 2, its
baseline value, so no baseline edit is needed.

The two remaining ratchet failures (`core` 3 -> 4 and `protocol` 0 -> 1)
reproduce byte-identically on pristine origin/master and are not from
this branch.
oferchen added a commit that referenced this pull request Aug 14, 2026
The pinned upstream source moved from 3.4.4 to 3.5.0 in #7305, which
changed `PINNED_SOURCE_DIR` and the line manifest the citation gate
resolves against. This branch was written before that landed, so its
`clientserver.c:1559` citation named the 3.4.4 line:

    3.4.4  1559:  return start_daemon(STDIN_FILENO, STDIN_FILENO);
    3.5.0  1738:  return start_daemon(STDIN_FILENO, STDIN_FILENO);

Both occurrences now name 1738. Measured with
`tools/ci/citation_drift_audit.py --ratchet`: daemon goes 3 -> 2, its
baseline value, so no baseline edit is needed.

The two remaining ratchet failures (`core` 3 -> 4 and `protocol` 0 -> 1)
reproduce byte-identically on pristine origin/master and are not from
this branch.
oferchen added a commit that referenced this pull request Aug 14, 2026
… 3.5.0

#7305 moved the pinned upstream source from 3.4.4 to 3.5.0. Ten PRs
authored before that flip merged after it, so their citations name 3.4.4
line numbers in a tree the gate resolves against 3.5.0. This clears the
`core` ratchet, which five open PRs currently inherit:

    FAIL: core suspected-drift rose 3 -> 4     (before)
    core: suspected-drift=0                    (after)

Every target was verified against BOTH tarballs. Only the first is a
mechanical retarget; the rest needed the enclosing construct because the
anchor the audit extracts is not unique in its file.

1. flags.rs  generator.c:298 -> :304
   `io_error & IOERR_GENERAL` is unique; surrounding context is
   byte-identical.

2. daemon_transfer/connection/mod.rs  clientserver.c:382 -> :425
   `rprintf(FERROR, "` occurs many times. The site is the `@ERROR`
   handler, located by `strncmp(line, "@error", 6)` (3.4.4:381 ->
   3.5.0:424) and confirmed by byte-identical context.

3. flags.rs  options.c:2852-2857 -> :3018-3023
4. invocation/tests.rs  options.c:2850-2851 -> :3016-3017  (two sites)
   Both were already correct 3.4.4 RANGES; the audit flagged them only
   because it anchors on the range's prose (`if (am_sender)`), which
   occurs three times in options.c and is not on the cited line. The
   blocks are byte-identical at a constant +166. The comments are
   re-anchored on `args[ac++] = "--super"` and
   `args[ac++] = "--only-write-batch=X"`, each unique in options.c, so
   the audit can resolve them instead of guessing.

5. invocation/tests.rs  main.c:1839 -> :1919, sender.c:217 -> :501
   ⚠ Neither was reported by the ratchet - it only inspects lines
   containing the word `upstream`, and these sit mid-sentence in a doc
   comment. Both were stale. `sender.c` moved by +284 where options.c
   moved by +166, so an offset applied in bulk would have been wrong;
   each was located by its construct (`if (write_batch < 0) dry_run = 1`
   and `f_xfer = write_batch < 0 ? batch_fd : f_out`).

`core` drops 4 -> 0, so its baseline goes 3 -> 0 in the same commit, as
the baseline file requires - leaving it at 3 would keep accepting drift
that no longer exists and hide the next regression under that headroom.

Deliberately out of scope:
- `protocol` (`flist.c:758`) - the identical fix is already in #7318.
- `daemon` (`clientserver.c:1559`) - same cohort, fixed on #7314.

Measured on ce8c63d: `tools/ci/citation_drift_audit.py --ratchet`
reports core=0; `cargo xtask citations` passes (7826 citations);
`cargo fmt --all -- --check` clean.
oferchen added a commit that referenced this pull request Aug 14, 2026
… 3.5.0 (#7321)

#7305 moved the pinned upstream source from 3.4.4 to 3.5.0. Ten PRs
authored before that flip merged after it, so their citations name 3.4.4
line numbers in a tree the gate resolves against 3.5.0. This clears the
`core` ratchet, which five open PRs currently inherit:

    FAIL: core suspected-drift rose 3 -> 4     (before)
    core: suspected-drift=0                    (after)

Every target was verified against BOTH tarballs. Only the first is a
mechanical retarget; the rest needed the enclosing construct because the
anchor the audit extracts is not unique in its file.

1. flags.rs  generator.c:298 -> :304
   `io_error & IOERR_GENERAL` is unique; surrounding context is
   byte-identical.

2. daemon_transfer/connection/mod.rs  clientserver.c:382 -> :425
   `rprintf(FERROR, "` occurs many times. The site is the `@ERROR`
   handler, located by `strncmp(line, "@error", 6)` (3.4.4:381 ->
   3.5.0:424) and confirmed by byte-identical context.

3. flags.rs  options.c:2852-2857 -> :3018-3023
4. invocation/tests.rs  options.c:2850-2851 -> :3016-3017  (two sites)
   Both were already correct 3.4.4 RANGES; the audit flagged them only
   because it anchors on the range's prose (`if (am_sender)`), which
   occurs three times in options.c and is not on the cited line. The
   blocks are byte-identical at a constant +166. The comments are
   re-anchored on `args[ac++] = "--super"` and
   `args[ac++] = "--only-write-batch=X"`, each unique in options.c, so
   the audit can resolve them instead of guessing.

5. invocation/tests.rs  main.c:1839 -> :1919, sender.c:217 -> :501
   ⚠ Neither was reported by the ratchet - it only inspects lines
   containing the word `upstream`, and these sit mid-sentence in a doc
   comment. Both were stale. `sender.c` moved by +284 where options.c
   moved by +166, so an offset applied in bulk would have been wrong;
   each was located by its construct (`if (write_batch < 0) dry_run = 1`
   and `f_xfer = write_batch < 0 ? batch_fd : f_out`).

`core` drops 4 -> 0, so its baseline goes 3 -> 0 in the same commit, as
the baseline file requires - leaving it at 3 would keep accepting drift
that no longer exists and hide the next regression under that headroom.

Deliberately out of scope:
- `protocol` (`flist.c:758`) - the identical fix is already in #7318.
- `daemon` (`clientserver.c:1559`) - same cohort, fixed on #7314.

Measured on ce8c63d: `tools/ci/citation_drift_audit.py --ratchet`
reports core=0; `cargo xtask citations` passes (7826 citations);
`cargo fmt --all -- --check` clean.
oferchen added a commit that referenced this pull request Aug 14, 2026
)

* fix(daemon): render the peer host like upstream, not three ways

The daemon named the peer three different ways for the same missing
hostname: a lowercase `unknown` in the `log format` `%h` escape, the bare
peer address in the `rsync allowed access` / `denied` / `connect from`
lines, and an empty string in `RSYNC_HOST_NAME`. A single session could
therefore log

    rsync allowed access on module m from 127.0.0.1 (127.0.0.1)
    ... h=[unknown] a=[127.0.0.1]

Upstream keeps ONE host string per connection and renders it at every one
of those sites (clientserver.c:1524-1526, :770-771, log.c:583-593), and
that string is never empty or an address. It distinguishes two cases the
`Option<&str>` collapsed:

  UNDETERMINED  reverse lookup is off, so no name was ever sought
                (clientserver.c:126)
  UNKNOWN       a lookup ran and produced nothing - the 0.0.0.0 sentinel,
                a failed reverse lookup, or a rejected forward
                confirmation (clientname.c:34, :112)

`peer_host_display()` is that one rule; the ad-hoc fallbacks at the nine
log helpers, the `%h` renderer and the exec environment are gone, and
`format_host()` (the address-substituting one) is deleted.

Measured against the real rsync 3.5.0 daemon serving the same config:

  case                        upstream %h / %a       oc before      oc after
  TCP, reverse lookup = yes   localhost/127.0.0.1    match          match
  TCP, reverse lookup = no    UNDETERMINED/127.0.0.1 unknown/...    match
  rsh, no peer env            UNKNOWN/0.0.0.0        unknown/...    match
  rsh, REMOTE_HOST set        UNKNOWN/192.0.2.55     unknown/...    match

`%a` needed no change - it already rendered the resolved peer address.

Scope: this is the display, log and environment rule only. Upstream also
feeds these sentinels to `allow_access()`, and clientname.c:93-95
documents `UNKNOWN` as usable in a `hosts allow` line; adopting that
would widen oc's ACL matching, so access control keeps consuming the
`Option<&str>` unchanged and the question is filed separately.

Two existing tests pinned the pre-fix behaviour and are corrected: the
`RSYNC_HOST_NAME` assertion expected an empty string, and `format_host`
had three tests asserting the address substitution.

* fix(daemon): match the host sentinels in hosts allow, as upstream does

Upstream documents `UNKNOWN` as a value an operator may put in a
`hosts allow` line (clientname.c:91-94), and hands `allow_access()` the
same never-empty host string its log lines print (clientserver.c:769-773).
`match_hostname` refuses only a NULL or empty name (access.c:37-38), so a
sentinel is matched like any other name.

oc modelled the host as `Option<&str>` and passed `None`, so both
sentinels were unmatchable. Measured on 3.5.0 and oc, `reverse lookup =
no`, loopback peer:

  hosts allow = UNDETERMINED    upstream ALLOWED   oc DENIED
  hosts allow = other.example   upstream DENIED    oc DENIED   (control)
  hosts allow = 127.0.0.1       upstream ALLOWED   oc ALLOWED  (control)

TWO defects, and fixing the first alone was INERT - the end-to-end
measurement still showed DENIED on every row:

1. The sentinel never reached the matcher. `permits()` now takes a
   `PeerHost`, built by the same rule the display path uses, so the string
   an ACL matches is the string the log line prints.

2. `HostnamePattern::matches` compared case-SENSITIVELY against a pattern
   lowercased at parse time. That held only because every host until now
   arrived pre-lowercased from DNS via `normalize_hostname_owned`.
   Upstream lowercases the LIST (`strlower`, access.c:251) and matches
   with `iwildmatch`, the case-INSENSITIVE form (access.c:46) - so
   `unknown` matches `UNKNOWN` there. The host is now folded at the match
   site, which fixes the exact, suffix and wildcard arms together.

The `Resolved`/`Sentinel` distinction is kept because oc has one rule
upstream does not: a hostname-based DENY rule fails closed when no name
was resolved (GHSA-rjfm-3w2m-jf4f). Upstream can rely on reverse DNS
being cached from before `daemon chroot`; oc resolves per connection
after a process-wide chroot, where a chroot without NSS silently yields
no name. That guard is re-keyed from `hostname.is_none()` to
`!host.is_resolved()` - the SAME predicate, since `PeerHost::new` returns
`Sentinel` exactly when the resolved name is absent - so the allow-side
sentinels match without disarming it.

Tests: a 6-row table asserting the outcome of a real loopback
connection, run against oc AND the real 3.5.0 binary. It carries both
sentinel spellings and the wildcard arm, two controls (an unrelated
hostname rule still refuses; an address rule still admits, proving the
directive is live rather than ignored), and the discriminator - with
`reverse lookup = yes` a resolved peer must NOT match `UNDETERMINED`, so
a build that matched the sentinel unconditionally fails exactly one row.
Non-vacuity measured per half: reverting either the pass-through or the
case fold reddens the oc cell alone and leaves the upstream oracle green.

The harness pins the daemon's stdin to /dev/null. Without it the daemon
takes its single-connection path, never listens, and every row reports
"connection refused" - identical output for rows that must differ, which
is a broken instrument rather than a result. That is how the first
measurement of this defect went wrong.

* refactor(daemon): make the fail-closed deny guard compiler-enforced

The guard that refuses a peer when a hostname-based `hosts deny` rule
cannot be evaluated (GHSA-rjfm-3w2m-jf4f) asked `!host.is_resolved()`.
That is correct today, but it rests on a biconditional over the two
current `PeerHost` variants - sentinel iff no name was resolved - and the
biconditional is not enforced anywhere. A third variant, say a
resolved-but-empty name, would make `is_resolved()` answer for a state
nobody considered and would default it into "allowed", silently, at the
one site in the module where being wrong is a security regression rather
than a parity one.

The guard now matches the enum exhaustively and `is_resolved()` is
deleted rather than left available. Adding a variant is a compile error
instead of an inherited default, so the property is checked by the
compiler rather than argued in a comment or trusted from a review.

Non-vacuity measured: adding a probe variant produces

  error[E0004]: non-exhaustive patterns: `PeerHost::ResolvedButEmpty` not
  covered --> crates/daemon/src/daemon/module_state/definition.rs:281:39

at the guard, and a second E0004 at `as_str()` - the other site a new
state must be reasoned about. Behaviour is unchanged: 599 access-control
tests and the sentinel parity table pass before and after.

Same technique as enumerating the drains by deleting the ambiguous API,
applied prospectively rather than to find today's callers.

* fix(daemon): hosts deny fails CLOSED on an unresolvable token

CVE-2026-70452's sibling. Upstream returns the caller's `deny` flag when
the forward lookup of a configured token fails (access.c:57-63):

    if (!(hp = gethostbyname(tok))) {
        /* A deny-list hostname token we cannot resolve must fail CLOSED:
         * we can't prove the peer isn't the denied host ... */
        return deny;
    }

oc returned "no match" for both lists, so `hosts deny = host.example`
admitted every peer whenever that name would not resolve - a fail-OPEN on
a deny rule, reachable by making the operator's DNS unavailable.

Measured on 3.5.0 and oc, `reverse lookup = yes`, loopback peer:

  hosts deny = unresolvable.example.com   upstream DENIED   oc ALLOWED
  hosts deny = 203.0.113.9   (control)    upstream ALLOWED  oc ALLOWED
  hosts deny = 127.0.0.1     (control)    upstream DENIED   oc DENIED

All three now agree.

ENUMERATED rather than generalised. Upstream has ONE decision site and
threads a per-call flag to it - `access_match(allow_list, .., 0)`
(access.c:284), `access_match(deny_list, .., 1)` (:293), and
`allow_proxy_protocol_peer` (:305) which is allow-shaped. So `deny` is a
parameter here too, not module state: one rule read differently per call.
Both earlier gates return 0 regardless of the flag (access.c:49-53), and
that is preserved.

The fix needed a second distinction oc did not have. Upstream separates a
FAILED lookup (NULL `gethostbyname` -> return deny) from a SUCCESSFUL one
whose records do not include the peer (falls out of the loop -> return 0).
`forward_resolve` collapsed both into an empty `Vec`, which is precisely
what made the deny side fail open, so it now returns `Option<Vec<IpAddr>>`
- `None` is a failed lookup. The reverse-name confirmation path keeps its
existing fail-closed reading of `None` (clientname.c:437-441).

Tests: the new table asserts the fix, the ASYMMETRY (the identical
unresolvable token on the allow side must still NOT admit - a fix
returning true unconditionally would pass the first assertion and fail
this one), and two controls - a deny token resolving elsewhere leaves the
peer permitted, and one resolving to the peer still blocks. Without the
first control a build that refuses everything satisfies the table, which
is the failure mode a fail-closed change invites.

Non-vacuity measured: restoring `None => false` reddens exactly the new
test. Task 648's sentinel table was re-run end-to-end and is unaffected.

One existing test encoded the fail-open - it asserted a second peer was
admitted while the deny token was unresolvable, which upstream refuses.
Corrected by giving the token a resolution, which is what that test
actually meant to isolate.

* fix(daemon): retarget the inetd start_daemon citation at rsync 3.5.0

The pinned upstream source moved from 3.4.4 to 3.5.0 in #7305, which
changed `PINNED_SOURCE_DIR` and the line manifest the citation gate
resolves against. This branch was written before that landed, so its
`clientserver.c:1559` citation named the 3.4.4 line:

    3.4.4  1559:  return start_daemon(STDIN_FILENO, STDIN_FILENO);
    3.5.0  1738:  return start_daemon(STDIN_FILENO, STDIN_FILENO);

Both occurrences now name 1738. Measured with
`tools/ci/citation_drift_audit.py --ratchet`: daemon goes 3 -> 2, its
baseline value, so no baseline edit is needed.

The two remaining ratchet failures (`core` 3 -> 4 and `protocol` 0 -> 1)
reproduce byte-identically on pristine origin/master and are not from
this branch.
oferchen added a commit that referenced this pull request Aug 24, 2026
* chore(citations): retarget upstream citations at rsync 3.5.0

The audit pinned 3.4.4. Flipping VER alone turns most of the repo red: at
3.5.0 the corpus measured 453 suspected-drift out of 495 string-anchored
citations (91%). The retarget is the work; the flip is one line.

Citations were moved by ordinal mapping rather than arithmetic: for each
flagged citation, find the anchor's occurrence index at 3.4.4 and use the
same index at 3.5.0. That is only sound when the anchor occurs equally
often in both versions, so 418 citations qualified; a further 21 were
already drifted at 3.4.4 and had a unique 3.5.0 anchor, making their
correct line unambiguous. 122 range ENDs were shifted by the same delta as
their start - the CITE regex matches only `file.c:START`, so a first pass
that moves START alone leaves `exclude.c:1381-1237` behind.

Drift falls 453 -> 14 of 495. Every one of the 14 remaining is an anchor
that matches more than one upstream line, so the tool cannot localise it
and its verdict is not evidence; they are recorded in the baseline as
false positives, not as unfixed drift.

Two tool changes come with the flip:

* every hit is printed, not the first 12 - a sweep driven by a truncated
  list is the sweep that leaves the rest behind;
* citations whose anchors resolve nowhere are counted and listed as
  `unresolved` instead of being dropped in silence. That silence is where
  a version bump hides "the code this cites no longer exists": 211 such
  citations exist at 3.5.0, four of which resolved cleanly at 3.4.4.

* chore(citations): fail the audit on a backwards citation range

`CITE` matches only `file.c:START`, so nothing in this tool ever looked at
END. A retarget that moves START therefore leaves END on the old pin and
produces `exclude.c:1381-1237` - which every other check here audits
perfectly clean. That happened 116 times in the 3.5.0 sweep and was caught
by hand, not by the gate.

Assert the structural invariant instead: END >= START. It fails in every
mode including --write-baseline and is deliberately not ratcheted, because
there is no such thing as an accepted backwards range.

Non-vacuity checked by injecting one: the tool reports the file, line and
offending token and exits 1; removing it returns to exit 0.

* chore(citations): move the xtask gate's pin to 3.5.0 alongside the audit

The tree carries two independent citation checks against two independently
pinned upstream releases, and the 3.5.0 retarget moved only one of them.

`xtask/src/commands/citations.rs` is the hard gate: it runs under the
required `nextest` cell and asserts every citation names a file and line the
pinned release actually has. It pinned 3.4.4 via its own MANIFEST_PATH and
PINNED_SOURCE_DIR, so the retargeted citations named 80 lines that release
does not have - `daemon.rs:132` cites `main.c:1948`, and 3.4.4's `main.c` is
1879 lines. Against the regenerated 3.5.0 manifest the same corpus reports 0.

`.github/workflows/citation-drift.yml` fetched only the 3.4.4 tarball, so the
audit would have aborted on a missing source tree. That half failed loudly
rather than silently, but it still failed.

Regenerates the manifest as upstream-3.5.0-lines.tsv (494 files), repoints
the workflow and its job name, and records in both the module doc and
CONTRIBUTING that the two pins move together: they read the same comments
against different trees, so a half-moved pin makes them contradict.

Also retargets three citations in the io_timeout family that the audit could
not resolve. io.c:1151 -> io.c:1281 for the allowed_lull derivation, and
io.c:179 -> io.c:226 for the early-return guard, whose anchor additionally
quoted two joined C lines and so matched nothing anywhere; it now quotes one.
3.5.0 hardened set_io_timeout against a negative or INT_MAX timeout, which oc
does not need - Duration is unsigned and the interval is clamped at both ends
- so the note records why rather than implying a gap.
oferchen added a commit that referenced this pull request Aug 24, 2026
… 3.5.0 (#7321)

#7305 moved the pinned upstream source from 3.4.4 to 3.5.0. Ten PRs
authored before that flip merged after it, so their citations name 3.4.4
line numbers in a tree the gate resolves against 3.5.0. This clears the
`core` ratchet, which five open PRs currently inherit:

    FAIL: core suspected-drift rose 3 -> 4     (before)
    core: suspected-drift=0                    (after)

Every target was verified against BOTH tarballs. Only the first is a
mechanical retarget; the rest needed the enclosing construct because the
anchor the audit extracts is not unique in its file.

1. flags.rs  generator.c:298 -> :304
   `io_error & IOERR_GENERAL` is unique; surrounding context is
   byte-identical.

2. daemon_transfer/connection/mod.rs  clientserver.c:382 -> :425
   `rprintf(FERROR, "` occurs many times. The site is the `@ERROR`
   handler, located by `strncmp(line, "@error", 6)` (3.4.4:381 ->
   3.5.0:424) and confirmed by byte-identical context.

3. flags.rs  options.c:2852-2857 -> :3018-3023
4. invocation/tests.rs  options.c:2850-2851 -> :3016-3017  (two sites)
   Both were already correct 3.4.4 RANGES; the audit flagged them only
   because it anchors on the range's prose (`if (am_sender)`), which
   occurs three times in options.c and is not on the cited line. The
   blocks are byte-identical at a constant +166. The comments are
   re-anchored on `args[ac++] = "--super"` and
   `args[ac++] = "--only-write-batch=X"`, each unique in options.c, so
   the audit can resolve them instead of guessing.

5. invocation/tests.rs  main.c:1839 -> :1919, sender.c:217 -> :501
   ⚠ Neither was reported by the ratchet - it only inspects lines
   containing the word `upstream`, and these sit mid-sentence in a doc
   comment. Both were stale. `sender.c` moved by +284 where options.c
   moved by +166, so an offset applied in bulk would have been wrong;
   each was located by its construct (`if (write_batch < 0) dry_run = 1`
   and `f_xfer = write_batch < 0 ? batch_fd : f_out`).

`core` drops 4 -> 0, so its baseline goes 3 -> 0 in the same commit, as
the baseline file requires - leaving it at 3 would keep accepting drift
that no longer exists and hide the next regression under that headroom.

Deliberately out of scope:
- `protocol` (`flist.c:758`) - the identical fix is already in #7318.
- `daemon` (`clientserver.c:1559`) - same cohort, fixed on #7314.

Measured on 30b95b7: `tools/ci/citation_drift_audit.py --ratchet`
reports core=0; `cargo xtask citations` passes (7826 citations);
`cargo fmt --all -- --check` clean.
oferchen added a commit that referenced this pull request Aug 24, 2026
)

* fix(daemon): render the peer host like upstream, not three ways

The daemon named the peer three different ways for the same missing
hostname: a lowercase `unknown` in the `log format` `%h` escape, the bare
peer address in the `rsync allowed access` / `denied` / `connect from`
lines, and an empty string in `RSYNC_HOST_NAME`. A single session could
therefore log

    rsync allowed access on module m from 127.0.0.1 (127.0.0.1)
    ... h=[unknown] a=[127.0.0.1]

Upstream keeps ONE host string per connection and renders it at every one
of those sites (clientserver.c:1524-1526, :770-771, log.c:583-593), and
that string is never empty or an address. It distinguishes two cases the
`Option<&str>` collapsed:

  UNDETERMINED  reverse lookup is off, so no name was ever sought
                (clientserver.c:126)
  UNKNOWN       a lookup ran and produced nothing - the 0.0.0.0 sentinel,
                a failed reverse lookup, or a rejected forward
                confirmation (clientname.c:34, :112)

`peer_host_display()` is that one rule; the ad-hoc fallbacks at the nine
log helpers, the `%h` renderer and the exec environment are gone, and
`format_host()` (the address-substituting one) is deleted.

Measured against the real rsync 3.5.0 daemon serving the same config:

  case                        upstream %h / %a       oc before      oc after
  TCP, reverse lookup = yes   localhost/127.0.0.1    match          match
  TCP, reverse lookup = no    UNDETERMINED/127.0.0.1 unknown/...    match
  rsh, no peer env            UNKNOWN/0.0.0.0        unknown/...    match
  rsh, REMOTE_HOST set        UNKNOWN/192.0.2.55     unknown/...    match

`%a` needed no change - it already rendered the resolved peer address.

Scope: this is the display, log and environment rule only. Upstream also
feeds these sentinels to `allow_access()`, and clientname.c:93-95
documents `UNKNOWN` as usable in a `hosts allow` line; adopting that
would widen oc's ACL matching, so access control keeps consuming the
`Option<&str>` unchanged and the question is filed separately.

Two existing tests pinned the pre-fix behaviour and are corrected: the
`RSYNC_HOST_NAME` assertion expected an empty string, and `format_host`
had three tests asserting the address substitution.

* fix(daemon): match the host sentinels in hosts allow, as upstream does

Upstream documents `UNKNOWN` as a value an operator may put in a
`hosts allow` line (clientname.c:91-94), and hands `allow_access()` the
same never-empty host string its log lines print (clientserver.c:769-773).
`match_hostname` refuses only a NULL or empty name (access.c:37-38), so a
sentinel is matched like any other name.

oc modelled the host as `Option<&str>` and passed `None`, so both
sentinels were unmatchable. Measured on 3.5.0 and oc, `reverse lookup =
no`, loopback peer:

  hosts allow = UNDETERMINED    upstream ALLOWED   oc DENIED
  hosts allow = other.example   upstream DENIED    oc DENIED   (control)
  hosts allow = 127.0.0.1       upstream ALLOWED   oc ALLOWED  (control)

TWO defects, and fixing the first alone was INERT - the end-to-end
measurement still showed DENIED on every row:

1. The sentinel never reached the matcher. `permits()` now takes a
   `PeerHost`, built by the same rule the display path uses, so the string
   an ACL matches is the string the log line prints.

2. `HostnamePattern::matches` compared case-SENSITIVELY against a pattern
   lowercased at parse time. That held only because every host until now
   arrived pre-lowercased from DNS via `normalize_hostname_owned`.
   Upstream lowercases the LIST (`strlower`, access.c:251) and matches
   with `iwildmatch`, the case-INSENSITIVE form (access.c:46) - so
   `unknown` matches `UNKNOWN` there. The host is now folded at the match
   site, which fixes the exact, suffix and wildcard arms together.

The `Resolved`/`Sentinel` distinction is kept because oc has one rule
upstream does not: a hostname-based DENY rule fails closed when no name
was resolved (GHSA-rjfm-3w2m-jf4f). Upstream can rely on reverse DNS
being cached from before `daemon chroot`; oc resolves per connection
after a process-wide chroot, where a chroot without NSS silently yields
no name. That guard is re-keyed from `hostname.is_none()` to
`!host.is_resolved()` - the SAME predicate, since `PeerHost::new` returns
`Sentinel` exactly when the resolved name is absent - so the allow-side
sentinels match without disarming it.

Tests: a 6-row table asserting the outcome of a real loopback
connection, run against oc AND the real 3.5.0 binary. It carries both
sentinel spellings and the wildcard arm, two controls (an unrelated
hostname rule still refuses; an address rule still admits, proving the
directive is live rather than ignored), and the discriminator - with
`reverse lookup = yes` a resolved peer must NOT match `UNDETERMINED`, so
a build that matched the sentinel unconditionally fails exactly one row.
Non-vacuity measured per half: reverting either the pass-through or the
case fold reddens the oc cell alone and leaves the upstream oracle green.

The harness pins the daemon's stdin to /dev/null. Without it the daemon
takes its single-connection path, never listens, and every row reports
"connection refused" - identical output for rows that must differ, which
is a broken instrument rather than a result. That is how the first
measurement of this defect went wrong.

* refactor(daemon): make the fail-closed deny guard compiler-enforced

The guard that refuses a peer when a hostname-based `hosts deny` rule
cannot be evaluated (GHSA-rjfm-3w2m-jf4f) asked `!host.is_resolved()`.
That is correct today, but it rests on a biconditional over the two
current `PeerHost` variants - sentinel iff no name was resolved - and the
biconditional is not enforced anywhere. A third variant, say a
resolved-but-empty name, would make `is_resolved()` answer for a state
nobody considered and would default it into "allowed", silently, at the
one site in the module where being wrong is a security regression rather
than a parity one.

The guard now matches the enum exhaustively and `is_resolved()` is
deleted rather than left available. Adding a variant is a compile error
instead of an inherited default, so the property is checked by the
compiler rather than argued in a comment or trusted from a review.

Non-vacuity measured: adding a probe variant produces

  error[E0004]: non-exhaustive patterns: `PeerHost::ResolvedButEmpty` not
  covered --> crates/daemon/src/daemon/module_state/definition.rs:281:39

at the guard, and a second E0004 at `as_str()` - the other site a new
state must be reasoned about. Behaviour is unchanged: 599 access-control
tests and the sentinel parity table pass before and after.

Same technique as enumerating the drains by deleting the ambiguous API,
applied prospectively rather than to find today's callers.

* fix(daemon): hosts deny fails CLOSED on an unresolvable token

CVE-2026-70452's sibling. Upstream returns the caller's `deny` flag when
the forward lookup of a configured token fails (access.c:57-63):

    if (!(hp = gethostbyname(tok))) {
        /* A deny-list hostname token we cannot resolve must fail CLOSED:
         * we can't prove the peer isn't the denied host ... */
        return deny;
    }

oc returned "no match" for both lists, so `hosts deny = host.example`
admitted every peer whenever that name would not resolve - a fail-OPEN on
a deny rule, reachable by making the operator's DNS unavailable.

Measured on 3.5.0 and oc, `reverse lookup = yes`, loopback peer:

  hosts deny = unresolvable.example.com   upstream DENIED   oc ALLOWED
  hosts deny = 203.0.113.9   (control)    upstream ALLOWED  oc ALLOWED
  hosts deny = 127.0.0.1     (control)    upstream DENIED   oc DENIED

All three now agree.

ENUMERATED rather than generalised. Upstream has ONE decision site and
threads a per-call flag to it - `access_match(allow_list, .., 0)`
(access.c:284), `access_match(deny_list, .., 1)` (:293), and
`allow_proxy_protocol_peer` (:305) which is allow-shaped. So `deny` is a
parameter here too, not module state: one rule read differently per call.
Both earlier gates return 0 regardless of the flag (access.c:49-53), and
that is preserved.

The fix needed a second distinction oc did not have. Upstream separates a
FAILED lookup (NULL `gethostbyname` -> return deny) from a SUCCESSFUL one
whose records do not include the peer (falls out of the loop -> return 0).
`forward_resolve` collapsed both into an empty `Vec`, which is precisely
what made the deny side fail open, so it now returns `Option<Vec<IpAddr>>`
- `None` is a failed lookup. The reverse-name confirmation path keeps its
existing fail-closed reading of `None` (clientname.c:437-441).

Tests: the new table asserts the fix, the ASYMMETRY (the identical
unresolvable token on the allow side must still NOT admit - a fix
returning true unconditionally would pass the first assertion and fail
this one), and two controls - a deny token resolving elsewhere leaves the
peer permitted, and one resolving to the peer still blocks. Without the
first control a build that refuses everything satisfies the table, which
is the failure mode a fail-closed change invites.

Non-vacuity measured: restoring `None => false` reddens exactly the new
test. Task 648's sentinel table was re-run end-to-end and is unaffected.

One existing test encoded the fail-open - it asserted a second peer was
admitted while the deny token was unresolvable, which upstream refuses.
Corrected by giving the token a resolution, which is what that test
actually meant to isolate.

* fix(daemon): retarget the inetd start_daemon citation at rsync 3.5.0

The pinned upstream source moved from 3.4.4 to 3.5.0 in #7305, which
changed `PINNED_SOURCE_DIR` and the line manifest the citation gate
resolves against. This branch was written before that landed, so its
`clientserver.c:1559` citation named the 3.4.4 line:

    3.4.4  1559:  return start_daemon(STDIN_FILENO, STDIN_FILENO);
    3.5.0  1738:  return start_daemon(STDIN_FILENO, STDIN_FILENO);

Both occurrences now name 1738. Measured with
`tools/ci/citation_drift_audit.py --ratchet`: daemon goes 3 -> 2, its
baseline value, so no baseline edit is needed.

The two remaining ratchet failures (`core` 3 -> 4 and `protocol` 0 -> 1)
reproduce byte-identically on pristine origin/master and are not from
this branch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant