Repository navigation
fix(batch): route batch file opens onto the ownership walk at upstream modes - #7443
Merged
Merged
Conversation
…m modes
Upstream opens all three batch files through one primitive, each with its
own literal mode:
batch_sh_fd = open_no_attacker_symlinks(filename, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR|S_IXUSR); batch.c:254
batch_fd = open_no_attacker_symlinks(batch_name, O_WRONLY|O_CREAT|O_TRUNC,
S_IRUSR|S_IWUSR); batch.c:263
batch_fd = open_no_attacker_symlinks(batch_name, O_RDONLY, ...); batch.c:267
oc used plain `File::open` / `File::create` at all four call sites, so a
symlink planted at any component redirected the open - and for the two write
sides that means a create-and-truncate landing somewhere the operator never
named.
Measured against rsync 3.5.0, the modes diverged too, and in two opposite
directions:
file upstream oc @umask 022 oc @umask 000
BATCH 0600 0644 0666
BATCH.sh 0700 0700 0700
Owner-only on the batch file is load-bearing rather than incidental: the
batch stream carries the transferred file contents, so a world-readable
batch publishes everything the transfer moved, and a world-writable one lets
an attacker choose what a later --read-batch writes.
The `.sh` reached 0700 only via a post-hoc `chmod`, which is the second
divergence: upstream passes the mode to O_CREAT and never chmods, so
re-running over an existing file truncates it and leaves its mode alone.
Measured on both: pre-existing 0666 files stay 0666 upstream, while oc forced
the script back to 0700. Passing the mode to the create fixes both cells at
once and lets `set_script_permissions` go, removing a duplicated owner of the
mode along with the window the walk exists to close.
Adds `fast_io::operator_open_write_create` (the O_WRONLY|O_CREAT|O_TRUNC arm
the primitive lacked) and a `crates/batch/src/operator_file.rs` platform seam,
matching the per-crate shape already used by cli and core: the cfg is written
once, and the walk is deliberately not re-exported as if it were portable, so
its absence on non-Unix stays visible at the call site.
Tests pin both rules with the child umask pinned to 0 - without that, umask
022 turns a 0666 request into 0644 and a 0600 request into 0600, and the two
spellings stop being distinguishable. `pinning_the_child_umask_takes_effect`
is the control for that claim. Non-vacuity proven with two orthogonal
mutations, each killing exactly one test while the others stayed green:
reverting `create_write` to `File::create` fails the mode test (0666 vs 0600),
and restoring the post-hoc chmod fails the pre-existing-mode test (0700 vs
0666).
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…7477) The docs were last refreshed at #7423; 55 PRs have merged since, and the testsuite figures they quote had drifted far enough to understate the current state by roughly half. CHANGELOG: fill in Unreleased for everything merged since #7423. The dominant theme is routing every operator-named auxiliary file open onto the ownership walk - upstream's open_no_attacker_symlinks() applied at the call sites upstream applies it - plus a daemon hardening batch and an alt-dest correctness batch. README and SECURITY: the per-leg outcome tables were re-derived from the committed expect manifests rather than carried forward. Failures fell and the corpus grew, so every figure moved: non-root pipe 43 -> 21 fail (345 -> 349 corpus) root pipe 62 -> 29 fail (345 -> 349 corpus) non-root tcp 42 -> 29 fail (155 -> 158 corpus) root tcp 55 -> 38 fail (155 -> 158 corpus) Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55 across all four. SECURITY, two CVE rows that had gone stale: - CVE-2026-53790 said "under audit". The refusal has since been applied at the live sink - oc-rsync's own single-character config expander, which upstream does not have, so an upstream-shaped port alone would have been inert (#7465, #7430, #7445). - CVE-2026-53795 listed only the staging family. The auxiliary-file family followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459, #7463); what remains is the per-option-family confinement.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…7477) The docs were last refreshed at #7423; 55 PRs have merged since, and the testsuite figures they quote had drifted far enough to understate the current state by roughly half. CHANGELOG: fill in Unreleased for everything merged since #7423. The dominant theme is routing every operator-named auxiliary file open onto the ownership walk - upstream's open_no_attacker_symlinks() applied at the call sites upstream applies it - plus a daemon hardening batch and an alt-dest correctness batch. README and SECURITY: the per-leg outcome tables were re-derived from the committed expect manifests rather than carried forward. Failures fell and the corpus grew, so every figure moved: non-root pipe 43 -> 21 fail (345 -> 349 corpus) root pipe 62 -> 29 fail (345 -> 349 corpus) non-root tcp 42 -> 29 fail (155 -> 158 corpus) root tcp 55 -> 38 fail (155 -> 158 corpus) Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55 across all four. SECURITY, two CVE rows that had gone stale: - CVE-2026-53790 said "under audit". The refusal has since been applied at the live sink - oc-rsync's own single-character config expander, which upstream does not have, so an upstream-shaped port alone would have been inert (#7465, #7430, #7445). - CVE-2026-53795 listed only the staging family. The auxiliary-file family followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459, #7463); what remains is the per-option-family confinement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Routes the three
--read-batch/--write-batch/.shopens onto theownership walk, and corrects the create modes to upstream's.
Upstream
All three go through one primitive, each with its own literal mode:
oc used plain
File::open/File::createat all four call sites, so asymlink planted at any component redirected the open. For the two write sides
that means a privileged create-and-truncate landing where the operator never
named.
The modes diverged too, in two opposite directions
Measured against real rsync 3.5.0:
BATCH060006440666BATCH.sh070007000700Owner-only on the batch file is load-bearing rather than incidental: the
batch stream carries the transferred file contents, so a world-readable
batch publishes everything the transfer moved, and a world-writable one
lets an attacker choose what a later
--read-batchwrites.The
.shreached0700only via a post-hocchmod, which is the seconddivergence. Upstream passes the mode to
O_CREATand never chmods, sore-running over an existing file truncates it and leaves its mode alone:
0666BATCH06660666BATCH.sh06660700Passing the mode to the create fixes both cells at once and lets
set_script_permissionsgo, removing a duplicated owner of the mode alongwith the TOCTOU window the walk exists to close.
Shape
Adds
fast_io::operator_open_write_create- theO_WRONLY|O_CREAT|O_TRUNCarm the primitive lacked - and a
crates/batch/src/operator_file.rsplatformseam matching the per-crate shape already used by
cliandcore: thecfgis written once instead of once per call site, and the walk is deliberately
not re-exported as if it were portable, so its absence on non-Unix stays
visible to a reader of the call site.
Tests
tests/batch_files_created_with_upstream_modes.rs, with the child umaskpinned to
0viapre_exec. That pin is what makes the assertionsdiscriminating: under the usual
022a0666request lands as0644and a0600request lands as0600, so the two spellings becomeindistinguishable.
pinning_the_child_umask_takes_effectis the control forthat claim.
Non-vacuity proven with two orthogonal mutations, each killing exactly one
test while the other two stayed green (
--no-fail-fast, so the kill list iscomplete rather than truncated):
create_writereverted toFile::create→write_batch_creates_its_files_with_upstream_modesfails,
left: 438(0o666) vsright: 384(0o600).chmod 0700restored →rerunning_write_batch_leaves_an_existing_files_mode_alonefails,
left: 448(0o700) vsright: 438(0o666).Verification
cargo fmt --all -- --checkclean;cargo clippy --workspace --all-targets --all-features --no-deps -- -D warningsexit 0.cargo nextest run -p batch -p fast_io: 979/979.crates/batchkeeps#![deny(unsafe_code)]- the walk is reached throughfast_io's safe public API, no unsafe added to a denying crate.