Repository navigation
fix: walk unchrooted daemon module roots and destinations - #8904
Merged
Merged
Conversation
oferchen
force-pushed
the
fix/daemon-module-change-dir
branch
from
November 28, 2026 15:51
a7ac723 to
919e657
Compare
rsync 3.5.2 enters the module root with change_dir(module_chdir) for every session (clientserver.c:1063). For use chroot = no that is the ownership walk (util1.c:1351-1361): a symlink in the module path owned by another user is refused, and the client gets @error: chdir failed. oc ran that walk only when the session also chrooted or dropped privileges. A rootless daemon with use chroot = no returned early and served the module through the plain path, so a foreign-owned symlink in path = was followed on push and pull alike. The early path now runs the same walk and keeps the root's descriptor. It does not chdir: a session served as a thread of an async daemon would move every other session's working directory. The refusal is logged as 3.5.2 logs it: the walk's untrusted-symlink notice, then "[Receiver] chdir <path> failed: <errno text>" (clientserver.c:695). A privileged session still enters the module root before its privilege drop, as upstream does (clientserver.c:1063 before :1102, :1127), so a module below a directory its uid cannot search keeps working. Inside the module, 3.5.2 enters the client's destination with the confined walk, secure_relative_dirfd() and fchdir() (util1.c:1430-1446). An in-tree relative symlink is followed; one that leaves the module is refused with ELOOP whoever owns it. get_local_name() reports that as change_dir#1, #2 or #3 "<dest>" (in <module>) and exits 3, or as the make_path() mkdir failure with exit 11 under --mkpath. oc did a plain stat and failed later with its own code-11 line. The receiver now walks a daemon destination beneath the module root's descriptor through fast_io's open_dir_beneath, create_dir_beneath and make_path_beneath, and prints 3.5.2's lines. Each session records its module root once as a ServedRoot: the absolute module path, its canonical form and the root's descriptor. full_fname() strips the module root from that path, as util1.c:1543 strips module_dirlen from curr_dir, and a relative merge-file name is joined onto it (exclude.c:735-746). This also fixes the privileged leg, which served "." and printed link_stat "/d/d/a1" and "failed to open exclude file etc/hostname" where 3.5.2 prints "/d/a1" and the module-rooted name. insecure links = yes keeps the plain open for the root and the tail (syscall.c:139, :433-436), so an opted-out module's symlinked root is followed instead of being replaced by a new directory. The daemon now logs a fatal cause and trailer before framing them for the client, as rwrite() calls logit() before sending (log.c:390-407). A 3.5.2 client kills its remote-shell child on exit (cleanup.c:203-204), so a daemon reached that way lost the line when it logged afterwards. Deliberate deviation: 3.5.2's do_mkdir() (main.c:817) follows an escaping link and makes a new destination outside the module before change_dir#2 refuses it. oc refuses first, with the same line and exit code, and makes nothing.
oferchen
force-pushed
the
fix/daemon-module-change-dir
branch
from
November 28, 2026 16:52
919e657 to
5daed2c
Compare
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.
Summary
A daemon serving a module with
use chroot = nohad two gaps against rsync 3.5.2, one destructive bug, and one pre-existing rendering defect on its privileged leg.Data loss: an opted-out module's symlinked root was replaced. With
insecure links = yesandpath =naming a symlink, oc replaced the operator's symlink with a new empty directory and wrote the transfer into it. rsync 3.5.2 follows the link. oc now does the same: the symlink is still there afterward and the data lands in its target.The module root was never walked by a rootless daemon. rsync 3.5.2 enters the module root with
change_dir(module_chdir)on every session (clientserver.c:1063). For an unchrooted module that is the ownership walk (util1.c:1351-1361): a symlink inpath =owned by another user is refused. The client gets@ERROR: chdir failed, and the daemon log getschdir <path> failed(clientserver.c:692-699). oc had this walk, butapply_privilege_restrictions_with_upstream_errorsreturned early when the session neither chrooted nor dropped privileges. A rootless daemon therefore served a foreign-owned symlinked module root, on push and pull alike. The early path now runs the same walk and keeps the root's descriptor. It does not chdir (see "Working directory" below).The destination beneath the root was not walked either. rsync 3.5.2 enters the client's destination with the confined walk
secure_relative_dirfd()(util1.c:1430-1446). That walk follows an in-tree relative symlink and refuses one that leaves the module withELOOP, whoever owns it.get_local_name()then printschange_dir#1/#2/#3 "<dest>" (in <module>) failedand exits 3. Under--mkpathit printsmkdir ... failedand exits 11 (main.c:757-869). oc instead did a plain stat and failed later in its anchored sandbox, with either an oc-only code-11 line or a landlockEACCES. The receiver now walks a daemon destination beneath the module root's descriptor and prints 3.5.2's lines.Pre-existing defect on the privileged leg. A root daemon serving an unchrooted module with
uid =enters the module root and served the transfer as.. Two renderers took the module root from that spelling:full_fname()rendered a missing source aslink_stat "/d/d/a1" (in m). 3.5.2 prints"/d/a1"(util1.c:1540-1547,p1 = curr_dir + module_dirlen).failed to open exclude file etc/hostname; 3.5.2 logs<module path>/etc/hostname(exclude.c:735-746).Both reproduce on master (c87bc25) under
sudo. Both renderers now read one absolute module root, recorded once per session.insecure links = yeskeeps the plain open for both the root and the tail (syscall.c:139, :433-436; util1.c:1447-1451). A chrooted module also keeps the plain chdir for the tail.Difference from rsync 3.5.2's process model
The observable semantics are 3.5.2's, taken from its C source:
full_fname()strip (util1.c:1543)Only the mechanism differs, in one place. A rootless unchrooted session does not change directory; it walks relative to the module root's descriptor, because oc's threaded async daemon cannot share a process working directory.
change_dir(module_chdir, CD_NORMAL)(clientserver.c:1063). That is safe there because each connection is its own process:start_accept_loop()forks per connection (socket.c:761).--features async-daemon, oc serves sessions as threads of one process, and those threads share one working directory. Achdir/fchdirin one session would move every other session.fchdirinto the module root before the privilege drop, as 3.5.2 does (clientserver.c:1063 before the setgid/setuid at :1102 and :1127). A module below a directory itsuidcannot search works only that way.fchdir: a privileged session always runs in its own forked process, because the async daemon refusesuid,gid,use chrootand running as root (daemon.rs,run_async_daemon). No new task is needed.Client-visible output is byte-identical to 3.5.2. Both renderers take the module root from its absolute path, so they print what 3.5.2 prints from its working directory:
full_fname()strips the module root the way util1.c:1540-1547 does (p1 = curr_dir + module_dirlen).dirbuf.The oracle cells compare every line against 3.5.2, in both legs and in all four client/daemon pairings.
Changes
transferconfig/served_root.rs: newServedRoot. It holds the module root's absolute path, its canonical form, whether the session runs from that directory, and the root's descriptor. It is set once per connection and replacesdaemon_module_dir.transferfull_fname.rs:FullFnamePaths::daemontakes theServedRoot. The module strip always uses the absolute path. A session served from its working directory roots the relative spellings first; the sender's paths andcurr_dirare both cwd-space (.sender()), the receiver'scurr_dironly.transferreceiver/dest_root.rs: newEntry::Confined(ModuleRoot);Entry::Walkedis Unix-only, as its only constructor is. The destination is walked beneath the root's descriptor:open_dir_beneathcreate_dir_beneath--mkpaththroughmake_path_beneath, whoseELOOPstays make_path()'s own failure (exit 11), as the relative make_path of 3.5.2 reports it (syscall.c:2306-2332)ELOOPfrom change_dir is the refusal that names the steptransferreceiver/directory/mod.rs: the destination root itself is stat'd through a symlink that names it. Upstream stats.in the directory it entered (main.c:776-781). Without this, serving the absolute path brought the opted-out data-loss bug back.transfersetup/context.rs:destination_entrypicksConfinedfor an unchrooted daemon module that has not opted out. The merge-name filter strips the canonical and the absolute module root.daemonmodule_access/transfer/sandbox.rs:ServedRoot.[Receiver] chdir <path> failed: <strerror> (<errno>)in rsyserr form (clientserver.c:695).daemonorchestration.rs,server_config.rs: build theServedRootand hand it to the server config. A relative merge-file name is joined onto the absolute root (exclude.c:735-746).daemonmodule_access/helpers.rs:log_pending_diagnosticsdrains session diagnostics into the daemon log. It is shared withstreams.rs, so a notice raised before the transfer reaches the log, not stderr.daemonmodule_access/transfer/streams.rs: a fatal cause and its trailer are written to the daemon log before they are framed for the client. This matches upstream rwrite(), which calls logit() before sending (log.c:390-407).fast_ioat_syscalls/create.rs:open_dir_beneath,create_dir_beneathandmake_path_beneathtake the anchor descriptor.EINVALfor an absolute path or.., as at syscall.c:3477-3484.make_path_beneath_cwddelegates tomake_path_beneath(CWD, ...). The cwd-onlyopen_dir_beneath_cwdandcreate_dir_beneath_cwdare removed, so there are no duplicates.Deviations
mod/esc/new/, whereescleaves the moduledo_mkdir()(main.c:817) followsescand createsoutside/new, thenchange_dir#2 "esc/new" (in mod) failed: Too many levels of symbolic links (40), exit 3change_dir#2line, exit 3, nothing created outside the moduleThis deviation is owner-approved and matches #8858 and #8899. Every other cell below matches 3.5.2.
Measured
The 3.5.2 client drove a 3.5.2 daemon and an oc daemon, each with
use chroot = noand a globallog file. The rootless rows ran the daemon as an unprivileged user, withflink/escowned bynobody.@ERROR: chdir failed, exit 5flink/sub)insecure links = yes)rel -> inner)change_dir#1 "esc/" (in mod) ... (40), exit 3mod/esc/f)change_dir#3 "esc" (in mod) ... (40), exit 3--mkpath mod/esc/a/b/)mkdir "esc/a/b/" (in mod) ... (40), exit 11... Permission denied (13), exit 11mkdir ... (13), exit 11insecure links = yes)d/a1(root daemon,uid =the user)link_stat "/d/a1" (in m), exit 23link_stat "/d/d/a1" (in m)-M--filter=. /etc/hostnamefailed to open exclude file <module>/etc/hostname, exit 11... etc/hostnameDaemon log after the change: line for line equal to 3.5.2's, apart from the program name (
oc-rsync:) and the trailer location. That covers the untrusted-symlink notice,[Receiver] chdir <path> failed: ..., eachchange_dir#N/mkdirline with its trailer, and the merge-file line.Tests
crates/cli/tests/daemon_module_change_dir.rs. It runs each cell oc to oc and, whenOC_RSYNC_UPSTREAM_BIN_3_5_2resolves, with a 3.5.2 client, a 3.5.2 daemon, and both. Results must be equal, except for the deviation cell, which pins oc's daemon. The cells cover:@ERROR: chdir failed, exit 5, nothing written, and the untrusted-symlink notice followed by thechdir <path> failedlog linesudo -n: a missing source renderslink_stat "/inner/a1" (in priv), and the merge file is logged as<module>/etc/hostname. Red against the master binary ("/inner/inner/a1"), green after.uidcannot search (mode 000): push, pull and a new destination directory all exit 0 and land in the module. This pins why the privileged session keeps its working-directory entry.sudo -n. They fail rather than skip when it is unavailable.rsyncvsoc-rsync), and the log stamp before]is stripped. A trailer is compared up to its source location, which names each program's own file and line.crates/daemon/src/tests/chunks/daemon_async_push_pull.rs:concurrent_async_sessions_keep_their_own_module_roots_and_the_process_cwd. Two sessions on different modules run at once in one async daemon. Each pushes 200 files and pulls a seed from its own module, and the process working directory is unchanged afterwards. Red on this PR's first head (a7ac723), where the rootless path fchdir'd: the cwd moved tomodule-a. Green on master and after.crates/fast_io/tests/daemon_destination_beneath_root.rs(renamed from..._beneath_cwd.rs): the three walks beneath a descriptor, with no chdir. Covers the root and an in-tree link, an escape,EINVAL, mkdir errors, a wholemake_path, nothing made outside, and a cell showing the anchor, not the cwd, decides where a name resolves.full_fname.rsunit tests: a session served from its cwd renders the sender's./d/a1once below the root; the receiver roots only itscurr_dir; a session not served from its cwd roots nothing.OC_RSYNC_UPSTREAM_COMPAT=1and the 3.5.2 oracle (cargo nextest run -p <crate> --all-features):sudo -n.check_rustfmt_all-D warningson the host and onx86_64-pc-windows-gnu-D warningsno-placeholderscitation_drift_audit --ratchetFollow-ups
/./inner path (module_dirlen > 0). 3.5.2 confines the tail there too (util1.c:1430). oc keeps its anchored sandbox for chrooted modules, unchanged here.