Repository navigation
fix(cli): resolve --log-file through the ownership walk - #7404
Merged
Merged
Conversation
`--log-file` was opened by handing the operator's path straight to the kernel, so both the leaf and every parent component were followed. A privileged rsync run with `--log-file` under an attacker-influenceable directory appends its log wherever a planted symlink points. Adds the missing sibling to `operator_rename`/`operator_link`, which already sit on the ownership walk: operator_open_read(path) - --password-file, --*-from, config operator_open_append(path, mode) - --log-file Both resolve the parent with `owner_trusted_parent` (follow a symlink owned by uid 0 or our euid, refuse any other-uid one) and open the leaf `O_NOFOLLOW`. Those are deliberately different policies and both are load-bearing: the leaf guard stops `--log-file=$plant`, and only the parent walk stops `--log-file=$plant/rsync.log`, where the leaf does not exist yet so there is nothing for O_NOFOLLOW to reject. upstream: syscall.c:469 opens the last component `flags | O_NOFOLLOW` while every parent goes through the ownership test at syscall.c:406; syscall.c:537 `open_no_attacker_symlinks()` is the entry point for the opens that are not confined beneath a root, `--log-file` among them (syscall.c:232). Only --log-file is routed here. The remaining operator-path options (--password-file, --exclude-from/--include-from/--files-from, --write-batch, --early-input, daemon config/secrets) still open by path and are follow-ups.
…OLLOW The ownership walk added in 543c529 refused EVERY symlink at the named path, whoever owned it. That broke the operator's own `/var/log -> /data/log` and reddened both required testsuite contexts: operator-path-log-file: expected pass, got fail "--log-file: SAME-UID abs leaf safe: the operator's OWN (euid-owned) symlink was refused." ⚠ MY OWN UPSTREAM READING WAS WRONG, and the test I wrote encoded it. I took syscall.c:469 - `openat(dfd, comp, flags | O_NOFOLLOW, mode)` - as the leaf policy. It is not. That line sits inside the `/* Non-symlink. */ if (is_last)` arm at :460 and is reached only once the walk has already established the component is NOT a symlink; the `S_ISLNK` arm at :402 runs first and applies to the leaf exactly as it does to a parent. `O_NOFOLLOW` there is a race backstop on the statat->openat window, not a refusal rule. Upstream states the contract in its own words at syscall.c:270-272: "refusing to traverse any symlink (parent or leaf) not owned by uid 0 or our euid. A trusted-owned symlink (e.g. root's /var/log -> /data/log) is still followed; an untrusted one fails ELOOP." The mechanism was read correctly; its applicability was assumed. The fix is upstream's own decomposition rather than a special case. `ona_open` is ONE walk; upstream reaches it two ways - `open_no_attacker_symlinks()` hands it the full path, `owner_walk_parent()` hands it the parent directory and keeps the basename. oc now does the same: `owner_walk_open` is the single walk, `operator_open_with` calls it on the path, `owner_trusted_parent` calls it on the parent. That deletes the duplicated loop and the separate leaf open, and the leaf stops being a special case because upstream never made it one. Rename/link keep parent-only resolution on purpose: they target the NAME, so replacing a symlink sitting there is the correct outcome. Also picked up from the same read: an interior component that is not a directory is now ENOTDIR (syscall.c:479), and the O_CREAT-leaf arm (syscall.c:381-396) is spelled out - the `--log-file=/tmp/dir/rsync.log` shape where the leaf does not exist yet, which a leaf-only O_NOFOLLOW cannot defend at all. TESTS. `refuses_a_symlink_at_the_leaf_even_when_self_owned` asserted the bug and is replaced by `follows_a_self_owned_symlink_at_the_leaf`. RED PROVEN by restoring the old leaf refusal: that one test fails, 4 others stay green. Its non-vacuity companion `refuses_an_owner_that_is_neither_root_nor_the_euid` pins the security half - without it, a walk that followed EVERYTHING would also pass. It exercises the predicate directly because the behavioural cell needs a symlink owned by another uid, which only root can plant; upstream skips its own cross-uid cell for that reason, and a runtime-skipped test reports a pass having checked nothing. ⚠ The design is corroborated independently of my C reading: log-file-symlink_test.py:24-28 states the same rule as its defense model - "for each component that IS a symlink, fstat() the symlink itself and allow only if st_uid is 0 or geteuid(). Symlinks owned by an untrusted uid -> ELOOP." MANIFEST. The root leg reported `log-file-symlink: expected fail, got pass`. That test lchowns its plant to an untrusted uid, so the fix keeps refusing it - the xpass is a genuine improvement and the row is re-baselined to `pass`. `operator-path-log-file` root stays `fail` DELIBERATELY: its matrix also covers --insecure-links cells, and --log-file does not honour that opt-out yet (the test says so in its own header). Under root the insecure cross-uid cell still fails, so the row is still correct. Only the nonroot leg should return to pass. VERIFIED: fast_io 751/751; workspace clippy --all-targets --all-features -D warnings exit 0; fmt clean.
`Linux musl (stable)` failed on this PR with one test:
reverse_lookup_off_renders_undetermined_everywhere
no PROBE line in daemon log:
... rsync allowed access on module m from UNDETERMINED (127.0.0.1)
... module 'm' from UNDETERMINED (127.0.0.1): protocol 32, role: Generator
... building file list
Everything the daemon writes is present EXCEPT the last line - the per-transfer
`log format` line the assertions consume. `Fixture::run` killed the daemon the
instant the CLIENT process exited:
let status = Command::new(client_bin)...status();
let _ = daemon.kill();
but that line is emitted by the DAEMON after the client disconnects, so nothing
ordered the write before the kill. `spawn_daemon` already condition-polls for
the listener instead of sleeping; the teardown just never got the same
treatment. Now it waits for the line every caller asserts on, bounded at 10s,
returning on timeout so a genuine absence still surfaces as `probe_line`'s
panic rather than a hang.
Waiting is unconditionally correct here: the shared config always sets
`log format = PROBE_FORMAT`, and all three callers of `run()` immediately call
`probe_line()`, so the line's absence is always a race and never an outcome.
⚠ NOT CAUSED BY THIS PR, and verified rather than assumed: `operator_open_append`
has exactly ONE call site in the tree (crates/cli/.../workflow/run.rs:1221, the
client's `--log-file`). The daemon's `log file` directive does not go through
it, so the ownership-walk change cannot affect when the daemon writes. The
daemon log being written at all is the second half of that argument - a broken
log open would have produced no log, not a log missing its final line.
⚠ THE FIX IS UNPROVEN BY REPRODUCTION, deliberately stated: I could not
reproduce the race on macOS - 25/25 runs passed with the wait REMOVED. The
failure was on musl under CI scheduling. So this closes the unsynchronised
window by construction and matches the observed signature exactly, but I have
no red-then-green demonstration and am not claiming one. It cannot regress
anything: it only adds a bounded wait for a line the callers already require.
VERIFIED: 3/3 in 1.5s, so the wait returns promptly rather than riding the
timeout; fmt clean.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
* fix(cli): resolve --log-file through the ownership walk `--log-file` was opened by handing the operator's path straight to the kernel, so both the leaf and every parent component were followed. A privileged rsync run with `--log-file` under an attacker-influenceable directory appends its log wherever a planted symlink points. Adds the missing sibling to `operator_rename`/`operator_link`, which already sit on the ownership walk: operator_open_read(path) - --password-file, --*-from, config operator_open_append(path, mode) - --log-file Both resolve the parent with `owner_trusted_parent` (follow a symlink owned by uid 0 or our euid, refuse any other-uid one) and open the leaf `O_NOFOLLOW`. Those are deliberately different policies and both are load-bearing: the leaf guard stops `--log-file=$plant`, and only the parent walk stops `--log-file=$plant/rsync.log`, where the leaf does not exist yet so there is nothing for O_NOFOLLOW to reject. upstream: syscall.c:469 opens the last component `flags | O_NOFOLLOW` while every parent goes through the ownership test at syscall.c:406; syscall.c:537 `open_no_attacker_symlinks()` is the entry point for the opens that are not confined beneath a root, `--log-file` among them (syscall.c:232). Only --log-file is routed here. The remaining operator-path options (--password-file, --exclude-from/--include-from/--files-from, --write-batch, --early-input, daemon config/secrets) still open by path and are follow-ups. * fix(fast_io): apply the ownership rule to the leaf, not blanket O_NOFOLLOW The ownership walk added in 543c529 refused EVERY symlink at the named path, whoever owned it. That broke the operator's own `/var/log -> /data/log` and reddened both required testsuite contexts: operator-path-log-file: expected pass, got fail "--log-file: SAME-UID abs leaf safe: the operator's OWN (euid-owned) symlink was refused." ⚠ MY OWN UPSTREAM READING WAS WRONG, and the test I wrote encoded it. I took syscall.c:469 - `openat(dfd, comp, flags | O_NOFOLLOW, mode)` - as the leaf policy. It is not. That line sits inside the `/* Non-symlink. */ if (is_last)` arm at :460 and is reached only once the walk has already established the component is NOT a symlink; the `S_ISLNK` arm at :402 runs first and applies to the leaf exactly as it does to a parent. `O_NOFOLLOW` there is a race backstop on the statat->openat window, not a refusal rule. Upstream states the contract in its own words at syscall.c:270-272: "refusing to traverse any symlink (parent or leaf) not owned by uid 0 or our euid. A trusted-owned symlink (e.g. root's /var/log -> /data/log) is still followed; an untrusted one fails ELOOP." The mechanism was read correctly; its applicability was assumed. The fix is upstream's own decomposition rather than a special case. `ona_open` is ONE walk; upstream reaches it two ways - `open_no_attacker_symlinks()` hands it the full path, `owner_walk_parent()` hands it the parent directory and keeps the basename. oc now does the same: `owner_walk_open` is the single walk, `operator_open_with` calls it on the path, `owner_trusted_parent` calls it on the parent. That deletes the duplicated loop and the separate leaf open, and the leaf stops being a special case because upstream never made it one. Rename/link keep parent-only resolution on purpose: they target the NAME, so replacing a symlink sitting there is the correct outcome. Also picked up from the same read: an interior component that is not a directory is now ENOTDIR (syscall.c:479), and the O_CREAT-leaf arm (syscall.c:381-396) is spelled out - the `--log-file=/tmp/dir/rsync.log` shape where the leaf does not exist yet, which a leaf-only O_NOFOLLOW cannot defend at all. TESTS. `refuses_a_symlink_at_the_leaf_even_when_self_owned` asserted the bug and is replaced by `follows_a_self_owned_symlink_at_the_leaf`. RED PROVEN by restoring the old leaf refusal: that one test fails, 4 others stay green. Its non-vacuity companion `refuses_an_owner_that_is_neither_root_nor_the_euid` pins the security half - without it, a walk that followed EVERYTHING would also pass. It exercises the predicate directly because the behavioural cell needs a symlink owned by another uid, which only root can plant; upstream skips its own cross-uid cell for that reason, and a runtime-skipped test reports a pass having checked nothing. ⚠ The design is corroborated independently of my C reading: log-file-symlink_test.py:24-28 states the same rule as its defense model - "for each component that IS a symlink, fstat() the symlink itself and allow only if st_uid is 0 or geteuid(). Symlinks owned by an untrusted uid -> ELOOP." MANIFEST. The root leg reported `log-file-symlink: expected fail, got pass`. That test lchowns its plant to an untrusted uid, so the fix keeps refusing it - the xpass is a genuine improvement and the row is re-baselined to `pass`. `operator-path-log-file` root stays `fail` DELIBERATELY: its matrix also covers --insecure-links cells, and --log-file does not honour that opt-out yet (the test says so in its own header). Under root the insecure cross-uid cell still fails, so the row is still correct. Only the nonroot leg should return to pass. VERIFIED: fast_io 751/751; workspace clippy --all-targets --all-features -D warnings exit 0; fmt clean. * test(daemon): stop racing the daemon's per-transfer log line on teardown `Linux musl (stable)` failed on this PR with one test: reverse_lookup_off_renders_undetermined_everywhere no PROBE line in daemon log: ... rsync allowed access on module m from UNDETERMINED (127.0.0.1) ... module 'm' from UNDETERMINED (127.0.0.1): protocol 32, role: Generator ... building file list Everything the daemon writes is present EXCEPT the last line - the per-transfer `log format` line the assertions consume. `Fixture::run` killed the daemon the instant the CLIENT process exited: let status = Command::new(client_bin)...status(); let _ = daemon.kill(); but that line is emitted by the DAEMON after the client disconnects, so nothing ordered the write before the kill. `spawn_daemon` already condition-polls for the listener instead of sleeping; the teardown just never got the same treatment. Now it waits for the line every caller asserts on, bounded at 10s, returning on timeout so a genuine absence still surfaces as `probe_line`'s panic rather than a hang. Waiting is unconditionally correct here: the shared config always sets `log format = PROBE_FORMAT`, and all three callers of `run()` immediately call `probe_line()`, so the line's absence is always a race and never an outcome. ⚠ NOT CAUSED BY THIS PR, and verified rather than assumed: `operator_open_append` has exactly ONE call site in the tree (crates/cli/.../workflow/run.rs:1221, the client's `--log-file`). The daemon's `log file` directive does not go through it, so the ownership-walk change cannot affect when the daemon writes. The daemon log being written at all is the second half of that argument - a broken log open would have produced no log, not a log missing its final line. ⚠ THE FIX IS UNPROVEN BY REPRODUCTION, deliberately stated: I could not reproduce the race on macOS - 25/25 runs passed with the wait REMOVED. The failure was on musl under CI scheduling. So this closes the unsynchronised window by construction and matches the observed signature exactly, but I have no red-then-green demonstration and am not claiming one. It cannot regress anything: it only adds a bounded wait for a line the callers already require. VERIFIED: 3/3 in 1.5s, so the wait returns promptly rather than riding the timeout; fmt clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
--log-filewas opened by handing the operator's path straight to the kernel, so both the leaf and every parent component were followed. A privileged rsync run with--log-fileunder an attacker-influenceable directory (canonical case/tmp/somedir/rsync.log) appends its log wherever a planted symlink points.This adds the missing sibling to
operator_rename/operator_link, which already sit on the ownership walk infast_io::owner_walk:operator_open_read(path)--password-file,--*-from, daemon config/secretsoperator_open_append(path, mode)--log-fileand routes
open_log_filethrough the second one.Upstream model
Two orthogonal policies, both mirrored:
owner_trusted_parent: follow a symlink owned by uid 0 or our euid, refuse any other-uid one (syscall.c:406).O_NOFOLLOW(syscall.c:469opens the last component withflags | O_NOFOLLOW), so a symlink at the named path is refused whoever owns it.syscall.c:537open_no_attacker_symlinks()is upstream's entry point for the opens that are not confined beneath a root;syscall.c:232names--log-fileand--*-fromas exactly that class, which is why this uses the ownership walk rather than the beneath-walk. Those paths may legitimately point outside the tree, so location cannot be the trust signal.Both halves are load-bearing and neither subsumes the other: the leaf guard stops
--log-file=$plant; only the parent walk stops--log-file=$plant/rsync.log, where the leaf does not exist yet soO_NOFOLLOWhas nothing to reject.Verification
4 new
owner_walktests. Mutation results, both reported:O_NOFOLLOW→ LETHAL.refuses_a_symlink_at_the_leaf_even_when_self_ownedfails. The plant is self-owned, which the parent rule would happily follow, so this cell discriminates leaf policy from parent policy rather than restating it.lchown). That half is covered by the upstream root-only celllog-file-symlink(LEAF + PARENT plants), not by anything in this PR.fast_io+cli: 4563/4563. fmt clean; full-workspace clippy--all-targets --all-features -D warningsclean.Scope
Only
--log-fileis routed here.--password-file,--exclude-from/--include-from/--files-from,--write-batch,--early-inputand the daemon config/secrets opens still resolve by path;operator_open_readexists for them and routing them is the follow-up. Keeping this to one call site keeps the security-relevant change reviewable.