Skip to content

fix(transfer): stop pre-empting the confined -R implied-parent mkdir - #7565

Merged
oferchen merged 3 commits into
masterfrom
fix/relative-implied-parent-preemption
Sep 1, 2026
Merged

oferchen merged 3 commits into
masterfrom
fix/relative-implied-parent-preemption

Conversation

@oferchen

@oferchen oferchen commented Aug 28, 2026 •

Copy link
Copy Markdown
Owner

The upstream chain

Replacing a conflicting destination symlink with a real directory reaches the confined unlink wrapper upstream, not the plain one:

generator.c:1829/1841   delete_item(fname, sx.st.st_mode, del_opts | DEL_FOR_DIR)
delete.c:233/237        ok = del_unlink(fbuf) == 0
delete.c:71-78          do_unlink_atfd(dfd, leaf, 0) against a held dirfd,
                        else robust_unlink(fbuf)
util1.c:545-550         robust_unlink() -> rc = do_unlink_at(fname)

Both arms are the confined wrappers. Upstream issues no plain unlink() on this path. do_unlink_at() in syscall.c is the three-arm contract: symlink_optout_allowed() takes the plain syscall; otherwise owner_walk_parent() then unlinkat(dfd, bname, 0); a refused walk returns -1 rather than falling back.

oc did the opposite. classify_dir_destination removed the symlink with a path-based fs::remove_file, and the comment above it cited syscall.c do_unlink() - a function this path never reaches. That citation is what made a plain unlink look correct here. It is fixed in the same commit.

Both call sites now route through fast_io::unlink_via_sandbox_or_fallback, oc's port of do_unlink_at(). sandbox may be None; that is a supported arm, not a gap, and it errors rather than degrading to a plain syscall when the walk refuses.

The rule this is an instance of

The seccomp allowlist is a deliberate completeness detector. An EPERM on the daemon worker path names an unported confinement site, and the fix is always to port the caller - never to widen the filter.

The worker allowlist is *at-only by design: it was derived from the sites already routed onto the confined resolver, so anything still calling std::fs issues a path-based syscall the filter does not carry. Widening it silences the detector and moves oc away from upstream. Someone will hit this again on mkdir 83 within the week; the answer there is the same.

Why this class is structurally invisible on aarch64

The defect only exists on x86_64, and not by accident of which host happened to fail. Disassembling Ubuntu amd64 libc.so.6 (glibc 2.44) with a pure-ELF opcode scanner - b8 imm32 followed by 0f 05 inside each symbol body, nothing executed - gives what glibc actually issues:

libc entry point x86_64 syscall
unlink() 87
rmdir() 84
mkdir() 83
rename() 82
symlink() 88
link() 86
readlink() 89
chmod() 90
chown() 92
lchown() 94
open() 257 (openat)

open() is the exception, and it is why the gap survived: it already lowers to openat, so the first operation anyone reaches for to sanity-check the filter is the one that cannot show the defect. stat/lstat are the same shape (newfstatat).

aarch64 control, from asm-generic/unistd.h: __NR_unlink, __NR_mkdir, __NR_rename, __NR_rmdir are absent; __NR_unlinkat is 35. The architecture is *at-only, so an *at-only allowlist is complete there and cannot miss anything. An aarch64 green is not evidence the allowlist is correct - that arch is structurally unable to exercise the gap. Same class as the earlier unlink, readlink and mkdir findings.

The scanner is kept as abiscan.py. Note it enumerates detector hits, not additions to make.

Reproducing a CI daemon defect locally

Build the binary with cargo build --workspace --all-features --bin oc-rsync. -p bin --all-features enables only the bin package's own features; daemon-seccomp is not a default feature and is not reachable from the root manifest, so it engages solely through workspace-wide feature unification - exactly what CI does. Every -p bin build measures a daemon with no seccomp layer at all, and the daemon says so in its own log:

seccomp BPF unavailable in this build     <- -p bin
seccomp BPF filter engaged                <- --workspace --all-features

Three separate investigations of this cell produced false passes on that difference before it was noticed.

Mechanism proof

On aarch64, removing libc::SYS_unlinkat from the worker allowlist reproduces the CI failure character-for-character: exit 23, multiplexed frame truncated, daemon log Invalid cross-device link (os error 18) (code 1) at streams.rs(420), outside: ["marker"], inside: ["a", "realdir"]. That is the same defect expressed through the syscall aarch64 does use, which is why it is a valid mechanism proof on a host that cannot reproduce the x86_64 form.

The swallow was two sites, not one

create_directories and create_directory_incremental each carried their own copy of:

.unwrap_or_else(|_| if dir_path.exists() { Existing } else { Missing })

Wrong twice over. exists() follows symlinks, so the entry whose removal had just been denied reported back as an existing directory and the transfer proceeded through a symlink the peer controls. And the errno was discarded, which is how a denied unlink surfaced three layers later as an opaque EXDEV from the confined walk.

Upstream does goto skipping_dir_contents (generator.c:1840-1843), and generator.c:1443-1467 states the rule for the whole family: a runtime denial is a real failure and is deliberately NOT retried unconfined. Both sites now report the failure into the same set as a denied mkdir, so it reaches io_error and the exit code. Fixing only the first would have left the incremental-recursion path walking through the surviving symlink.

