Skip to content

feat(daemon): apply PR_SET_NO_NEW_PRIVS + log active LSMs at startup - #5581

Merged
oferchen merged 2 commits into
masterfrom
feat/lsm-startup-hardening
Jun 11, 2026
Merged

oferchen merged 2 commits into
masterfrom
feat/lsm-startup-hardening

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Sets PR_SET_NO_NEW_PRIVS once at daemon main-entry via nix::sys::prctl::set_no_new_privs, so any later execve() (including pre/post-xfer-exec hooks) cannot regain privileges and Landlock can engage on kernels that gate it behind the no-new-privs bit.
  • Reads /sys/kernel/security/lsm and emits the active LSM list at info level so operators see a single audit line confirming which kernel-side defenses (Landlock, lockdown, Yama, AppArmor, etc.) cover the daemon. Missing securityfs degrades to a graceful skip.
  • Applies uniformly across all three daemon entry points (standalone TCP accept loop, inetd stdio, --server --daemon stdio); no-op on non-Linux targets.

Test plan

  • cargo nextest run -p daemon --all-features -E 'test(hardening)' covers the two new unit tests: a mocked-file LSM read that asserts the trimmed list reaches the log sink, and a missing-path probe that asserts graceful skip without panic.
  • Full CI matrix (fmt+clippy, nextest stable, Windows, macOS, Linux musl) exercises the cross-platform no-op stub on non-Linux and confirms the Linux-only nix process feature compiles.
  • Existing daemon integration tests (tests::support::run_daemon) confirm the daemon still starts successfully on Linux with the prctl call wired in.

oferchen added 2 commits June 11, 2026 06:12
The PR added a nix dependency with the process feature to the daemon
crate but did not regenerate Cargo.lock, causing all --locked CI cells
to fail with 'the lock file needs to be updated'.

