Skip to content

fix(metadata): force am_root=false under fake-super (#1926) - #3547

Merged
oferchen merged 1 commit into
masterfrom
fix/fake-super-am-root-gate-1926
May 2, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/fake-super-am-root-gate-1926

Conversation

@oferchen

@oferchen oferchen commented May 1, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #1926.

When the receiver has fake_super active (CLI --fake-super or daemon module fake super = yes), force am_root = false semantics in the privilege-decision branches that gate ownership and special-file creation, matching upstream rsync 3.4.1.

Upstream uses an am_root tri-state int:

  • 0 - regular user
  • 1 - real root
  • 2 - --super
  • -1 - --fake-super / daemon fake super = yes

A negative am_root is the sentinel that routes privileged operations (chown, mknod, mkfifo) through the user.rsync.%stat xattr placeholder path instead of attempting real syscalls. See options.c:89, clientserver.c:1102-1105, and syscall.c do_mknod() (the am_root < 0 branch substitutes a 0600 regular file).

Changes

  • Extract a single effective_am_root(super_mode, fake_super) -> bool helper in crates/engine/src/local_copy/options/metadata/accessors.rs. It returns false whenever fake_super is set, otherwise honours super_mode falling back to the effective UID check.
  • Rewire LocalCopyOptions::am_root() through the helper so every privilege-decision call site sees the demotion uniformly.
  • Update two tests in tests/execute_super.rs that previously asserted the un-demoted behavior; add upstream citations to the rewritten assertions.
  • Add 6 unit tests covering the full truth table at the helper level (the four required cases plus the two super_mode = None cases).

The helper is pub(super) so internal call sites can be grown later (special-file executors, daemon hand-off path) without re-deriving the rule.

Test plan

  • cargo fmt --all (clean).
  • cargo clippy -p engine --all-features --all-targets -- -D warnings (clean).
  • CI nextest matrix (run by branch protection).

Upstream references

  • target/interop/upstream-src/rsync-3.4.1/options.c:89 - am_root tri-state declaration.
  • target/interop/upstream-src/rsync-3.4.1/options.c:653 - --fake-super sets am_root = -1.
  • target/interop/upstream-src/rsync-3.4.1/clientserver.c:1102-1105 - daemon fake super = yes forces am_root = -1.
  • target/interop/upstream-src/rsync-3.4.1/syscall.c:90-174 - do_mknod() am_root < 0 placeholder substitution.

@github-actions github-actions Bot added the bug Something isn't working label May 1, 2026
Mirrors upstream rsync 3.4.1's am_root tri-state semantics: when
--fake-super (or daemon `fake super = yes`) is active, the receiver
must demote am_root to the negative sentinel that routes privileged
operations (chown, mknod, mkfifo) through the user.rsync.%stat
xattr placeholder branch instead of attempting real syscalls.

Extracts an `effective_am_root(super_mode, fake_super) -> bool`
helper covering the full truth table and rewires
`LocalCopyOptions::am_root()` through it. Updates the two
combined-flag tests that previously asserted the un-demoted
behavior, and adds dedicated truth-table tests at the helper.

upstream: options.c:89 - am_root tri-state, -1 is "fake-super"
upstream: clientserver.c:1102-1105 - daemon fake super = yes forces -1
upstream: syscall.c do_mknod() - am_root<0 substitutes 0600 placeholder

Refs #1926.
@oferchen
oferchen force-pushed the fix/fake-super-am-root-gate-1926 branch from d37e402 to 6e48d9b Compare May 2, 2026 01:28
@oferchen
oferchen marked this pull request as ready for review May 2, 2026 03:42
@oferchen
oferchen merged commit 886891d into master May 2, 2026
37 checks passed
@oferchen
oferchen deleted the fix/fake-super-am-root-gate-1926 branch May 2, 2026 03:50
oferchen added a commit that referenced this pull request May 5, 2026
Mirrors upstream rsync 3.4.1's am_root tri-state semantics: when
--fake-super (or daemon `fake super = yes`) is active, the receiver
must demote am_root to the negative sentinel that routes privileged
operations (chown, mknod, mkfifo) through the user.rsync.%stat
xattr placeholder branch instead of attempting real syscalls.

Extracts an `effective_am_root(super_mode, fake_super) -> bool`
helper covering the full truth table and rewires
`LocalCopyOptions::am_root()` through it. Updates the two
combined-flag tests that previously asserted the un-demoted
behavior, and adds dedicated truth-table tests at the helper.

upstream: options.c:89 - am_root tri-state, -1 is "fake-super"
upstream: clientserver.c:1102-1105 - daemon fake super = yes forces -1
upstream: syscall.c do_mknod() - am_root<0 substitutes 0600 placeholder

Refs #1926.
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