Verification, and one claim that is inference

  • The new test denies the removal with a read-only parent - the portable stand-in for any refusal, since a confined-walk rejection and a syscall-filter denial reach the same arm. It skips under root (root ignores the directory write bit, so the cell would pass vacuously) and asserts the symlink still exists, so the fixture cannot silently stop denying.
  • Mutation-proven: restoring only the swallow fails that test on its own assertion; restoring the fix returns it green.
  • 18/18 across daemon_relative_implied_parent_confinement and every directory::creation test. The sibling escape cells still refuse: relative_implied_parents_must_not_be_built_outside_the_module, a_sole_creator_relative_parent_must_not_escape_the_module, a_confined_relative_push_still_delivers_the_whole_path.
  • fmt clean; clippy -p transfer --all-features --all-targets -D warnings clean.

⚠ Stated plainly: "the fix works on x86_64" is inference, not measurement. The change removes the EPERM by making the syscall unlinkat, which the allowlist carries on every architecture - but that has not been observed on a host where the filter is live. No seccomp layer exists on macOS or aarch64, so the local greens cannot show the CI cell flipping. The reasoning is sound and the mutation proved the mechanism through that exact syscall; CI is the instrument for the rest.

Known adjacent site, deliberately not in scope

fs::create_dir_all at creation.rs:325 issues mkdir 83 and is in the same gap on the same path. It is the next instance of this class and is left to its own change.

@github-actions github-actions Bot added the bug Something isn't working label Aug 28, 2026
@oferchen
oferchen force-pushed the fix/relative-implied-parent-preemption branch from 9261e8c to faa37b2 Compare August 28, 2026 18:39
ensure_relative_parents created every --relative implied parent up front
with an unconfined, path-based create_dir. Two consequences followed from
the one cause.

It ran BEFORE the file list's own directory pass, so the directories
already existed when that pass classified them: a real run reported
'.d..t......' for parents its own --dry-run reported as 'cd+++++++++',
and rsync 3.5.0 reports 'cd+++++++++' in both. Upstream's equivalent is a
fallback, not a pre-pass - generator.c:1718-1725 calls make_path() only
for a parent do_stat_at() still reports absent, which is after
gen_entry_mkdir() (generator.c:1873) has created and itemized every
directory the file list carries. The call now runs after the directory
pass in all three receiver drivers.

And it created through a plain path, so a symlinked component pointed a
daemon's implied parent outside the module root. Upstream's make_path()
builds every component with do_mkdir_at() (util1.c:238, util1.c:277),
i.e. the ownership walk plus mkdirat() (syscall.c:2066), never a bare
mkdir(2). The remaining fallback creations now go through
fast_io::mkdirat_via_sandbox_or_fallback.

Measured on a daemon push with an out-of-module symlink at the first
implied parent: before, 'outside/b' and 'outside/b/c' were created
outside the module and the client still exited 0; after, only the seeded
marker remains, matching rsync 3.5.0 on the same fixture.
@oferchen
oferchen force-pushed the fix/relative-implied-parent-preemption branch from faa37b2 to 50072db Compare September 1, 2026 06:06
Replacing a conflicting destination symlink with a real directory used a
path-based `fs::remove_file`. That unlinks an entry whose target the PEER
chose, on the receiver's destination path, re-resolving every component
under the peer's influence. It is now routed onto the shared confined op,
`unlink_via_sandbox_or_fallback`, at both call sites -
`create_directories` and `create_directory_incremental`.

upstream: generator.c:1829/1841 `delete_item(..., del_opts | DEL_FOR_DIR)`
-> delete.c:71-78 `del_unlink()` -> `do_unlink_atfd()` against a held dirfd,
else util1.c:545 `robust_unlink()` -> `do_unlink_at()`. Both arms are the
confined wrappers; upstream issues no plain `unlink()` on this path.

`sandbox` may be `None`. That is a supported arm, not a gap: the helper then
applies upstream's three-arm `do_unlink_at()` contract, which errors rather
than falling back to a plain syscall when the ownership walk refuses.

Second half: a refused removal is now REPORTED. Both sites recovered with
`.unwrap_or_else(|_| if dir_path.exists() { Existing } else { Missing })`,
and `exists()` FOLLOWS symlinks - so the entry whose removal had just been
denied reported back as an existing directory and the transfer walked
straight through it, with the errno discarded. Upstream does
`goto skipping_dir_contents` (generator.c:1840-1843), and
generator.c:1443-1467 states the rule for the family: a runtime denial is a
real failure and is deliberately NOT retried unconfined. The failure now
lands in the same failed-directory set as a denied mkdir, so it reaches
io_error and the exit code.

Also corrects the citation at creation.rs:95-97, which named
`syscall.c do_unlink()`. That is the wrong upstream function for this site
and is what pointed the previous reading at the plain entry point.

The new test denies the removal with a read-only parent - the portable
stand-in for any refusal - and asserts the failure is reported. Restoring
the swallow fails it; the --existing companion stays green.
@oferchen
oferchen merged commit 603d101 into master Sep 1, 2026
69 checks passed
@oferchen
oferchen deleted the fix/relative-implied-parent-preemption branch September 1, 2026 22:22
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