Skip to content

fix(daemon): resolve the real peer address on both stdio paths - #7303

Merged
oferchen merged 2 commits into
masterfrom
fix/daemon-peer-address
Aug 14, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/daemon-peer-address

Conversation

@oferchen

Copy link
Copy Markdown
Owner

What

hosts allow / hosts deny were evaluated against a synthetic 127.0.0.1:0 on both stdio daemon entry points. The canonical "local only" rule admitted every client; an allow-list naming real subnets rejected every legitimate one. Broken in both directions depending on the config, and %a / %h misattributed every audit line.

The two paths are not the same case

That is what made the old code look defensible, and it is why the fix has two halves:

upstream oc before
inetd / socket activation (am_daemon > 0) fd 0 is the connected socket; client_addr() skips the env arm and client_sockaddr() reads the peer via getpeername (clientname.c:80-83, :37-45) fabricated 127.0.0.1, with a comment claiming "there is no TCP socket to query"
daemon behind a remote shell (am_daemon < 0) fd 0 is a pipe; seed "0.0.0.0", then the first of REMOTE_HOST / SSH_CONNECTION / SSH_CLIENT / SSH2_CLIENT, truncated at the first space, kept only if it parses (clientname.c:63-78) fabricated 127.0.0.1; none of those four variables appeared anywhere in the tree

Both sites carried an upstream: comment asserting that upstream uses 127.0.0.1:0. It does not, on either path, and on the inetd path the stated premise is simply false. Those comments are why the hole survived review; they are deleted and replaced with real citations.

The 0.0.0.0 seed is the security-relevant half: it matches no realistic allow token, so a remote-shell daemon with no peer information in its environment fails closed, where 127.0.0.1 failed open against exactly the rule operators write to mean "local only".

Also mirrored

  • getpeername failure aborts with RERR_SOCKETIO rather than substituting a placeholder (clientname.c:41-45). Serving a session whose peer cannot be named would evaluate the ACL against nothing.
  • IPv4-mapped IPv6 normalisation (::ffff:a.b.c.d → IPv4) before any lookup or comparison (clientname.c:47-74). This changes what an IPv4 hosts allow matches on a dual-stack listener, so it is part of the ACL contract, not cosmetics.

One deliberate, documented narrowing

A peer that has an address but not an IP one — an AF_UNIX socketpair, as used by systemd socket activation with Accept=yes and by RSYNC_CONNECT_PROG — degrades to the same 0.0.0.0 sentinel instead of aborting. Upstream serves that configuration: getpeername succeeds, and the getnameinfo that follows fails but its return value is never checked (clientname.c:81), so the address is simply left empty. Both "" and 0.0.0.0 match no realistic allow token, so the ACL outcome is identical; the sentinel just stops oc inventing an address it does not have.

I found this the honest way: the first revision aborted, and it broke the existing daemon_empty_digest_list_refused tests, which hand the daemon a UnixStream::pair(). I verified those three pass on clean origin/master before concluding it was my regression rather than a pre-existing failure.

No new unsafe, no new dependency

socket2 is already a direct dependency of crates/daemon (Cargo.toml:87, v0.6.5). SockRef::from(&io::Stdin) borrows fd 0 through AsFd — the same construction is_stdin_socket() already uses to classify that descriptor. The task anticipated relocating unsafe into fast_io; there is none to relocate.

Tests — one per entry point

A per-path test would have passed on whichever path its author happened to pick, which is how this survived.

  • tests/daemon_stdio_peer_address_acl.rs (remote shell): the loopback rule must DENY (it ADMITTED before) and REMOTE_HOST must ADMIT (it would have been DENIED before, since the fabricated peer was never 192.0.2.7). Each is the other's control. Plus SSH_CONNECTION first-field truncation.
  • tests/daemon_inetd_peer_address_acl.rs (inetd): the daemon's socket is peered over IPv6 loopback, so the fabricated 127.0.0.1 and the true ::1 cannot coincide, and both directions are asserted.

⚠ An earlier revision of the inetd file used 127.0.0.2, which silently skipped on macOS (only 127.0.0.1 is configured there). It reported "2 passed" in 0.00s and proved nothing on half the CI matrix. Caught by checking --nocapture for the skip reason rather than trusting the green.

