Skip to content

fix(server): bound a peer-named merge file by --confine-root - #7598

Merged
oferchen merged 2 commits into
masterfrom
feat/confine-merge-file-open
Sep 2, 2026
Merged

oferchen merged 2 commits into
masterfrom
feat/confine-merge-file-open

Conversation

@oferchen

@oferchen oferchen commented Sep 1, 2026 •

Copy link
Copy Markdown
Owner

The gap

Testsuite cell rrsync-merge-file-confine (3.5.0) passes on upstream and failed
on oc.

A dir-merge rule travels over the protocol as a filter rule, not in the argv an
rrsync wrapper validates, so the peer names the merge file.
--filter=':-s ../outside-secret' reads a file beside the restricted directory,
and because an exclude-only merge turns every line into a pattern, nothing fails
to parse: the file's contents come back as absences from the file list. No
error, no verbosity, and on a pull no --delete either.

oc walked the ownership of that open but never bounded it. Two halves were
missing, and each is independently load-bearing:

  1. filters::merge_open::read_to_string - the per-directory merge open the
    generator scan and the receiver delete pass both use - took the ancillary
    entry point (operator_read_to_string), so the walk followed a trusted
    symlink and judged nothing about where it landed. Its sibling in the
    local-copy engine (engine::local_copy::dir_merge::load::open_merge_file)
    was already confined.
  2. Nothing published --confine-root into the walk's session. Both
    install_local_session call sites passed confine_root: None, and
    --server mode installed no session at all, so even the already-confined
    opens measured against an empty root.

The fix

  • New fast_io::operator_read_to_string_confined, the confined counterpart of
    operator_read_to_string (as operator_open_read_confined is to
    operator_open_read). The filters seam routes onto it - one seam, three call
    sites (enter_directory, load_inline_dir_merge, merge::read::read_rules).
  • install_local_session now carries the --confine-root root, and both the
    client (workflow::run::execute) and the non-daemon server
    (run_server_mode) publish it. A daemon still publishes its module root
    (install_daemon_session), matching upstream's
    am_daemon ? module_dir : confine_root; --server --daemon is dispatched
    before run_server_mode, so the arm that honours a peer-supplied argv value
    is never a daemon.

Without --confine-root the session is (optout=false, root=None) on both
paths - byte-identical to today - so nothing changes for an ordinary transfer.

Kernel-anchored, not lexical

The cell's second leg reaches the tree through root/self-alias -> ., so
rsync's tracked path sits one component deeper than the kernel's. The merge
file's own ../secret then normalises to root/secret textually - inside
the root - while the kernel lands outside:

named:    <root>/self-alias/outside-link
link:     outside-link -> ../secret
LEXICAL:  <root>/self-alias/../secret == <root>/secret   -> inside   (wrong)
KERNEL:   self-alias resolves to <root>, then ../secret  -> outside  (right)

AbsPathTracker already advanced by RESOLVED components, seeded from
std::env::current_dir() (the physical cwd), which is upstream's own
requirement at syscall.c:311-322. crates/fast_io/tests/confine_root_merge_alias.rs
pins it, with lexical_normalisation_lands_inside_the_root as the instrument
check: the fixture is provably invisible to a string comparison.

Second defect, found while measuring

The server argv parser filtered every . operand as the cwd placeholder.
Upstream consumes one slot - dir = argv[0]; argc--; argv++; - whatever it
holds, so rsync host:. dest/ (which rrsync emits as -- . .) left oc's server
with no operand at all. Measured: an empty file list and a silent rc=0 no-op,
in both directions. The placeholder is now spent once.

Two existing cells asserted pos_args.is_empty() for -- . .; they encoded
this behaviour and are corrected to ["."].

Sites deliberately left alone

  • daemon::sections::module_access::helpers::read_patterns_from_file - the
    daemon's own include from / exclude from. Upstream exempts exactly these
    (if (!daemon_config_filter_file)); they legitimately live outside the
    module.
  • daemon::operator_file (config, motd, secrets) - operator-configured, and
    upstream opens them with operator_path_resolve = 0.
  • The --files-from opens - a different option family, and one upstream names
    among the opens that "may legitimately live elsewhere" (syscall.c:232-239).
  • $HOME/.cvsignore - named by --cvs-exclude, not by the peer.
  • cli::frontend::filter_rules::sources (--*clude-from, CLI merge) and the
    local-copy engine loader - both already confined.

