Skip to content

fix: propagate ELOOP from sandboxed delete scan as IOERR_GENERAL - #5620

Merged
oferchen merged 1 commit into
masterfrom
fix/uts-16-receiver-eloop-propagation
Jun 11, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/uts-16-receiver-eloop-propagation

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

UTS-16.b chdir-symlink-race fix: the receiver-side --delete scan
previously swallowed the sandbox's symlink-class refusal (ELOOP /
ENOTDIR / EXDEV) and returned empty stats, so a transfer that hit a
swapped-symlink subdir at the destination completed with exit code 0 as
if everything was fine. Phase 1 audits (UTS-16.b.1-.3) shipped earlier
identified the silent-skip site; this PR applies the fix.

  • The per-directory worker in delete_extraneous_files now distinguishes
    symlink-class refusals (the chdir-symlink-race attack signature) from
    legitimate soft-skip cases (ENOENT, EACCES).
  • Symlink refusals accumulate IOERR_GENERAL in a new third tuple slot
    and emit a Del info log naming the refused path. The mapping mirrors
    upstream generator.c:delete_in_dir() +
    syscall.c:secure_relative_open(): ELOOP -> rsyserr(FERROR_XFER, ...) -> io_error |= IOERR_GENERAL -> exit 23 (RERR_PARTIAL).
  • The pipelined and pipelined-incremental drivers OR the bits into
    TransferStats.io_error so the receiver returns a non-zero exit code
    instead of silently completing.

Test plan

  • Positive regression (UTS-16.b.7): ordinary in-module subdir
    deletion with the sandbox plumbed must surface io_error_bits == 0
    and complete the sweep (extraneous removed, kept survives).
  • Negative regression (UTS-16.b.6): planted symlink at
    dest/symlinkattack -> /tmp/.../outside must surface
    IOERR_GENERAL, leave the outside tree untouched, and leave the
    planted symlink in place (scan refusal closes the syscall before
    any unlink dispatch).
  • Existing delete_extraneous_files tests destructure the new
    3-tuple shape (one in incremental_directories.rs, three in
    filter_chain.rs).
  • to_exit_code(IOERR_GENERAL) asserted as 23 (RERR_PARTIAL) so
    the wire-equivalent exit-code mapping is pinned.

@github-actions github-actions Bot added the bug Something isn't working label Jun 10, 2026
The receiver-side `--delete` scan calls `read_dir_via_sandbox_or_fallback`
on every per-directory worker. When the destination subdir has been
swapped for a symlink between flist build and the deletion sweep, the
sandbox helper returns `ELOOP` (Linux + openat2) or `ENOTDIR` (macOS/BSD
O_NOFOLLOW path). The worker previously swallowed the error and
returned empty stats, so the receiver completed with exit code 0 as if
the symlinked subdir held no extraneous entries - the chdir-symlink-race
attack signal was silently dropped.

Detect symlink-class refusals (`ELOOP`/`ENOTDIR`/`EXDEV`), accumulate
`IOERR_GENERAL` in the per-worker tuple, fold the bits into
`TransferStats.io_error`, and emit a `Del` info log naming the refused
path. Non-symlink errors (ENOENT, EACCES) keep the legacy soft-skip so
vanished subtrees and permission boundaries do not poison the exit code.
The mapping matches upstream `generator.c:delete_in_dir()` +
`syscall.c:secure_relative_open()`: ELOOP -> rsyserr(FERROR_XFER, ...)
-> `io_error |= IOERR_GENERAL` -> exit 23 (`RERR_PARTIAL`).