One case (subnet_allow_does_not_admit_an_unknown_peer) is explicitly annotated as not discriminating — 127.0.0.1 fails a 198.51.100.0/24 rule too, so it passed pre-fix. It is kept for the second operator-visible symptom, and says so.

Non-vacuity

Restoring the fabricated address at each site independently:

  • remote shell: 3 of 4 cases turn red (the 4th is the annotated non-discriminating one);
  • inetd: both cases turn red.

Verification

cargo fmt --all -- --check                                                       clean
cargo clippy --locked --workspace --all-targets --all-features --no-deps -D warnings  clean
cargo nextest run -p daemon -E 'test(peer)+test(host)+test(inetd)+test(access)+test(module)'   652 passed
cargo nextest run -E 'binary(/daemon/)'                                          67 passed
cargo nextest run -E 'binary(/peer_address_acl/)'                                6 passed

Scope

Task 401, covering 412 / 413 / 414. Deliberately not included: 416 (%a / %h) is gated on this landing — rendering those from a fabricated address is the same defect in a costume — and 417, which on reading upstream turns out to be client-side (start_inband_exchange, clientserver.c:263), not daemon, and is unrelated to the peer address.

`hosts allow` / `hosts deny` were evaluated against a synthetic
`127.0.0.1:0` on both stdio entry points, so the canonical "local only"
rule admitted every client and an allow-list naming real subnets rejected
every legitimate one. Broken in both directions, depending on the config.

The two paths are NOT the same case, which is what made the old code look
defensible:

- inetd / socket activation (upstream `am_daemon > 0`): fd 0 IS the
  connected socket. `client_addr()` skips the environment arm entirely and
  `client_sockaddr()` reads the peer with `getpeername`
  (clientname.c:80-83, :37-45). oc was discarding an available value, and
  its comment's premise - "there is no TCP socket to query" - was false.
- daemon behind a remote shell (`am_daemon < 0`): fd 0 is a pipe and
  `getpeername` genuinely cannot work. Upstream seeds `"0.0.0.0"` then
  takes the first of REMOTE_HOST, SSH_CONNECTION, SSH_CLIENT, SSH2_CLIENT,
  truncated at the first space and kept only if it parses
  (clientname.c:63-78). None of those four variables appeared anywhere in
  the tree.

Both oc sites carried an `upstream:` comment asserting that upstream uses
`127.0.0.1:0`. It does not, on either path. Those comments are why the
hole survived review, and they are deleted.

The `0.0.0.0` seed is the security-relevant half: it matches no realistic
allow token, so a remote-shell daemon with no peer information in its
environment fails CLOSED where `127.0.0.1` failed open against exactly the
rule operators write to mean "local only".

Also mirrored: `getpeername` failure aborts with RERR_SOCKETIO rather than
substituting a placeholder (clientname.c:41-45), and an IPv4-mapped IPv6
peer (`::ffff:a.b.c.d`) is normalised to IPv4 before any ACL comparison
(clientname.c:47-74), which changes what an IPv4 `hosts allow` matches on a
dual-stack listener.

One deliberate, documented narrowing of the abort: a peer that has an
address but not an IP one - an AF_UNIX socketpair, as used by systemd
socket activation with `Accept=yes` and by RSYNC_CONNECT_PROG - degrades to
the same `0.0.0.0` sentinel instead of failing. Upstream serves that
configuration (its `getnameinfo` return is unchecked, leaving the address
empty); refusing it would have been a regression, and it is what the
existing `daemon_empty_digest_list_refused` tests exercise.

No unsafe is added: `socket2` is already a direct dependency of
`crates/daemon`, and `SockRef::from(&io::Stdin)` borrows fd 0 through
`AsFd` - the same construction `is_stdin_socket()` already uses.

Tests, one per entry point because a per-path test would have passed on
whichever path its author picked:

- `tests/daemon_stdio_peer_address_acl.rs` - remote shell. The loopback
  rule must DENY (it ADMITTED before) and REMOTE_HOST must ADMIT (it would
  have been DENIED before). Each is the other's control.