Upstream

  • exclude.c:1668-1684 parse_filter_file() - the
    if (!daemon_config_filter_file) operator_path_resolve = 1; around
    open_no_attacker_symlinks()
  • syscall.c:186-240 abspath_outside_confinement()
  • syscall.c:311-322 - the confine_root arm seeds abspath from getcwd()
    because "curr_dir is the lexical name change_dir() was given"
  • syscall.c:136-144 confinement_root()
  • main.c:966-975 do_server_sender(), main.c:1192-1194 do_server_recv()

Evidence

Upstream control - 3.5.0 built from the pinned tree: PASS.
oc before: FAIL - "the server read a merge file outside the restricted dir".

Mutation A - revert merge_open to the ancillary open, rebuild, rerun:
FAIL, and strace shows the escape as syscalls:

openat(AT_FDCWD, ".", O_PATH|O_DIRECTORY) = 3
newfstatat(3, "..", ...)                  = 0
openat(3, "..", O_NOFOLLOW|O_PATH|O_DIRECTORY) = 4
newfstatat(4, "outside-secret", {S_IFREG|0644, st_size=11}) = 0
openat(4, "outside-secret", O_RDONLY|O_NOFOLLOW) = 3   <- the read

with secretword missing from the delivered file list. With the fix the walk
stops at the confinement check and secretword arrives.

Mutation B - keep the confined open but drop the server's
install_local_session(.., confine_root), rebuild, rerun: FAIL, same
assertion. Each half is independently load-bearing: the routing without the
published root confines nothing, and the published root without the routing is
never consulted at that open.

Non-vacuity - the cell carries its own controls, and both hold: an in-tree
.rsync-filter is still read and obeyed (intree-dropped excluded,
intree-kept delivered), and the in-tree merge reached through the SAME
symlinked source arg still works. confine_root_merge_alias.rs repeats both at
the resolver level, plus an ancillary-open control showing --log-file and the
--*-from family are still not bound by the root.

Both testsuite legs, Linux (aarch64), 3.5.0, pipe transport:

  • nonroot: 253 passed / 6 failed / 86 skipped; mismatches vs the manifest:
    daemon-scan-cwd-desync (EAGAIN under a loaded VM - passes 3/3 re-run in
    isolation) and simd-checksum (skipped, simdtest not built on this host).
    rrsync-merge-file-confine PASS.
  • root (sudo): 281 passed / 7 failed / 57 skipped; mismatches: batch-file-symlink
    (passes in isolation on a re-run - the char-device fixture flaked under load)
    and simd-checksum again. rrsync-merge-file-confine PASS.

--expect-result fails on an unexpected PASS too, so the manifest flip is
confirmed by the run rather than asserted.

cargo nextest run -p fast_io -p filters: 2349 passed, 0 failed.
Clippy -D warnings clean on the pinned 1.88.0 toolchain;
tools/ci/check_rustfmt_all.py clean.

@oferchen
oferchen force-pushed the feat/confine-merge-file-open branch from 7a10545 to 3053c63 Compare September 1, 2026 10:50
A dir-merge rule travels over the protocol as a filter rule, not in the
argv an rrsync wrapper validates, so the PEER names the merge file:
`--filter=':-s ../outside-secret'` reads a file beside the restricted
directory. An exclude-only merge turns every line into a pattern, so
nothing fails to parse and the file's contents come back as absences from
the file list - no error, no verbosity, and on a pull no --delete either.

oc walked the ownership of that open but never bounded it:

  - `filters::merge_open::read_to_string` - the per-directory merge open
    the generator scan and the receiver delete pass both use - took the
    ANCILLARY entry point (`operator_read_to_string`), so the walk
    followed a trusted symlink and judged nothing about where it landed.
    Its sibling in the local-copy engine was already confined.
  - Nothing published `--confine-root` into the walk's session. Both
    `install_local_session` call sites passed `confine_root: None`, and
    `--server` mode installed no session at all, so even the already
    confined opens measured against an empty root.

Route the merge open through a new `operator_read_to_string_confined`,
and give `install_local_session` the root so the client and the
non-daemon server both publish it. A daemon still publishes its module
root instead, matching upstream's `am_daemon ? module_dir : confine_root`
- `--server --daemon` is dispatched before `run_server_mode`, so the arm
that honours a peer-supplied argv value is never a daemon.

The resolution is kernel-anchored, which is what the symlinked-source-arg
case needs: reached through `root/self-alias -> .`, the merge file's own
`../secret` normalises to `root/secret` textually - inside - while the
kernel lands outside. `AbsPathTracker` advances by RESOLVED components
from the physical cwd, so it sees the escape a string comparison cannot.

Second defect, found while measuring the cell: the server argv parser
filtered EVERY `.` operand as the cwd placeholder. Upstream consumes one
slot - `dir = argv[0]; argc--; argv++;` - whatever it holds, so
`rsync host:. dest/` (which rrsync emits as `-- . .`) left oc's server
with no operand at all: an empty file list and a silent rc=0 no-op.
Spend the placeholder once.

