| 1 | # Security Policy |
| 2 | |
| 3 | ## Supported Versions |
| 4 | |
| 5 | Only the current release of the software is actively supported. If you need |
| 6 | help backporting fixes into an older release, feel free to ask. |
| 7 | |
| 8 | ## Reporting a Vulnerability |
| 9 | |
| 10 | Email your vulnerability information to rsync's maintainer: |
| 11 | |
| 12 | Rsync Project <[email protected]> |
| 13 | |
| 14 | |
| 15 | ## Approach to platform residuals |
| 16 | |
| 17 | rsync hardens its security-sensitive operations — path resolution, metadata |
| 18 | application, file/socket creation — against local attacks such as parent-symlink |
| 19 | TOCTOU races. Some of these operations can only be made race-safe with a |
| 20 | primitive the underlying OS provides (an `*at()` syscall on a held directory fd, |
| 21 | an fdescfs-style `/proc/self/fd` magic symlink, `mknodat()`, the `*xattrat` |
| 22 | syscalls, and so on), and that primitive is not available on every supported |
| 23 | platform. |
| 24 | |
| 25 | The guiding rule for those cases is: |
| 26 | |
| 27 | > **On a modern Linux system every issue described in this document is fully |
| 28 | > addressed.** Where an operation *can* be secured on some platforms but *cannot* |
| 29 | > be secured on others, and the residual risk is a *local* privilege-escalation |
| 30 | > or data-disclosure class (an attacker who already has write access inside the |
| 31 | > transferred tree), rsync prefers keeping the operation functional on the |
| 32 | > platforms that lack the primitive over disabling a long-standing feature for |
| 33 | > everyone on those platforms. |
| 34 | |
| 35 | So a hardened operation takes the race-safe path wherever the platform offers one |
| 36 | and falls back to the historical (path-based, unconfined) behaviour only where it |
| 37 | does not — rather than refusing the operation outright. Each such fallback is an |
| 38 | accepted residual, documented under "Known residuals" below, and on the daemon it |
| 39 | can be turned off per feature with `refuse options = ...`. The residuals are |
| 40 | therefore confined to non-Linux platforms (the BSDs, macOS, Solaris/illumos), |
| 41 | Cygwin, and — for a few features — pre-6.13 Linux kernels; a current, normally |
| 42 | configured Linux deployment carries none of them. (The `/proc/self/fd`-based |
| 43 | fallbacks assume a mounted `/proc`, which every standard Linux provides; a |
| 44 | deliberately `/proc`-less container is the one Linux case that can still hit a |
| 45 | residual.) |
| 46 | |
| 47 | The one deliberate exception is an operation whose unconfined fallback would |
| 48 | *create a new filesystem object at an attacker-influenceable path* rather than set |
| 49 | metadata on the object rsync already transferred: the nested-socket `bind()` on |
| 50 | platforms without a race-safe socket-create (no `bindat()`). There the unsafe path |
| 51 | is an out-of-tree write/create primitive, not a same-object metadata race, and a |
| 52 | transferred socket inode is a worthless placeholder, so rsync refuses (skips) it |
| 53 | rather than keeping it functional. A leaf permission change is likewise failed |
| 54 | closed rather than applied through a raced symlink, but only as a rare backstop: |
| 55 | the common file/dir/FIFO case is secured on every platform via `fchmod` on a held |
| 56 | fd, so no real functionality is lost. |
| 57 | |
| 58 | This trade-off applies only to these local-attacker residual classes. Remotely |
| 59 | reachable defects — memory safety, authentication bypass, protocol parsing, input |
| 60 | bounds — are fixed unconditionally on all platforms, never left as a residual. |
| 61 | |
| 62 | |
| 63 | ## Robustness against malicious peers |
| 64 | |
| 65 | rsync treats everything the peer sends — the file list, checksum headers, |
| 66 | multiplexed messages, forwarded daemon arguments, filter rules — as untrusted, |
| 67 | and bounds-checks it before use. A peer-triggerable crash of a connection's |
| 68 | worker process is treated as a defect to be fixed, even though the daemon's |
| 69 | fork-per-connection model confines such a fault to that one connection rather |
| 70 | than the whole service. |
| 71 | |
| 72 | Alongside the issues enumerated elsewhere in this document, the code is hardened |
| 73 | continuously through protocol fuzzing (driving the daemon protocol against a |
| 74 | writable module) and static analysis, with a CI gate. This release closes a |
| 75 | batch of peer-triggerable faults found that way: NULL-dereference and |
| 76 | reachable-assert crashes from crafted file lists or indices, reads past a |
| 77 | file-list allocation (mostly bounded over-reads of an entry's extra slots), |
| 78 | unbounded merge-file and suffix-list recursion, and several bounded |
| 79 | out-of-bounds writes driven by peer-supplied lengths or option arguments. Each |
| 80 | is fixed at the root with a bounds or validity check plus a defence-in-depth |
| 81 | guard at the use site, and carries a regression test. |
| 82 | |
| 83 | Two further peer-input hardenings in this release: a peer-supplied I/O-error |
| 84 | value (the `MSG_IO_ERROR` message and the file-list trailer) is masked to the |
| 85 | defined `IOERR_*` bits, so a peer cannot set arbitrary error flags in the local |
| 86 | `io_error` that would be stored and re-forwarded upstream; and control |
| 87 | characters in a (peer-controlled) filename written to the log file are escaped, |
| 88 | so a name carrying C0/C1 terminal-escape bytes cannot inject sequences into an |
| 89 | administrator's terminal when the log is viewed (CWE-117). The number of |
| 90 | equal-weak-checksum blocks `hash_search()` examines per offset is also bounded |
| 91 | (issue #217), so a crafted or degenerate checksum set with a very long |
| 92 | equal-checksum chain cannot drive the sender's per-offset match-verify into a |
| 93 | quadratic walk and pin one connection's CPU. |
| 94 | |
| 95 | Contributors adding code that consumes peer input should validate it at the |
| 96 | point of receipt rather than relying on a downstream check. |
| 97 | |
| 98 | |
| 99 | ## Symlink-race-safe path resolution |
| 100 | |
| 101 | This section documents how rsync defends against parent-directory symlink races |
| 102 | (a TOCTOU / confused-deputy class) and the per-platform approach it takes, so |
| 103 | that contributors and automated agents extend the code consistently rather than |
| 104 | reintroducing the weakness. |
| 105 | |
| 106 | ### The threat |
| 107 | |
| 108 | Many rsync operations resolve pathnames that an unprivileged party can partially |
| 109 | control: a receiver writing into a destination tree, a sender reading a source |
| 110 | tree, and temp and partial files, and so on. (The operator-chosen directory |
| 111 | paths — `--link-dest`/`--compare-dest`/`--copy-dest`/`--backup-dir`/`--temp-dir`/ |
| 112 | `--partial-dir` — may legitimately point outside the tree, so they are resolved |
| 113 | by the ownership walk described under *Symlink defense for operator-supplied |
| 114 | paths* below rather than the strict transfer-path resolver here.) If someone who |
| 115 | can write inside that tree races a |
| 116 | parent directory component between a real directory and a symlink ("symlink |
| 117 | flipping"), a path-based syscall — `open`, `stat`, `chmod`, `chown`, `utimes`, |
| 118 | `rename`, `unlink`, `mkdir`, `mknod`, `symlink`, hard-link creation — can be |
| 119 | redirected to a target *outside* the intended tree. When rsync resolves that |
| 120 | path with more authority than the component's controller and without a |
| 121 | confinement boundary, this is a confused-deputy bug (e.g. a root nightly backup |
| 122 | capturing `/etc/shadow`, or a root receiver chmod/chown/unlink-ing a system |
| 123 | file). |
| 124 | |
| 125 | `O_NOFOLLOW` on the final component is **not** sufficient: the *parent* |
| 126 | components must be resolved safely. |
| 127 | |
| 128 | The boundary that matters is **authority plus confinement**, not "daemon vs |
| 129 | non-daemon". A non-chroot daemon module, a root-run local transfer, and a |
| 130 | two-user transfer are all unconfined privileged path resolvers. Where a real |
| 131 | confinement boundary already exists (e.g. a per-module `chroot`) that is the |
| 132 | strongest protection; otherwise rsync must resolve paths defensively. |
| 133 | |
| 134 | A `chroot` is only a boundary for the *outer* path it confines. A daemon module |
| 135 | written as `path = /outer/./inner` (`use chroot = yes`) chroots to `/outer` but |
| 136 | treats `/inner` as the module root, so a symlink inside the module that points to |
| 137 | a sibling of `/inner` is still inside the chroot yet outside the module — the |
| 138 | inner module therefore needs the same defensive resolution as a non-chroot |
| 139 | module. The single gate that decides when hardened resolution applies is |
| 140 | "unconfined privileged resolver": `am_daemon && (!am_chrooted || module_dirlen)` |
| 141 | for the daemon (any non-chroot module, plus a `/./` inner-module chroot), and any |
| 142 | non-chroot receiver. The local sender's content open is confined the same way for |
| 143 | default symlink handling; only the symlink-following modes (`-L`/`--copy-links`/ |
| 144 | `--copy-unsafe-links`/`-k`) and `--insecure-links` are excluded, so those keep |
| 145 | following symlinks by design. |
| 146 | |
| 147 | ### The mechanism |
| 148 | |
| 149 | Resolution of attacker-influenceable paths goes through `secure_relative_open()` |
| 150 | and the `do_*_at()` wrappers in `syscall.c`, never a raw `open()`/`rename()`/ |
| 151 | `chmod()` on a full path string. The principle is: **trust the operator-named |
| 152 | transfer root, and confine all resolution beneath it**, rejecting escapes via |
| 153 | `..` above the anchor, absolute symlinks, or out-of-tree symlinks. |
| 154 | `secure_relative_open()` resolves the parent directory by walking it one |
| 155 | component at a time on a stack of held directory fds, then operates on the final |
| 156 | component with an at-style call on the resulting directory fd. |
| 157 | |
| 158 | For per-entry work the receiver and generator go one step further and hold the |
| 159 | parent directory open: `open_dir_secure()` resolves an entry's directory once |
| 160 | (via `secure_relative_open()`), `held_dfd_for()` caches that descriptor for the |
| 161 | duration of the entry, and every operation on the entry — `lstat`, the temp-file |
| 162 | `mkstemp`, the temp->final `rename`, `chmod`/`chown`/`utimes`, `mkdir`, special- |
| 163 | file and symlink creation, the delta-basis open, and the recursive delete — runs |
| 164 | through that one held fd via an `*at()` call (`do_*_atfd()`). Because the |
| 165 | descriptor is pinned to the directory inode, a parent component flipped to a |
| 166 | symlink *after* the open cannot redirect any of those operations. The alternate- |
| 167 | destination lookups are confined the same way (`basis_link_stat()` in |
| 168 | `generator.c` and `secure_basis_open()` in `receiver.c`), so a peer-chosen |
| 169 | `--link-dest`/`--compare-dest`/`--copy-dest` basis index cannot reach an |
| 170 | out-of-module file through a symlinked parent. |
| 171 | |
| 172 | The sender's source-directory *enumeration* is confined the same way as its |
| 173 | content open. `send_directory()` opens each scanned directory through |
| 174 | `secure_opendir()` — which resolves it via `secure_relative_open()` / |
| 175 | `secure_relative_open_at()` and turns the held fd into the `DIR*` with |
| 176 | `fdopendir()` — so a parent component raced into a symlink, or (for a daemon |
| 177 | following mode) an in-module symlink pointing outside the module, cannot redirect |
| 178 | the scan to enumerate an out-of-tree directory and leak its entry names, metadata |
| 179 | and symlink targets. For a daemon, both the enumeration and the content open |
| 180 | anchor at the served module root **pinned by identity**: `module_dirfd` is opened |
| 181 | (`open(".")`) the moment the daemon `chdir`s into the module, while still |
| 182 | privileged, and module-relative paths resolve beneath that fd via |
| 183 | `secure_relative_open_at()`. Anchoring at the held fd rather than re-resolving the |
| 184 | absolute module path keeps the confinement working after the daemon drops to the |
| 185 | module uid even when the module sits under a directory that uid cannot traverse |
| 186 | (e.g. a `0700` home — re-resolving the absolute path would `EACCES`), and is |
| 187 | immune to the logical-path-versus-real-cwd skew a followed in-tree directory |
| 188 | symlink would otherwise introduce. |
| 189 | |
| 190 | ### Path resolution |
| 191 | |
| 192 | `secure_relative_open()` resolves a path with a single portable mechanism on |
| 193 | every platform: a per-component walk on a stack of held directory fds. Each |
| 194 | component is opened relative to the held parent with `openat(parent_fd, |
| 195 | "component", O_NOFOLLOW)`; descending into a real subdirectory pushes its fd, a |
| 196 | `..` pops back to the already-held parent (a pop at the anchor is refused), and an |
| 197 | in-tree directory symlink is followed by reading its target and walking that off |
| 198 | the same stack (absolute targets refused, symlink hops bounded). The final |
| 199 | component is opened `O_NOFOLLOW`. |
| 200 | |
| 201 | Because every component is opened relative to a *pinned* fd under `O_NOFOLLOW`, |
| 202 | and `..` is resolved by the held-fd stack rather than by the kernel, the walk is |
| 203 | race-free by construction: no rename or symlink swap of any path name can redirect |
| 204 | resolution outside the anchor subtree, and no kernel "beneath" primitive |
| 205 | (`openat2(RESOLVE_BENEATH)` / `openat(O_RESOLVE_BENEATH)`) is required. The |
| 206 | confinement is therefore uniform across Linux, the BSDs, macOS and |
| 207 | Solaris/illumos, on old and new kernels alike, with nothing to probe or fall back |
| 208 | to at runtime (and so no `openat2`/seccomp interaction to worry about in sandboxed |
| 209 | environments). Cygwin is the exception, because its directory descriptors and |
| 210 | symlink emulation do not give the held-fd walk the same inode pinning — see the |
| 211 | Cygwin residual below. |
| 212 | |
| 213 | Legitimate *in-tree* directory symlinks are followed, so `--keep-dirlinks` / |
| 214 | `--copy-links` and a symlinked module path keep working. A relative alternate-dest |
| 215 | such as `--compare-dest=../01` may legitimately climb to a sibling still inside the |
| 216 | module; such a `..` path is re-anchored at the module root and its in-module climb |
| 217 | adjudicated by the walk (the `..` pops to the held parent), while escapes above the |
| 218 | anchor are still rejected. |
| 219 | |
| 220 | ### Leaf operations |
| 221 | |
| 222 | The final operation is hardened as well, following `cp`: reads use `O_NOFOLLOW` |
| 223 | so a flipped leaf symlink is not followed, and new or destination files are |
| 224 | created with `O_CREAT|O_EXCL` (rsync's temporary files use `mkstemp`) so a |
| 225 | planted symlink at the target cannot be written through. A leaf `chmod` is the |
| 226 | one operation with no portable no-follow form: it is closed by opening the leaf |
| 227 | `O_RDONLY|O_NOFOLLOW` and `fchmod`-ing the held fd (refusing a symlink leaf with |
| 228 | `ELOOP`), falling back to `fchmodat(AT_SYMLINK_NOFOLLOW)` and then the |
| 229 | `fchmodat2()` syscall, and failing closed with a warning rather than ever |
| 230 | chmod-ing through a raced leaf symlink. |
| 231 | |
| 232 | ### Guidance for contributors |
| 233 | |
| 234 | * When adding code that performs a path-based syscall on a path that can be |
| 235 | influenced by the remote peer or by another local user, use a `do_*_at()` |
| 236 | wrapper (or `secure_relative_open()`), not a raw full-path syscall. |
| 237 | * When introducing a new operation, add a matching `do_<op>_at()` wrapper that |
| 238 | resolves the parent with `secure_relative_open()` and acts via an at-style call |
| 239 | on the returned dirfd. |
| 240 | * Do not assume a non-daemon transfer is safe; the question is whether rsync has |
| 241 | more authority than whoever controls the path components. |
| 242 | * On platforms whose API lacks an at-style equivalent (e.g. `setattrlist()`), |
| 243 | follow the residuals policy at the top of this document: for a metadata |
| 244 | operation on the already-transferred object (ACLs, xattrs, crtimes, permissions) |
| 245 | fall back to the path-based call to keep the feature functional and document the |
| 246 | residual; but where the unsafe fallback would *create a new object on an |
| 247 | unconfined path* (the nested-socket `bind()` case), refuse it instead — that is |
| 248 | an out-of-tree write/create primitive, not a same-object metadata race, and the |
| 249 | lost functionality is negligible. |
| 250 | |
| 251 | |
| 252 | ## Symlink defense for operator-supplied paths |
| 253 | |
| 254 | rsync opens several operator-supplied paths during normal operation. These fall |
| 255 | into two groups, both governed by the same ownership-walk policy below: |
| 256 | |
| 257 | * operator **files**: `--log-file`, `--password-file`, `--early-input` (a client |
| 258 | read whose contents are forwarded to the daemon's early-exec), `--files-from`, |
| 259 | `--include-from`, `--exclude-from`, `--filter=. file`, `--write-batch`, |
| 260 | `--read-batch`, per-directory filter merge files (`-C` / `-F` / `dir-merge`), |
| 261 | and on the daemon side `motd file =`, `secrets file =`, `lock file =`, and |
| 262 | `rsyncd.conf` itself. |
| 263 | * operator **directories**: `--backup-dir`, `--temp-dir`/`-T`, `--partial-dir`, |
| 264 | and the `--link-dest`/`--compare-dest`/`--copy-dest` basis lookup. These take |
| 265 | a directory the operator chose, which may legitimately point outside the |
| 266 | transfer tree (`--backup-dir=/var/backups`), so they are resolved with the |
| 267 | ownership walk rather than the strict transfer-path resolver. |
| 268 | |
| 269 | The daemon module-root `chdir()` under |
| 270 | `use chroot = no` and the non-daemon receiver's `chdir()` into the |
| 271 | operator-named destination directory are in the same class: both follow |
| 272 | the operator's/root's own symlinked target (the `/backup -> /mnt/disk` |
| 273 | admin pattern) but refuse one an attacker raced in from another uid, |
| 274 | unless `--insecure-links` restores the legacy plain `chdir()`. |
| 275 | |
| 276 | Each of these reads or writes a path the operator or sender chose, which |
| 277 | may transit attacker-influenceable parent directories (the `/tmp/somedir/` |
| 278 | class) or be planted directly (the `/home/$user/.cvsignore` class when |
| 279 | root runs `rsync -a /home /backup`). |
| 280 | |
| 281 | rsync's defense, applied uniformly to all of the above, is a |
| 282 | component-by-component path walk (`open_no_attacker_symlinks` in |
| 283 | `util1.c`) that allows symlinks **only** when the symlink itself is owned |
| 284 | by uid 0 or the running process's effective uid. Symlinks owned by any |
| 285 | other uid are refused with `ELOOP` at any path component (parent or leaf). |
| 286 | Plain `O_NOFOLLOW` would be leaf-only and would not defend the |
| 287 | `/tmp/somedir/log` parent-component plant; this walk does. |
| 288 | |
| 289 | The trust model preserves legitimate setups such as `/var/log -> /data/log` |
| 290 | (root-owned dir-symlink) and a non-root user's own `~/log -> /data/me` |
| 291 | symlink; it refuses an attacker's `/tmp/somedir -> /attack/path` plant. |
| 292 | For `--read-batch` an additional `fstat()` check refuses non-regular |
| 293 | files (FIFOs, devices) at the batch path, since the batch content drives |
| 294 | the receiver's protocol parser. |
| 295 | |
| 296 | **Policy.** A symlink at **any** path component (parent or leaf) is **followed |
| 297 | iff it is owned by uid 0 or the process's effective uid, and refused (`ELOOP`) |
| 298 | otherwise**, identically for **absolute and relative** operator paths. The trust |
| 299 | signal is **authority (ownership)**, not **location**: an operator path may |
| 300 | legitimately point outside the transfer tree, so it cannot be confined by |
| 301 | location the way a transfer path is. This is deliberately distinct from the |
| 302 | transfer-path resolver `secure_relative_open()` (see *Symlink-race-safe path |
| 303 | resolution* above), which refuses **all** symlinks and anchors **beneath the |
| 304 | transfer root** — correct for peer-named paths, which never legitimately escape. |
| 305 | For the operator directory paths, a refused symlink simply makes the target look |
| 306 | absent (no backup/temp/basis is taken through it) and the transfer proceeds |
| 307 | normally; the operator's own symlinked target keeps working. |
| 308 | |
| 309 | **The daemon `exclude`/`filter` chain is not a symlink boundary.** The daemon |
| 310 | filter chain (`exclude`, `exclude from`, `filter`, …) matches the *logical* |
| 311 | module-relative **name** of each item, not the physical file it resolves to. It |
| 312 | is a visibility/tamper filter — a peer cannot *name* a daemon-excluded path to |
| 313 | pull, push to, or delete it — but it is **not** a security boundary against |
| 314 | symlinks: an in-module symlink whose own name is not excluded can be followed to |
| 315 | an excluded target (the name the filter sees, e.g. `link`, is not the excluded |
| 316 | name, e.g. `secret`). This is by design and is the long-standing behaviour of |
| 317 | stock rsync; the defense for a writable module against symlink trickery is |
| 318 | `munge symlinks` (enabled by default for a writable, non-chrooted module), **not** |
| 319 | the filter. Do not rely on `exclude`/`filter` to confine a peer who can introduce |
| 320 | or traverse a symlink; see `rsyncd.conf(5)` ("filter" and "munge symlinks"). |
| 321 | |
| 322 | What *is* enforced for a *peer-supplied* operator path (`--partial-dir`, |
| 323 | `--backup-dir`, the alt-dest basis) is confinement to the **module root**: the |
| 324 | ownership walk refuses a foreign-uid symlink (the symlink-race defense) and |
| 325 | refuses a resolved target *outside* the module. That module-boundary confinement |
| 326 | is independent of `exclude`/`filter` — it holds whether or not the module sets an |
| 327 | exclude — and is what the operator-path tests cover. |
| 328 | |
| 329 | **`--insecure-links`.** This flag is a **local** opt-out that restores the legacy |
| 330 | follow-any-symlink behaviour for the paths above. It is **not forwarded** to the |
| 331 | remote (a remote-shell peer that wants the opt-out must set it on its own side, |
| 332 | e.g. via `--rsync-path`), and a **daemon never honors it**: the opt-out predicate |
| 333 | reads the client-controllable flag only off a daemon, so a peer-forwarded or |
| 334 | `-M`-injected `--insecure-links` cannot weaken a daemon's confinement — the daemon |
| 335 | additionally hard-refuses it (drops the connection) via the refused-options path. |
| 336 | A daemon admin who wants the legacy behaviour for one isolated/trusted module |
| 337 | sets `insecure links = yes` in that module's `rsyncd.conf` stanza (see |
| 338 | `rsyncd.conf(5)`); this is admin-only and re-opens the symlink-escape |
| 339 | vulnerabilities for that module on purpose. The `operator-path-*` and |
| 340 | `insecure-links-*` tests enforce this consistency across every path-taking |
| 341 | option and across absolute/relative, leaf/parent, and same-uid/cross-uid plants. |
| 342 | |
| 343 | For `support/rrsync` (the SSH-restricted-rsync wrapper), the same TOCTOU |
| 344 | class is closed in Python by opening each validated path component with |
| 345 | `O_RDONLY|O_NOFOLLOW`, verifying via `readlink('/proc/self/fd/N')` that the |
| 346 | pinned inode is still in-tree, and passing `/proc/self/fd/N` as the exec'd |
| 347 | rsync's argument (so the kernel routes the child's open through the pinned |
| 348 | inode rather than re-resolving the path). A receiver-side new destination |
| 349 | has no inode of its own yet, so its existing parent directory is pinned the |
| 350 | same way and the leaf is created at `/proc/self/fd/<parent>/<leaf>`. This pin |
| 351 | relies on an fdescfs-style magic symlink and is not available on every |
| 352 | platform -- see the rrsync residual below. |
| 353 | |
| 354 | ### Known residuals |
| 355 | |
| 356 | The following are documented as out of scope for this release: |
| 357 | |
| 358 | * The source-directory *enumeration* confinement needs `fdopendir()` (to form a |
| 359 | `DIR*` from the securely-resolved held fd) and `dirfd()`; on a platform lacking |
| 360 | either, `send_directory()` falls back to the legacy `opendir()` on the path, so |
| 361 | the scan is unconfined there — the same resolver-fallback shape as the other |
| 362 | `*at()`-less residuals. Every current target provides both; the per-entry |
| 363 | operations and the content open remain confined regardless. |
| 364 | |
| 365 | * On **Cygwin**, the per-component held-fd walk does not provide the same |
| 366 | inode-pinning guarantee as on a POSIX kernel: Cygwin tracks a process's |
| 367 | current directory and resolves directory descriptors by path name rather than |
| 368 | by a pinned inode, and emulates symlinks as special files. Static out-of-tree |
| 369 | symlinks are still refused (the walk sees and rejects them), and a daemon |
| 370 | module path anchored at an absolute `module_dir` is confined; but an entry |
| 371 | whose parent component is *raced* from a directory to a symlink mid-resolution |
| 372 | can still slip past confinement that is anchored at the process CWD (e.g. the |
| 373 | sender's content open), because the descriptor is not bound to the original |
| 374 | inode. The parent-component symlink-race tests are therefore not enforced on |
| 375 | Cygwin (see `RSYNC_EXPECT_SKIPPED` in `.github/workflows/cygwin-build.yml` and |
| 376 | the Cygwin-only xfail in `symlink-race-source_test.py`). Cygwin is a |
| 377 | development/interoperability target, not a privilege boundary host, so this is |
| 378 | accepted for this release. |
| 379 | |
| 380 | * On a platform with no `mknodat()` at all -- macOS before 13 is the |
| 381 | supported example, where `mknod()` and `mkfifo()` exist but neither |
| 382 | `mknodat()` nor `mkfifoat()` does -- creating a device node or FIFO |
| 383 | falls back to plain `do_mknod()`, which resolves the whole path by name. |
| 384 | What is lost is the *pinned parent*: the directory components are |
| 385 | re-resolved by the kernel at create time, so an attacker who can swap a |
| 386 | parent component races the create and can place the node outside the |
| 387 | transfer. The final component is not at risk -- `mknod()` and |
| 388 | `mkfifo()` do not follow a symlink at the leaf, they fail `EEXIST`. |
| 389 | Where `AT_FDCWD` exists -- which is every platform rsync 3.5.0 supports, |
| 390 | macOS 10.13 included -- fake-super placeholders still return through |
| 391 | `openat(..., O_NOFOLLOW)`, reached before either `*at` primitive is |
| 392 | tested, so ordinary in-tree placeholder creation stays confined; |
| 393 | fake-super loses parent confinement and the `O_NOFOLLOW` leaf only on the |
| 394 | paths that reach plain `do_mknod()` (the cache-declined/cross-tree |
| 395 | wrapper and the backup paths). On a build with no `AT_FDCWD` at all |
| 396 | there is no fd-relative primitive of any kind, so nothing above applies |
| 397 | and every special-file create, fake-super included, is unconfined. Transferring specials there (`--devices`, `--specials`) carries |
| 398 | the parent-component race. `symlink-mknod-fakesuper-symlink-race` skips |
| 399 | itself on such a build, since the property it asserts is one the build |
| 400 | deliberately does not have. |
| 401 | |
| 402 | * On platforms where `mknod()`/`mknodat()` cannot create a socket inode |
| 403 | (the BSDs, macOS, Solaris), a transferred socket is recreated with |
| 404 | `socket()` + `unlink` + `bind(path)`, which cannot be confined (there is |
| 405 | no portable `bindat()`). Linux creates it race-safely with `mknodat()` |
| 406 | on a held dirfd; on the others a *nested* socket is skipped with a |
| 407 | warning rather than bound on an unconfined path, leaving only a |
| 408 | top-level, operator-named socket binding by path. |
| 409 | |
| 410 | * `support/rrsync`'s race-free inode-pin -- of both existing path |
| 411 | components and a new destination's parent -- depends on materialising a |
| 412 | held fd as a path that the exec'd rsync re-resolves to the same inode. |
| 413 | rrsync validates and pins in its own process, but it then *exec*s a |
| 414 | separate rsync that re-resolves the paths from `argv`, so the confining |
| 415 | reference must be expressible as an argument. A held dirfd is not: it is |
| 416 | usable as a path only through an fdescfs-style magic symlink. rrsync |
| 417 | implements this for Linux only, via `/proc/self/fd/N`; it does not use the |
| 418 | `/dev/fd/N` equivalent that macOS/FreeBSD expose with `fdescfs` mounted. So on |
| 419 | every non-Linux platform (the BSDs, macOS, Solaris -- whose `/proc/self/fd` |
| 420 | entries are not magic symlinks -- and Cygwin), and on a `/proc`-less Linux |
| 421 | namespace, rrsync falls through to the realpath-validated path unpinned, |
| 422 | so a parent-component or between-pin-and-exec flip remains possible there; |
| 423 | a deeper `-R` new path whose parent does not exist yet is likewise |
| 424 | unpinned. The portable closure is an rsync-side fd-passing API -- rrsync |
| 425 | hands rsync the confined dirfd (inherited across `exec`) and rsync |
| 426 | resolves that argument relative to it with the same `secure_relative_open` |
| 427 | resolver the daemon uses, needing no magic-symlink filesystem -- a |
| 428 | protocol/CLI addition under discussion on the rsync-security list. |
| 429 | |
| 430 | * The operator-directory ownership walk refuses a foreign-owned symlink on a |
| 431 | `--backup-dir`/`--temp-dir`/`--partial-dir`/`--link/compare/copy-dest` path, so |
| 432 | a *statically planted* symlink is rejected and the dependent operation does not |
| 433 | escape. Both the data writes and the *source-metadata reads* of those |
| 434 | operations are now confined to held no-follow fds: the `--copy-dest` |
| 435 | `copy_file()`/`copy_xattrs()` source read goes through the held basis content fd |
| 436 | (`sys_fgetxattr`), and `make_backup()` reads the backed-up file's ACL/xattrs |
| 437 | through a `backup_source_fd()`-pinned fd -- so a parent-component flip can no |
| 438 | longer redirect them to disclose an out-of-module value. The cross-tree |
| 439 | metadata *apply* on those leaves (the `%stat`/ACL/xattr write on a |
| 440 | `--temp-dir`/`--backup-dir` staging file) is fd-pinned the same way, now |
| 441 | including under `--fake-super`: the `set_file_attrs()` no-follow leaf fd was |
| 442 | previously opened only when `am_root >= 0`, so a `fake super = yes` daemon fell |
| 443 | back to a path-based `sys_lsetxattr()`/chmod a raced parent could redirect; the |
| 444 | pin is now opened for fake-super too (a raced leaf is refused, not redirected). |
| 445 | Two narrow follow-ons |
| 446 | re-resolve the (now-validated) operator path by name and remain a |
| 447 | *post-validation* parent-component race: |
| 448 | * the in-place backup (`--inplace --backup`) writes the backup file's data |
| 449 | through a confined create, but its `set_file_attrs()` metadata set |
| 450 | (chmod/chown/times) re-resolves the `--backup-dir` path by name afterwards |
| 451 | (it is not placed under operator mode, which would force the shared |
| 452 | `set_file_attrs()` path off its held-O_NOFOLLOW-fd xattr write and re-open |
| 453 | the very parent-symlink xattr race `copy-xattrs-symlink-race` pins closed); and |
| 454 | * the abbreviated-xattr optimisation reuses a basis xattr value for the |
| 455 | destination only when its checksum matches the digest the sender sent; that |
| 456 | basis read (`rsync_xal_set()`) re-resolves the basis path by name. This is a |
| 457 | *constrained checksum-oracle*, not a disclosure: it confirms that some raced |
| 458 | out-of-module xattr hashes to a value the sender already chose, rather than |
| 459 | copying an unknown value onto a readable file, and needs a colluding sender |
| 460 | plus a local racer. |
| 461 | An attacker who flips a parent component in the window *after* the confined data |
| 462 | write/stat can thus still affect those narrow metadata/oracle operations. This |
| 463 | is the same local-attacker post-confinement TOCTOU class as the ACL/crtimes |
| 464 | residuals below; the data-write and direct source-read escapes are closed, and |
| 465 | `--insecure-links` (or a module's `insecure links = yes`) is orthogonal to it. |
| 466 | |
| 467 | * POSIX ACL application (`-A`/`--acls`) is race-safe on every Linux kernel — |
| 468 | 6.13+ via the `*xattrat` syscalls (or a patched libacl's `*_at` bindings), and |
| 469 | older kernels via the `/proc/self/fd` compat that pins the same inode, provided |
| 470 | `procfs` is mounted — and a transferred file/dir/FIFO has its xattrs (`-X`) |
| 471 | applied through the held no-follow fd, so the apply cannot be redirected by a |
| 472 | raced parent component. Where neither primitive is available — the BSDs, |
| 473 | Solaris and macOS (no `*xattrat` syscalls and no `/proc/self/fd` magic |
| 474 | symlinks), plus the edge case of a Linux instance with no usable `/proc` (a |
| 475 | `/proc`-less container/namespace) — the ACL apply falls back to the path-based |
| 476 | `acl_set_file()` / |
| 477 | `sys_acl_*file()` calls — the long-standing 3.4.x behaviour — to keep `--acls` |
| 478 | functional rather than silently skipping it, so a parent-component flip can |
| 479 | have the received ACL written onto an object outside the module/destination |
| 480 | boundary (and, because the attacker controls the ACL bytes, granted to a chosen |
| 481 | uid). As with the macOS crtime tier below, this is an accepted residual under |
| 482 | the functionality-over-refusal policy; a daemon operator who does not want it |
| 483 | can disable the feature with `refuse options = acls`. |
| 484 | |
| 485 | * macOS creation-time (`--crtimes`) preservation uses the path-based |
| 486 | `setattrlist()`/`getattrlist()` with `FSOPT_NOFOLLOW`, which protects only |
| 487 | the final component; there is no `setattrlistat()` targeting |
| 488 | `ATTR_CMN_CRTIME`. As with POSIX ACLs where the OS offers no race-safe |
| 489 | primitive, `--crtimes` is kept functional (daemon and non-daemon) and the |
| 490 | parent-component symlink race is an accepted residual: an attacker who |
| 491 | flips a parent component can have a crtime read/write target an object |
| 492 | outside the module/destination boundary. The mtime/atime path is *not* |
| 493 | affected -- `set_times()` resolves it race-safely through `utimensat()` on a |
| 494 | held dirfd in hardened mode. A daemon operator who does not want the crtime |
| 495 | residual can disable the feature with `refuse options = crtimes` in |
| 496 | `rsyncd.conf`. |
| 497 | |
| 498 | * Pulling with `-o`/`-g` (or `-a`) **as root from an untrusted sender** is by |
| 499 | design a trust relationship, not a confinement boundary: the sender dictates |
| 500 | each received file's owner/group, including uid/gid 0. rsync maps the |
| 501 | sender's id/name pairs through the local id database; an empty or unknown |
| 502 | sender name falls back to the sender's numeric id (the value `--numeric-ids` |
| 503 | would use), and a sender can equally request root via the literal name |
| 504 | `root`. A root receiver must therefore only pull with `-o`/`-g` from a |
| 505 | trusted source (or use a non-root receiver / a uid-gid policy). The daemon |
| 506 | *name-converter* path is guarded separately — an unknown name there maps to |
| 507 | the sender's numeric id rather than 0 (see `clientserver.c`). |
| 508 | |
| 509 | ## Daemon authentication digest |
| 510 | |
| 511 | Daemon authentication is a secret-prefix challenge-response: the client returns |
| 512 | `base64(H(secret || challenge))`, where `H` is a digest the two sides negotiate. |
| 513 | The negotiation is unauthenticated and ordered by the connecting side, and the |
| 514 | `md5`/`md4` digests remain available for backward compatibility, so a peer that |
| 515 | sends no digest list (any rsync before 3.2.0, including the openrsync that ships |
| 516 | with macOS) falls back to `md5` (or `md4` below protocol 30), and an on-path |
| 517 | attacker can rewrite the negotiation to force `md5`/`md4` even between two modern |
| 518 | peers. This is **not** an authentication bypass — `md4`/`md5` have no practical |
| 519 | preimage break — but a weak digest makes a *captured* `(challenge, response)` |
| 520 | pair far cheaper to brute-force offline, recovering a guessable shared secret. |
| 521 | |
| 522 | The challenge itself is seeded from the kernel CSPRNG (`/dev/urandom`), so it is |
| 523 | an unpredictable per-connection nonce. An earlier time/pid-based challenge was |
| 524 | low-entropy enough (~35 bits) that recovering the `(sec, usec, pid)` tuple from |
| 525 | one observed challenge let an on-path observer predict every subsequent challenge |
| 526 | from that daemon process and pre-compute a dictionary against a captured |
| 527 | response. (If `/dev/urandom` is unavailable the daemon logs a warning and falls |
| 528 | back to the legacy time-based challenge rather than a constant.) |
| 529 | |
| 530 | A daemon operator whose clients are all modern (rsync 3.2.7+ built with openssl, |
| 531 | when the SHA digests were added) can require a strong digest with the `auth |
| 532 | digest` module parameter, e.g. `auth digest = sha256`, which refuses any |
| 533 | connection that negotiates — or falls back to — a weaker digest (see |
| 534 | `rsyncd.conf`). |
| 535 | |
| 536 | Residual: there is **no default floor**, because requiring one would break every |
| 537 | pre-3.2.0 client (notably the macOS-bundled openrsync, which authenticates only |
| 538 | with `md4`). An operator who cannot raise the floor should run the daemon behind |
| 539 | a verified TLS transport (`rsync-ssl`/stunnel) or over ssh — which removes the |
| 540 | on-path capture/downgrade vector at the transport layer — and should use a |
| 541 | high-entropy shared secret, which is infeasible to brute-force regardless of the |
| 542 | digest. |