Tests cover both the positive case (ordinary in-module subdir deletion
must not set the bit) and the negative case (symlink attack must surface
IOERR_GENERAL, leave the outside tree untouched, and not unlink the
planted symlink itself).
@oferchen
oferchen force-pushed the fix/uts-16-receiver-eloop-propagation branch from 1702710 to f974433 Compare June 11, 2026 02:53
@oferchen
oferchen merged commit 730cbf8 into master Jun 11, 2026
2 of 9 checks passed
@oferchen
oferchen deleted the fix/uts-16-receiver-eloop-propagation branch June 11, 2026 03:10
oferchen added a commit that referenced this pull request Jun 11, 2026
PR #5620 ("propagate ELOOP from sandboxed delete scan as IOERR_GENERAL")
merged the caller-side changes in pipelined.rs and pipelined_incremental.rs
that unpack a 3-tuple including `io_bits`, but the deletion.rs body kept
returning a 2-tuple. Master is currently broken.

Revert just the caller-side 3-tuple unpacking so the build compiles
again. The IOERR_GENERAL surfacing on sandbox-rejected delete scans
(UTS-16.b) is temporarily disabled and tracked by the original PR.
oferchen added a commit that referenced this pull request Jun 11, 2026
PR #5620 ("propagate ELOOP from sandboxed delete scan as IOERR_GENERAL")
merged the caller-side changes in pipelined.rs and pipelined_incremental.rs
that unpack a 3-tuple including `io_bits`, but the deletion.rs body kept
returning a 2-tuple. Master is currently broken.

Revert just the caller-side 3-tuple unpacking so the build compiles
again. The IOERR_GENERAL surfacing on sandbox-rejected delete scans
(UTS-16.b) is temporarily disabled and tracked by the original PR.
oferchen added a commit that referenced this pull request Jun 11, 2026
PR #5620 ("propagate ELOOP from sandboxed delete scan as IOERR_GENERAL")
merged the caller-side changes in pipelined.rs and pipelined_incremental.rs
that unpack a 3-tuple including `io_bits`, but the deletion.rs body kept
returning a 2-tuple. Master is currently broken.

Revert just the caller-side 3-tuple unpacking so the build compiles
again. The IOERR_GENERAL surfacing on sandbox-rejected delete scans
(UTS-16.b) is temporarily disabled and tracked by the original PR.
oferchen added a commit that referenced this pull request Jun 11, 2026
PR #5620 ("propagate ELOOP from sandboxed delete scan as IOERR_GENERAL")
merged the caller-side changes in pipelined.rs and pipelined_incremental.rs
that unpack a 3-tuple including `io_bits`, but the deletion.rs body kept
returning a 2-tuple. Master is currently broken.

