Skip to content

fix(batch): route batch file opens onto the ownership walk at upstream modes - #7443

Merged
oferchen merged 1 commit into
masterfrom
fix/batch-file-ownership-walk
Aug 22, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/batch-file-ownership-walk

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Routes the three --read-batch / --write-batch / .sh opens onto the
ownership walk, and corrects the create modes to upstream's.

Upstream

All three go 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. 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:

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:

pre-existing 0666 upstream 3.5.0 oc (before)
BATCH 0666 0666
BATCH.sh 0666 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 TOCTOU window the walk exists to close.

Shape

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 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 umask
pinned to 0 via pre_exec. That pin is what makes the assertions
discriminating: under the usual 022 a 0666 request lands as 0644 and a
0600 request lands as 0600, so the two spellings become
indistinguishable. 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 other two stayed green (--no-fail-fast, so the kill list is
complete rather than truncated):

  • create_write reverted to File::create → write_batch_creates_its_files_with_upstream_modes
    fails, left: 438 (0o666) vs right: 384 (0o600).
  • post-hoc chmod 0700 restored → rerunning_write_batch_leaves_an_existing_files_mode_alone
    fails, left: 448 (0o700) vs right: 438 (0o666).

Verification

  • cargo fmt --all -- --check clean; cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings exit 0.
  • cargo nextest run -p batch -p fast_io: 979/979.
  • New test file 3/3.
  • crates/batch keeps #![deny(unsafe_code)] - the walk is reached through
    fast_io's safe public API, no unsafe added to a denying crate.

…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).
@github-actions github-actions Bot added the bug Something isn't working label Aug 22, 2026
@oferchen
oferchen merged commit 6f04308 into master Aug 22, 2026
75 checks passed
@oferchen
oferchen deleted the fix/batch-file-ownership-walk branch August 22, 2026 16:45
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
…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.
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