Add nix to the daemon entry in Cargo.lock so --locked builds succeed.
@oferchen
oferchen force-pushed the feat/lsm-startup-hardening branch from e212192 to fedcd8f Compare June 11, 2026 03:13
@oferchen
oferchen merged commit e34bdd7 into master Jun 11, 2026
12 of 20 checks passed
oferchen added a commit that referenced this pull request Jun 11, 2026
Master HEAD does not compile on Linux: `delete_extraneous_files`
returns `io::Result<(DeleteStats, bool)>` but its callers in
`receiver/transfer/pipelined.rs:64` and
`receiver/transfer/pipelined_incremental.rs:100` destructure
`(ds, exceeded, io_bits)` (3-tuple). The mismatch is from the merge
of #5639/#5581 dropping the i32 io_bits slot that
c55f044 ("propagate ELOOP from sandboxed delete scan as
IOERR_GENERAL") and the UTS-16.b series introduced.

Restore the 3-tuple return type and replace the `first_err`
accumulator with an `io_err_bits` accumulator. A fail-loud sandbox
class (ELOOP / EOPNOTSUPP / ENOTDIR / EPERM) from any worker now
ORs IOERR_GENERAL into the third slot instead of converting to
`Err`, which is what the receiver-side filter_chain test
`reject_symlinked_subdir_via_implied_filter` already asserts and
what the UTS-16.b "non-zero exit instead of silent skip" intent
documented at `pipelined.rs:59-61` requires.

EDG-SANDBOX classification (`fail_loud_unlink_error`) is unchanged;
only the propagation channel from worker -> caller switches from
`Err` to the i32 bits, which keeps the exit code at 23
(RERR_PARTIAL) by way of `to_exit_code`.

The fix is the smallest patch that unbreaks master and matches the
caller / test expectations already merged. Catastrophic, non-worker
errors above the parallel scan still propagate via `?` and `Err`.
oferchen added a commit that referenced this pull request Jun 11, 2026
LSM-CAP at PR #5581 dropped every capability except CAP_CHOWN even
for modules configured with uid=0. A uid=0 worker is, by operator
intent, the root identity: the kernel grants root the file-system
bypass set (DAC_OVERRIDE, DAC_READ_SEARCH, FOWNER, FSETID) implicitly
so it can read, write, chmod and utime under directories owned by
unprivileged users. Stripping those 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)` returns EACCES at the
homedir component and the connection closes 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.

Add DAC_OVERRIDE, DAC_READ_SEARCH, FOWNER, and FSETID to the required
set whenever the module retains uid=0 (i.e. the worker is still root).
Unprivileged modules (uid != 0) keep the empty set: setuid drops these
implicitly so the explicit drop is redundant. 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.
@oferchen
oferchen deleted the feat/lsm-startup-hardening branch June 11, 2026 08:31
oferchen added a commit that referenced this pull request Jun 11, 2026
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.
oferchen added a commit that referenced this pull request Jun 11, 2026
Master HEAD does not compile on Linux: `delete_extraneous_files`
returns `io::Result<(DeleteStats, bool)>` but its callers in
`receiver/transfer/pipelined.rs:64` and
`receiver/transfer/pipelined_incremental.rs:100` destructure
`(ds, exceeded, io_bits)` (3-tuple). The mismatch is from the merge
of #5639/#5581 dropping the i32 io_bits slot that
c55f044 ("propagate ELOOP from sandboxed delete scan as
IOERR_GENERAL") and the UTS-16.b series introduced.

Restore the 3-tuple return type and replace the `first_err`
accumulator with an `io_err_bits` accumulator. A fail-loud sandbox
class (ELOOP / EOPNOTSUPP / ENOTDIR / EPERM) from any worker now
ORs IOERR_GENERAL into the third slot instead of converting to
`Err`, which is what the receiver-side filter_chain test
`reject_symlinked_subdir_via_implied_filter` already asserts and
what the UTS-16.b "non-zero exit instead of silent skip" intent
documented at `pipelined.rs:59-61` requires.

EDG-SANDBOX classification (`fail_loud_unlink_error`) is unchanged;
only the propagation channel from worker -> caller switches from
`Err` to the i32 bits, which keeps the exit code at 23
(RERR_PARTIAL) by way of `to_exit_code`.

The fix is the smallest patch that unbreaks master and matches the
caller / test expectations already merged. Catastrophic, non-worker
errors above the parallel scan still propagate via `?` and `Err`.
oferchen added a commit that referenced this pull request Jun 11, 2026
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.
oferchen added a commit that referenced this pull request Jun 11, 2026
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.
oferchen added a commit that referenced this pull request Jun 11, 2026
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.
oferchen added a commit that referenced this pull request Jun 11, 2026
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.
oferchen added a commit that referenced this pull request Jun 11, 2026
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.
oferchen added a commit that referenced this pull request Jun 11, 2026
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.
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
feat(daemon): apply PR_SET_NO_NEW_PRIVS + log active LSMs at startup
oferchen added a commit that referenced this pull request Aug 24, 2026
Master HEAD does not compile on Linux: `delete_extraneous_files`
returns `io::Result<(DeleteStats, bool)>` but its callers in
`receiver/transfer/pipelined.rs:64` and
`receiver/transfer/pipelined_incremental.rs:100` destructure
`(ds, exceeded, io_bits)` (3-tuple). The mismatch is from the merge
of #5639/#5581 dropping the i32 io_bits slot that
c55f044 ("propagate ELOOP from sandboxed delete scan as
IOERR_GENERAL") and the UTS-16.b series introduced.

Restore the 3-tuple return type and replace the `first_err`
accumulator with an `io_err_bits` accumulator. A fail-loud sandbox
class (ELOOP / EOPNOTSUPP / ENOTDIR / EPERM) from any worker now
ORs IOERR_GENERAL into the third slot instead of converting to
`Err`, which is what the receiver-side filter_chain test
`reject_symlinked_subdir_via_implied_filter` already asserts and
what the UTS-16.b "non-zero exit instead of silent skip" intent
documented at `pipelined.rs:59-61` requires.

EDG-SANDBOX classification (`fail_loud_unlink_error`) is unchanged;
only the propagation channel from worker -> caller switches from
`Err` to the i32 bits, which keeps the exit code at 23
(RERR_PARTIAL) by way of `to_exit_code`.

The fix is the smallest patch that unbreaks master and matches the
caller / test expectations already merged. Catastrophic, non-worker
errors above the parallel scan still propagate via `?` and `Err`.
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

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant