Skip to content

fix(fast_io): resolve an absolute operator rename endpoint by ownership - #7398

Merged
oferchen merged 1 commit into
masterfrom
fix/temp-dir-rename-owner-walk
Aug 20, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/temp-dir-rename-owner-walk

Conversation

@oferchen

@oferchen oferchen commented Aug 20, 2026 •

Copy link
Copy Markdown
Owner

What

confined_rename resolved an absolute endpoint outside the confinement root
with AT_FDCWD and the whole path. That is the temp file staged by an absolute
--temp-dir: its creation is confined, but the commit re-resolves its path,
so a parent component flipped to a foreign-owned symlink in between redirects
the rename source and lands attacker content in the destination.

That is the escape upstream's temp-dir-symlink-injection test demonstrates. On
master it fails intermittently on the root leg - it loops for a race budget, so
it passes only when the flipper misses the window.

Upstream rule

do_rename_at() (syscall.c:1866-1990) resolves each side independently,
by three arms, not two:

endpoint resolver upstream
relative with a slash secure_relative_open() - confined beneath the tree :1945
absolute owner_walk_parent() - the ownership walk :1926
slashless AT_FDCWD + the name :1949

The split exists because location cannot be the trust signal for an operator
path - it may legitimately point outside the tree - so authority (ownership)
is used instead: follow a symlink owned by uid 0 or our euid, refuse any other.

oc had the first and third arms and folded the second into the third.
crates/fast_io/src/owner_walk.rs already implements the walk; it was wired
only into the backup path (engine/src/local_copy/overrides.rs).

Keying oc's first arm on beneath the root rather than on relative is the
equivalent test: upstream has already chdir'd the receiver into the
destination, so its transfer paths are relative where oc's are
absolute-but-beneath-root.

The trap this deliberately avoids

The ownership rule is more permissive than the confined walk. Applying it to
both sides - or to any endpoint beneath the root - would weaken the
destination while fixing the source. Upstream does not set
operator_path_resolve for this call, and neither does this change: the arm is
selected by provenance, and the destination keeps the confined walk.

Design

ConfinedEndpoint gains an OwnerWalked arm, and the (dirfd, name) mapping
moves onto the type as resolved(). There were four copies of that match,
and the compiler found a fourth consumer I had not accounted for
(confined_clone_file) precisely because the enum is exhaustive. Those copies
are how the two commit strategies drifted apart once before - the O_TMPFILE
linkat path skipped confinement while the named-temp rename enforced it - so a
new arm must now be impossible to handle in only some of them.

Tests

  • endpoint_provenance::* - three cases pinning which resolver each provenance
    selects. The absolute-outside-root case is the fix.
  • an_out_of_tree_source_behind_an_owned_symlink_still_commits - the direction a
    blanket refusal would break: an operator path may legitimately live behind a
    symlink they own, and the walk must follow it.

RED/GREEN measured. Removing only the absolute arm, leaving everything else:

absolute-arm test owned-symlink follow 3 destination-confinement tests total
with the arm pass pass pass 7 passed
without FAIL pass pass 6 passed, 1 failed

Exactly one test flips, and it is the discriminator.

The cross-uid refusal is not duplicated here. Planting a foreign-owned
component needs a second uid, so an unprivileged assertion would pass
vacuously; the refusal is proven by the root leg of the upstream 3.5.0 suite.
This is the same division crates/fast_io/tests/owner_walk.rs already documents
for the backup path.

Known gap, pre-existing, not introduced

Upstream gates the ownership walk on symlink_optout_allowed()
(--insecure-links / the insecure links module directive). oc has that
predicate - fast_io::confinement::Activation, truth-tabled - with zero
production constructors
, so no site consults it. The sibling operator-path
call (backup_rename -> operator_link/operator_rename) applies the walk
unconditionally on Unix for the same reason. This change follows that
precedent rather than inventing a second policy; wiring the opt-out belongs to
both sites at once and is tracked separately.

Verification

  • cargo fmt --all -- --check - clean
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings - exit 0, zero warnings
  • cargo nextest run -p fast_io --all-features - 746 passed
  • cargo nextest run -p engine --all-features - 5008 passed

Full-workspace and cross-platform coverage is left to the required CI contexts.

Behavioural proof, with a negative control

The cross-uid refusal cannot be observed unprivileged, so it was measured
directly: upstream 3.5.0's own temp-dir-symlink-injection test, run as root
on aarch64 Linux against two --release binaries that differ only by this
commit. Same host, same harness, same built helper programs, same loop.

binary runs failures
parent commit 6c88fca (pre-fix) 5 2
this branch 24280b3 20 0

The control's failures carry the escape verbatim:

absolute --temp-dir rename injection: attacker out-of-tree content was renamed
into the destination (f23) -- the temp->final rename followed a flipped
foreign-owned temp-dir parent symlink.

The test loops for a race budget, so a single pass proves nothing - which is
why the control matters. At the control's ~40% per-run failure rate, 20
consecutive passes would occur by chance with probability ~4e-5.

That budget is also why this test is worth closing rather than baselining: a
fail row in the expect manifest would make a required CI context a coin flip,
and a pass row would have waived a live escape.

confined_rename left an endpoint outside the confinement root to ambient
AT_FDCWD resolution. That is the temp file staged by an absolute --temp-dir:
its creation is confined, but the commit re-resolves its path, so a parent
component flipped to a foreign-owned symlink in between redirects the rename
source and lands attacker content in the destination.

Upstream's do_rename_at() resolves each side by three arms, not two: a
relative side beneath the tree via secure_relative_open (syscall.c:1945), an
absolute operator side via the ownership walk (:1926), and a slashless name
via AT_FDCWD (:1949). oc had the first and third and folded the second into
the third; owner_walk.rs already implemented the walk but was wired only into
the backup path.

The ownership rule is more permissive than the confined walk, so it is
selected by provenance only - the destination keeps the confined walk, which
is why upstream does not set operator_path_resolve for this call.

The (dirfd, name) mapping moves onto ConfinedEndpoint as resolved(). Four
copies of that match existed, and the exhaustive enum surfaced a consumer the
change had not accounted for; those copies are how the O_TMPFILE linkat commit
and the named-temp rename drifted apart once before.
@github-actions github-actions Bot added the bug Something isn't working label Aug 20, 2026
@oferchen
oferchen merged commit 3759c95 into master Aug 20, 2026
71 checks passed
@oferchen
oferchen deleted the fix/temp-dir-rename-owner-walk branch August 20, 2026 09:43
oferchen added a commit that referenced this pull request Aug 24, 2026
…ip (#7398)

confined_rename left an endpoint outside the confinement root to ambient
AT_FDCWD resolution. That is the temp file staged by an absolute --temp-dir:
its creation is confined, but the commit re-resolves its path, so a parent
component flipped to a foreign-owned symlink in between redirects the rename
source and lands attacker content in the destination.

Upstream's do_rename_at() resolves each side by three arms, not two: a
relative side beneath the tree via secure_relative_open (syscall.c:1945), an
absolute operator side via the ownership walk (:1926), and a slashless name
via AT_FDCWD (:1949). oc had the first and third and folded the second into
the third; owner_walk.rs already implemented the walk but was wired only into
the backup path.

The ownership rule is more permissive than the confined walk, so it is
selected by provenance only - the destination keeps the confined walk, which
is why upstream does not set operator_path_resolve for this call.

The (dirfd, name) mapping moves onto ConfinedEndpoint as resolved(). Four
copies of that match existed, and the exhaustive enum surfaced a consumer the
change had not accounted for; those copies are how the O_TMPFILE linkat commit
and the named-temp rename drifted apart once before.
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