- `tests/daemon_inetd_peer_address_acl.rs` - inetd, peered over IPv6
  loopback so the fabricated `127.0.0.1` and the true `::1` cannot
  coincide. An earlier revision used `127.0.0.2` and silently SKIPPED on
  macOS, proving nothing on half the matrix.

Non-vacuity was proven by restoring the fabricated address at each site
independently: 3 of 4 remote-shell cases and both inetd cases turn red.
@github-actions github-actions Bot added the bug Something isn't working label Aug 13, 2026
…form

The three Windows cells were failing to BUILD, not to test:

  Windows ACL/xattr                          step 7 "Build oc-rsync"
  interop (Windows, best-effort)             step 5 "Build oc-rsync"
  Feature flags / concurrent-sessions        step 9 "Test" (compiles first)

One cause for all three. `normalize_v4_mapped` is called only from
`inherited_socket_peer_addr`, which is `#[cfg(unix)]` - a V4MAPPED peer
can only arrive through the inetd stdin socket that function reads. On
Windows the caller is compiled out, the function is dead, and
`RUSTFLAGS: "-D warnings"` (set in `_interop-windows.yml:70` and
`_test-features.yml:77`) turns the `dead_code` warning into a build
failure. Its two unit tests are gated for the same reason.

MEASURED, not inferred. Windows-gnu cross-check on the PR head, which
reproduces the failure exactly:

  cargo check --target x86_64-pc-windows-gnu --all-features -p daemon
  warning: function `normalize_v4_mapped` is never used
     --> crates/daemon/src/daemon/peer_address.rs:124:4

and after the fix, with `-D warnings` and `--all-targets`, plus the
`concurrent-sessions` feature cell separately: both clean.

⚠ It is NOT `SockRef::from(&stdin)`. That reading is structurally sound
about socket2 - on Windows the conversion needs `S: AsSocket`
(sockref.rs:97-100) and `std::io::Stdin` is `AsHandle` - but it does not
apply here, because BOTH `SockRef::from(&stdin)` sites were already
`#[cfg(unix)]` with explicit non-Unix arms (`peer_address.rs:155`,
`inetd.rs:23-37`), and the two remaining `SockRef::from` calls in
`inetd.rs` sit inside a `#[cfg(unix)]` test. Code that is not compiled on
Windows cannot be the Windows compile error. The other 14 `SockRef::from`
sites in `crates/daemon` all take a real `TcpListener`/`TcpStream`/
`UnixStream`, which do implement `AsSocket` where they are compiled.

No `#[allow(dead_code)]`: per the cross-platform policy the Windows arm
must be as explicit as the Unix one, and a suppressed warning would hide
the next instance of this exact class.
@oferchen
oferchen enabled auto-merge (squash) August 14, 2026 04:02
@oferchen
oferchen merged commit 490134f into master Aug 14, 2026
67 checks passed
@oferchen
oferchen deleted the fix/daemon-peer-address branch August 14, 2026 04:50
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
* fix(daemon): resolve the real peer address on both stdio paths

`hosts allow` / `hosts deny` were evaluated against a synthetic
`127.0.0.1:0` on both stdio entry points, so the canonical "local only"
rule admitted every client and an allow-list naming real subnets rejected
every legitimate one. Broken in both directions, depending on the config.

The two paths are NOT the same case, which is what made the old code look
defensible:

- inetd / socket activation (upstream `am_daemon > 0`): fd 0 IS the
  connected socket. `client_addr()` skips the environment arm entirely and
  `client_sockaddr()` reads the peer with `getpeername`
  (clientname.c:80-83, :37-45). oc was discarding an available value, and
  its comment's premise - "there is no TCP socket to query" - was false.
- daemon behind a remote shell (`am_daemon < 0`): fd 0 is a pipe and
  `getpeername` genuinely cannot work. Upstream seeds `"0.0.0.0"` then
  takes the first of REMOTE_HOST, SSH_CONNECTION, SSH_CLIENT, SSH2_CLIENT,
  truncated at the first space and kept only if it parses
  (clientname.c:63-78). None of those four variables appeared anywhere in
  the tree.

Both oc sites carried an `upstream:` comment asserting that upstream uses
`127.0.0.1:0`. It does not, on either path. Those comments are why the
hole survived review, and they are deleted.

