Skip to content

fix(engine): answer am_root from the process identity - #7574

Merged
oferchen merged 2 commits into
masterfrom
fix/local-copy-am-root-identity
Sep 1, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/local-copy-am-root-identity

Conversation

@oferchen

@oferchen oferchen commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Problem

crates/engine/src/local_copy/options/metadata/accessors.rs resolved the
local-copy am_root gate with rustix::process::geteuid().is_root(). Two
other consumers of the same question in the same crate already call
metadata::am_root():

  • crates/engine/src/local_copy/options/path_behavior.rs:450
    (may_attempt_node_creation)
  • crates/engine/src/local_copy/metadata_sync.rs:137

So the crate had two ways to answer one question, and they do not agree.

Why they do not agree

On Linux, rustix's default backend emits the bare syscall instruction instead
of calling the libc symbol. Compiled for aarch64-unknown-linux-gnu:

via_rustix:                    via_libc:
    mov  w8, #175                  b  geteuid
    svc  #0

fakeroot works by LD_PRELOAD-interposing the libc symbol, so it can see
b geteuid and cannot see svc #0. Under fakeroot the raw form reports the
real unprivileged uid while upstream rsync - which samples the libc
geteuid() (main.c:1764 our_uid = MY_UID(), rsync.h:1455) - believes it
is root. That silently flips the --super, device-creation and fake-super
placeholder gates in exactly the runs meant to validate them: the upstream
testsuite's fakeroot legs and packaging builds.

The same call is also blind to the permanent --copy-as privilege drop.
Upstream re-samples our_uid/am_root in become_copy_as_user();
metadata::am_root() reproduces that through the identity override installed
by metadata::copy_as::become_copy_as_user, a raw syscall does not.

Change

is_effective_root() delegates to metadata::am_root(). The #[cfg(unix)] /
#[cfg(not(unix))] pair goes away because metadata::am_root() is already
false on non-POSIX platforms, matching upstream's am_root = 0 there. No
behaviour change on a plain unprivileged or plain root run; the two now agree
under fakeroot and after --copy-as.

Test

am_root_follows_the_process_identity_not_the_raw_euid drives the identity
source in both directions, so it is non-vacuous whatever uid the test process
runs at. Reverting the one-line fix to rustix::process::geteuid().is_root()
turns it red and nothing else:

FAIL [0.018s] engine local_copy::options::metadata::tests::am_root_follows_the_process_identity_not_the_raw_euid
  panicked at crates/engine/src/local_copy/options/metadata/tests.rs:262:5:
  a process identity of uid 0 is upstream's am_root
Summary [0.091s] 45 tests run: 44 passed, 1 failed

With the fix in place: 324 tests run: 324 passed for
test(local_copy::options) or test(execute_super).

cargo fmt --all -- --check and
cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings
are clean. cargo check -p engine --all-features --tests also passes for
x86_64-pc-windows-gnu.

The local-copy privilege gate resolved `am_root` with
`rustix::process::geteuid()`, while the two other consumers of the same
question in this crate (`may_attempt_node_creation` and the metadata-sync
options) already call `metadata::am_root()`. Route the third through the
same helper so there is one answer.

The two differ in a way that matters. On Linux rustix compiles `geteuid`
to the bare syscall instruction rather than a call to the libc symbol
(`mov w8, #175; svc #0` on aarch64), so `fakeroot`'s LD_PRELOAD
interposition cannot see it and it reports the real unprivileged uid in
exactly the runs - the upstream testsuite's fakeroot legs, and packaging
builds - where upstream believes it is root. Upstream samples the libc
`geteuid()` (`main.c:1764` `our_uid = MY_UID()`, `rsync.h:1455`), which
fakeroot does intercept. It also re-samples it in `become_copy_as_user()`
after the permanent `--copy-as` drop; `metadata::am_root()` honours that
drop through the identity override, a raw syscall does not.

The new test drives the identity in both directions, so it stays
non-vacuous whether or not the test process runs as root.
@github-actions github-actions Bot added the bug Something isn't working label Sep 1, 2026
`our_uid = MY_UID()` resolves at main.c:313 and main.c:1844 in 3.5.0, not
1764. The process-identity site is the one in main(), corroborated by the
existing `main.c:1843 starttime = time(NULL)` citation one line above it;
313 is become_copy_as_user()'s re-sample after the --copy-as drop.
@oferchen
oferchen merged commit 781a196 into master Sep 1, 2026
69 checks passed
@oferchen
oferchen deleted the fix/local-copy-am-root-identity branch September 1, 2026 10:16
oferchen added a commit that referenced this pull request Sep 2, 2026
`## [Unreleased]` last covered the #7304-#7522 era. Measured against the 60
most recently merged pull requests, 44 were absent; of the most recent 45,
43 were absent. Nothing from #7574 onward was recorded at all.

Each entry is derived from what the pull request actually landed - the merge
commit and the body - not from its title. Three cases where those differ:

  * #7616 ships far more than the doc-alias correction its body describes:
    the `upstream_version` pin moves to 3.5.0 and `--version` starts naming
    `quic`, `sd-notify`, `vmsplice` and `send_zc`.
  * #7618 also adds the pull-request rustdoc-link job its body says was
    filed separately, which is what closes the master-only-gate recurrence.
  * #7602's squash carries the closed #7597 as its first commit, so the
    directory-obstacle half is recorded under #7602.

#7587 is deliberately not recorded. Its merge commit is empty: the change
had already landed as #7563, which the section already names.

Entries extend the existing Keep a Changelog groups and the bold
sub-groupings. Clusters that are one story carry one entry with several
references: the FERROR_XFER routing and its two-phase drain (#7576, #7581),
the connection-FSM close edge and the accept loop that outlives a session
error (#7579, #7590), the three detaching daemon suites (#7578, #7588,
#7592), the io_uring and SEND_ZC work (#7593, #7600, #7610), the citation
retargets (#7601, #7603, #7604), and the accept-loop pin flake (#7615,
#7620).

Only `## [Unreleased]` is touched; every released section, including the
3.4.4 statements that were correct when written, is byte-identical.
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