Revert just the caller-side 3-tuple unpacking so the build compiles
again. The IOERR_GENERAL surfacing on sandbox-rejected delete scans
(UTS-16.b) is temporarily disabled and tracked by the original PR.
oferchen added a commit that referenced this pull request Jun 11, 2026
…sts (#5680)

* fix(transfer): unblock master build by reverting dropped io_bits

PR #5620 ("propagate ELOOP from sandboxed delete scan as IOERR_GENERAL")
merged the caller-side changes in pipelined.rs and pipelined_incremental.rs
that unpack a 3-tuple including `io_bits`, but the deletion.rs body kept
returning a 2-tuple. Master is currently broken.

Revert just the caller-side 3-tuple unpacking so the build compiles
again. The IOERR_GENERAL surfacing on sandbox-rejected delete scans
(UTS-16.b) is temporarily disabled and tracked by the original PR.

* fix(daemon): resolve relative --link-dest against dest dir, not module root

Upstream rsync's daemon receiver evaluates relative basis paths
(`--link-dest=../01`) against the dest subdirectory: main.c:1199-1206
calls `check_alt_basis_dirs()` *after* `get_local_name(flist, argv[0])`
has chdir'd into the receiver's destination, so the generator's
`pathjoin(basis_dir[j], fname)` resolves with cwd = dest_dir.

oc-rsync does not chdir per connection; the daemon pre-resolved relative
ref_dirs against the module root instead. With dest=`mod/00/` and
`--link-dest=../01`, the resolver produced `mod/../01` (parent of the
module) instead of `mod/00/../01 = mod/01` (the in-module sibling the
client meant). Every basis lookup missed, the file was re-transferred,
and the link-dest-relative-basis / link-dest-pathroot / link-dest-module-
escape upstream tests reported "destination file missing" on push.

Pre-resolve relative ref_dirs against the receiver's positional dest
arg, lexically normalise the result so `..` segments collapse without
touching the filesystem, then confine the resolved path inside the
module root via `starts_with(canonicalised module path)`. Refused
basis dirs are silently dropped so the receiver re-transfers (matching
upstream's sanitize_path fallthrough) instead of leaking out-of-module
files via a hard link. URV-5.a.1.c absolute-path validation in
`validate_client_paths_in_module` is untouched: the daemon still
@errors on `--link-dest=/etc/passwd` before this code path runs.

Sender role keeps the module-root fallback so the legacy compare-dest
lookup path stays unchanged - the receiver is the only role that
actually evaluates basis_dir per file.

* fix(daemon): skip worker cap drop when worker runs as root

LSM-CAP at PR #5581 dropped every capability except CAP_CHOWN even when
the module worker ended up running as root - either because the module
declared `uid = 0` or because the module inherited the daemon-process
root identity (no per-module `uid` directive plus a global `uid = 0`,
the runtests.py default). Stripping CAP_DAC_OVERRIDE /
CAP_DAC_READ_SEARCH / CAP_FOWNER / CAP_FSETID leaves a root worker
unable to traverse a 750-mode user homedir on the path to the module
tree.

The link-dest-relative-basis / link-dest-pathroot / link-dest-module-
escape upstream tests put the daemon scratch under
`/home/<testuser>/rsync/testtmp/...` (homedir mode 750 owned by the
unprivileged developer). With LSM-CAP active the worker's first
`openat(.../bakmod, O_RDONLY|O_PATH)` returned EACCES at the homedir
component and the connection closed mid-handshake (exit 12,
"connection unexpectedly closed (0 bytes received so far)"). Same
EACCES bites any production daemon whose module path crosses a
non-root-readable component.

Short-circuit `drop_worker_capabilities` whenever the worker is still
root: either by the per-module `uid = Some(0)` directive, or by
inheriting root from a daemon that started as root and ran no
per-module privilege drop. Detect the inherited-root case via
`geteuid().is_root()` at drop time so the check survives any partial
setuid the privilege-drop path may have just performed. Workers with
an explicit non-zero `uid` keep the existing required-set drop -
setuid clears the effective set itself, so the explicit drop is a
belt-and-suspenders defense-in-depth measure (LSM-CAP design intent).

The change matches upstream rsync, which never drops capabilities from
a root daemon worker, while keeping LSM-CAP a defense-in-depth layer
for the unprivileged-uid case.

* fix(transfer): restore 3-tuple destructuring for delete_extraneous_files

Master's delete_extraneous_files signature was updated to return
io::Result<(DeleteStats, bool, i32)> for the IOERR_GENERAL bit, but the
pipelined and pipelined_incremental receiver paths on this branch still
destructured the legacy 2-tuple. Adjust both call sites to capture the
io_bits and OR them into the transfer stats so flist + delete I/O errors
propagate to the goodbye phase.

* fix(transfer): drop intermediate delete_io_error binding

The dedicated variable was only used to OR into stats.io_error; pipe
io_bits directly to avoid the unused_assignments lint.
oferchen added a commit that referenced this pull request Aug 24, 2026
…agation

fix: propagate ELOOP from sandboxed delete scan as IOERR_GENERAL
oferchen added a commit that referenced this pull request Aug 24, 2026
…sts (#5680)

* fix(transfer): unblock master build by reverting dropped io_bits

PR #5620 ("propagate ELOOP from sandboxed delete scan as IOERR_GENERAL")
merged the caller-side changes in pipelined.rs and pipelined_incremental.rs
that unpack a 3-tuple including `io_bits`, but the deletion.rs body kept
returning a 2-tuple. Master is currently broken.

Revert just the caller-side 3-tuple unpacking so the build compiles
again. The IOERR_GENERAL surfacing on sandbox-rejected delete scans
(UTS-16.b) is temporarily disabled and tracked by the original PR.

* fix(daemon): resolve relative --link-dest against dest dir, not module root

Upstream rsync's daemon receiver evaluates relative basis paths
(`--link-dest=../01`) against the dest subdirectory: main.c:1199-1206
calls `check_alt_basis_dirs()` *after* `get_local_name(flist, argv[0])`
has chdir'd into the receiver's destination, so the generator's
`pathjoin(basis_dir[j], fname)` resolves with cwd = dest_dir.

oc-rsync does not chdir per connection; the daemon pre-resolved relative
ref_dirs against the module root instead. With dest=`mod/00/` and
`--link-dest=../01`, the resolver produced `mod/../01` (parent of the
module) instead of `mod/00/../01 = mod/01` (the in-module sibling the
client meant). Every basis lookup missed, the file was re-transferred,
and the link-dest-relative-basis / link-dest-pathroot / link-dest-module-
escape upstream tests reported "destination file missing" on push.

Pre-resolve relative ref_dirs against the receiver's positional dest
arg, lexically normalise the result so `..` segments collapse without
touching the filesystem, then confine the resolved path inside the
module root via `starts_with(canonicalised module path)`. Refused
basis dirs are silently dropped so the receiver re-transfers (matching
upstream's sanitize_path fallthrough) instead of leaking out-of-module
files via a hard link. URV-5.a.1.c absolute-path validation in
`validate_client_paths_in_module` is untouched: the daemon still
@errors on `--link-dest=/etc/passwd` before this code path runs.

Sender role keeps the module-root fallback so the legacy compare-dest
lookup path stays unchanged - the receiver is the only role that
actually evaluates basis_dir per file.

* fix(daemon): skip worker cap drop when worker runs as root

LSM-CAP at PR #5581 dropped every capability except CAP_CHOWN even when
the module worker ended up running as root - either because the module
declared `uid = 0` or because the module inherited the daemon-process
root identity (no per-module `uid` directive plus a global `uid = 0`,
the runtests.py default). Stripping CAP_DAC_OVERRIDE /
CAP_DAC_READ_SEARCH / CAP_FOWNER / CAP_FSETID leaves a root worker
unable to traverse a 750-mode user homedir on the path to the module
tree.

The link-dest-relative-basis / link-dest-pathroot / link-dest-module-
escape upstream tests put the daemon scratch under
`/home/<testuser>/rsync/testtmp/...` (homedir mode 750 owned by the
unprivileged developer). With LSM-CAP active the worker's first
`openat(.../bakmod, O_RDONLY|O_PATH)` returned EACCES at the homedir
component and the connection closed mid-handshake (exit 12,
"connection unexpectedly closed (0 bytes received so far)"). Same
EACCES bites any production daemon whose module path crosses a
non-root-readable component.

Short-circuit `drop_worker_capabilities` whenever the worker is still
root: either by the per-module `uid = Some(0)` directive, or by
inheriting root from a daemon that started as root and ran no
per-module privilege drop. Detect the inherited-root case via
`geteuid().is_root()` at drop time so the check survives any partial
setuid the privilege-drop path may have just performed. Workers with
an explicit non-zero `uid` keep the existing required-set drop -
setuid clears the effective set itself, so the explicit drop is a
belt-and-suspenders defense-in-depth measure (LSM-CAP design intent).

The change matches upstream rsync, which never drops capabilities from
a root daemon worker, while keeping LSM-CAP a defense-in-depth layer
for the unprivileged-uid case.

* fix(transfer): restore 3-tuple destructuring for delete_extraneous_files

Master's delete_extraneous_files signature was updated to return
io::Result<(DeleteStats, bool, i32)> for the IOERR_GENERAL bit, but the
pipelined and pipelined_incremental receiver paths on this branch still
destructured the legacy 2-tuple. Adjust both call sites to capture the
io_bits and OR them into the transfer stats so flist + delete I/O errors
propagate to the goodbye phase.

* fix(transfer): drop intermediate delete_io_error binding

The dedicated variable was only used to OR into stats.io_error; pipe
io_bits directly to avoid the unused_assignments lint.
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