The `0.0.0.0` seed is the security-relevant half: it matches no realistic
allow token, so a remote-shell daemon with no peer information in its
environment fails CLOSED where `127.0.0.1` failed open against exactly the
rule operators write to mean "local only".

Also mirrored: `getpeername` failure aborts with RERR_SOCKETIO rather than
substituting a placeholder (clientname.c:41-45), and an IPv4-mapped IPv6
peer (`::ffff:a.b.c.d`) is normalised to IPv4 before any ACL comparison
(clientname.c:47-74), which changes what an IPv4 `hosts allow` matches on a
dual-stack listener.

One deliberate, documented narrowing of the abort: a peer that has an
address but not an IP one - an AF_UNIX socketpair, as used by systemd
socket activation with `Accept=yes` and by RSYNC_CONNECT_PROG - degrades to
the same `0.0.0.0` sentinel instead of failing. Upstream serves that
configuration (its `getnameinfo` return is unchecked, leaving the address
empty); refusing it would have been a regression, and it is what the
existing `daemon_empty_digest_list_refused` tests exercise.

No unsafe is added: `socket2` is already a direct dependency of
`crates/daemon`, and `SockRef::from(&io::Stdin)` borrows fd 0 through
`AsFd` - the same construction `is_stdin_socket()` already uses.

Tests, one per entry point because a per-path test would have passed on
whichever path its author picked:

- `tests/daemon_stdio_peer_address_acl.rs` - remote shell. The loopback
  rule must DENY (it ADMITTED before) and REMOTE_HOST must ADMIT (it would
  have been DENIED before). Each is the other's control.
- `tests/daemon_inetd_peer_address_acl.rs` - inetd, peered over IPv6
  loopback so the fabricated `127.0.0.1` and the true `::1` cannot
  coincide. An earlier revision used `127.0.0.2` and silently SKIPPED on
  macOS, proving nothing on half the matrix.

Non-vacuity was proven by restoring the fabricated address at each site
independently: 3 of 4 remote-shell cases and both inetd cases turn red.

* fix(daemon): gate normalize_v4_mapped to Unix, its only caller's platform

The three Windows cells were failing to BUILD, not to test:

  Windows ACL/xattr                          step 7 "Build oc-rsync"
  interop (Windows, best-effort)             step 5 "Build oc-rsync"
  Feature flags / concurrent-sessions        step 9 "Test" (compiles first)

One cause for all three. `normalize_v4_mapped` is called only from
`inherited_socket_peer_addr`, which is `#[cfg(unix)]` - a V4MAPPED peer
can only arrive through the inetd stdin socket that function reads. On
Windows the caller is compiled out, the function is dead, and
`RUSTFLAGS: "-D warnings"` (set in `_interop-windows.yml:70` and
`_test-features.yml:77`) turns the `dead_code` warning into a build
failure. Its two unit tests are gated for the same reason.

MEASURED, not inferred. Windows-gnu cross-check on the PR head, which
reproduces the failure exactly:

  cargo check --target x86_64-pc-windows-gnu --all-features -p daemon
  warning: function `normalize_v4_mapped` is never used
     --> crates/daemon/src/daemon/peer_address.rs:124:4

and after the fix, with `-D warnings` and `--all-targets`, plus the
`concurrent-sessions` feature cell separately: both clean.

⚠ It is NOT `SockRef::from(&stdin)`. That reading is structurally sound
about socket2 - on Windows the conversion needs `S: AsSocket`
(sockref.rs:97-100) and `std::io::Stdin` is `AsHandle` - but it does not
apply here, because BOTH `SockRef::from(&stdin)` sites were already
`#[cfg(unix)]` with explicit non-Unix arms (`peer_address.rs:155`,
`inetd.rs:23-37`), and the two remaining `SockRef::from` calls in
`inetd.rs` sit inside a `#[cfg(unix)]` test. Code that is not compiled on
Windows cannot be the Windows compile error. The other 14 `SockRef::from`
sites in `crates/daemon` all take a real `TcpListener`/`TcpStream`/
`UnixStream`, which do implement `AsSocket` where they are compiled.

No `#[allow(dead_code)]`: per the cross-platform policy the Windows arm
must be as explicit as the Unix one, and a suppressed warning would hide
the next instance of this exact class.
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