upstream: exclude.c:1668-1684 parse_filter_file() - the
`if (!daemon_config_filter_file) operator_path_resolve = 1;` around
`open_no_attacker_symlinks()`; syscall.c:186-240
abspath_outside_confinement(); syscall.c:311-322 - the `confine_root` arm
seeds `abspath` from getcwd() because "curr_dir is the lexical name
change_dir() was given"; syscall.c:136-144 confinement_root();
main.c:966-975 do_server_sender(); main.c:1192-1194 do_server_recv().

testsuite: rrsync-merge-file-confine flips fail -> pass in the nonroot
and root 3.5.0 manifests. Reverting either half reopens the escape and
reddens the cell.
@oferchen
oferchen merged commit 107314c into master Sep 2, 2026
72 checks passed
@oferchen
oferchen deleted the feat/confine-merge-file-open branch September 2, 2026 05:37
oferchen added a commit that referenced this pull request Sep 2, 2026
…e tree (#7626)

An accuracy audit of every performance, coverage and security claim in
README.md and SECURITY.md against a workflow file, a committed manifest, a
test or a measured number. Most of the 3.5.0 alignment already checked out;
what follows is what did not.

Stale testsuite outcomes. Both files carried 254/6 and 282/7 for the two
full-corpus legs, "7 of 345 tests currently diverge", and "32 across all
four". The committed manifests say 257/3 and 286/3, with 3 distinct
divergences on the pipe legs and 29 across all four; #7596, #7598 and #7599
each fixed a divergence and flipped its manifest rows without refreshing the
prose. Re-derived with the awk one-liner both files already publish.

An unmeasured measurement. Both files said "a measured run of 100,000
sessions consumed a single bgid" as the evidence that the u16 bgid namespace
cannot be exhausted. No such run exists in the tree, and it could not: per
docs/audits/bgid-lifecycle.md section 5, BufferRing and BgidAllocator are
constructed only inside fast_io and its tests, so an accepted connection
consumes no bgid at all. The conclusion holds; the evidence for it is now the
structural fact rather than an invented number.

A benchmark shape no published release carries. The Performance section
described the dual-baseline, peak-RSS, corpus-rate, spread-carrying report as
what is "attached to every GitHub release", and the image alt text named both
baselines. The linked image is served from the latest release, v0.6.4, whose
benchmark_results.json has one baseline (3.4.4), a 148 MB corpus, and only
mean/min/max per series. The paragraph now describes the harness and says
plainly which releases predate it.

MAX_WIRE_DEL_STAT. SECURITY cited crates/protocol/src/flist/delete_stats.rs,
which does not exist, and claimed a cap "well below the upstream lowered
ceiling". The reader is crates/protocol/src/stats/delete.rs and its cap is
1 << 28 - exactly upstream's rsync.h:187 value, unchanged in 3.4.4 and 3.5.0 -
and it rejects rather than clamps. Parity is the right answer; "well below"
was not.

Landlock framing. README presented the daemon's Landlock layer as "cargo
feature landlock", which reads as opt-in. crates/daemon pins fast_io with
that feature under cfg(target_os = "linux"), so it is on in every Linux build
including the released binaries. SECURITY's ABI enumeration stopped at v3
while the helper requests AccessFs::from_all(ABI::V5).

Benchmark report: publish the sample size. stats() records `runs` with the
stated intent that "a reader can tell a three-run cell from a six-run one",
but the report left it in the JSON. A reset cell is timed 3 times with the
warm-up discarded, so its median rests on 2 samples, and it rendered
identically to a 6-run cell's median over 5. One `Runs` column per row states
it - compare() hands every series in a row the same count - and the footnote
now names which population the median and the spread each describe.

benchmark_chart.py's no-baselines fallback said "3.4.4" while
benchmark_report.py's said "3.5.0"; two renderers of one file would have
named different upstream releases for the same run.

Verified and left alone: the 33-CVE count, the five new options and three new
daemon directives, the 13 Aug 2026 date, PROTOCOL_VERSION 32 /
SUBPROTOCOL_VERSION 0 and byte-identical errcode.h (checked against the
pinned 3.5.0 source); the 345/155 corpus sizes and the two tcp manifest rows;
the interop version lists against run_interop.sh; the 26 fuzz targets against
fuzz/Cargo.toml, name for name; the empty known-failures roster already
described as historical; daemon-seccomp absent from the default set and from
the release build; and every 3.4.4 mention that is deliberately about 3.4.4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant