Repository navigation
fix(daemon): refuse shell metacharacters in hook variable expansion - #7465
Merged
Merged
Conversation
A `%VAR%` reference expanded into a shell-executed hook directive is escaped
for the quoting context it lands in, and refused outright when the value
carries a character a shell could act on. Upstream applies this to the four
`FN_LOCAL_STRING_SHELL` directives - `early exec`, `name converter`,
`post-xfer exec`, `pre-xfer exec` (daemon-parm.h:349/363/365/366) - via
expand_vars(str, shell_escape=1) at loadparm.c:237-325.
Measured against real rsync 3.5.0 on Linux, upstream control run first:
cell upstream 3.5.0 oc before
daemon-exec-metachar-refused PASS FAIL
daemon-exec-metachar-documented-limit PASS FAIL
daemon-exec-second-shell-argument-injection PASS FAIL
⚠ THE EXPANSION LANGUAGES DIFFER, AND THAT IS THE ROOT CAUSE. Upstream
expands only delimited `%NAME%` environment references, gated on an uppercase
first letter plus a closing `%` (loadparm.c:250). oc's exec hooks were fed a
DIFFERENT language: single-character escapes `%P %m %u %a %h %p`, which
upstream does not have in config values at all - `%m` stays literal there.
So `pre-xfer exec = ... %RSYNC_USER_NAME% ...` never substituted anything,
and the cells failed on the POSITIVE control as much as on the refusal.
Consequences that a shape-only port of upstream's guard would have missed:
- The two languages COLLIDE. `%PATH%` reads as module-path + `ATH%` under the
single-char rule and as getenv("PATH") upstream. They therefore cannot be
layered as two passes - a value substituted by one would be rescanned by the
other, which is its own injection. This is one walk, delimited names first,
falling back to the single-char reading only when the candidate name is not
well-formed, so `%P/%m` keeps working while `%PATH%` reads as upstream reads
it.
- `%u`, `%h` and `%a` substitute peer-influenced values (auth user, reverse-DNS
hostname, peer address) into a shell command. Upstream has no such channel,
so porting its guard alone would have left that hole open. They now take the
same refusal as a `%RSYNC_*%` reference.
- ⚠ Both the pre-xfer and post-xfer sites passed `username: ""` into the
expansion, behind a comment presenting it as intentional. Resolving
`%RSYNC_USER_NAME%` from that context yields empty, so the fix would have
been INERT for the very cell it targets. Upstream sets RSYNC_USER_NAME to
the authenticated user on the daemon process at clientserver.c:815, ahead of
the hook retrieval at :959; both sites now do the same.
Resolvable names are read from the connection context rather than the process
environment, because oc sets the RSYNC_* variables on the hook CHILD while
upstream sets them on the daemon process. `RSYNC_REQUEST` and `RSYNC_ARG<n>`
are deliberately absent: upstream sets those inside the forked pre-exec child
(clientserver.c:568), after the directive is already expanded, so they are not
resolvable references on either implementation.
Three false upstream citations removed. `clientserver.c - exec command strings
support %P, %m, %u, %a, %h, %p` and the two claiming `log.c:lp_do_log_file()`
expands single-character escapes in path contexts describe behaviour upstream
does not have; they are why the divergence read as intentional.
Residuals, filed rather than claimed:
- Upstream expands all four directives together at clientserver.c:959-960,
BEFORE the transfer, so a refusal aborts via exit_cleanup(RERR_UNSUPPORTED).
oc expands per hook, so the post-xfer site can only decline to run the hook.
Hoisting oc's expansion to the same point is the follow-up.
- The refusal reaches the daemon log through rsync_error!, which adds the
`(code N)` envelope; upstream's rprintf(FLOG, ...) is bare.
- Whether oc's single-character escapes should exist in exec commands at all
is a genuine question - they are redundant with the RSYNC_* environment the
hook already receives, and they are the channel that needed the extra guard.
By the time a hook runs the stream is already multiplexed, so the plain @error line can fail to land. Sending first meant the `?` propagated that failure and the refusal never reached the daemon log - the operator's only record of a fail-closed security decision, dropped silently. Measured: the transfer already failed (rc=23) but the daemon log carried no refusal line at all, so the testsuite cells still could not tell the guard from an unrelated startup failure - which is exactly what they assert. upstream: loadparm.c:270-273 emits the FLOG line and only then calls exit_cleanup(), so the order is upstream's, not an invention.
Measured 3/3 GREEN against the fixed binary on Linux, upstream 3.5.0 control passing first. Row count unchanged at 345 on both pipe legs.
The two existing exec-command tests still compared the expansion against a &str after it started returning Result, so the daemon lib test target did not build and fmt+clippy failed before any other required check ran. Rewrite them against the new contract and add the coverage the change was missing: operator values stay verbatim, peer-influenced values are escaped for their quote context, the full refusal set fails closed, and the refusal names the token as written in the template.
The refusal is transport-independent - the daemon rejects the value while parsing the hook template, before any transfer - so all three cells pass over TCP exactly as they do over the pipe. Only the two pipe manifests were flipped, so both TCP legs saw an unexpected PASS and exited non-zero. Measured on both transports with the real 3.5.0 binary as the control: upstream PASS / oc PASS for all three. Row counts unchanged at 155 each.
oferchen
force-pushed
the
fix/daemon-hook-shell-metachar
branch
from
August 23, 2026 21:53
9c74368 to
ab5a701
Compare
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…7477) The docs were last refreshed at #7423; 55 PRs have merged since, and the testsuite figures they quote had drifted far enough to understate the current state by roughly half. CHANGELOG: fill in Unreleased for everything merged since #7423. The dominant theme is routing every operator-named auxiliary file open onto the ownership walk - upstream's open_no_attacker_symlinks() applied at the call sites upstream applies it - plus a daemon hardening batch and an alt-dest correctness batch. README and SECURITY: the per-leg outcome tables were re-derived from the committed expect manifests rather than carried forward. Failures fell and the corpus grew, so every figure moved: non-root pipe 43 -> 21 fail (345 -> 349 corpus) root pipe 62 -> 29 fail (345 -> 349 corpus) non-root tcp 42 -> 29 fail (155 -> 158 corpus) root tcp 55 -> 38 fail (155 -> 158 corpus) Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55 across all four. SECURITY, two CVE rows that had gone stale: - CVE-2026-53790 said "under audit". The refusal has since been applied at the live sink - oc-rsync's own single-character config expander, which upstream does not have, so an upstream-shaped port alone would have been inert (#7465, #7430, #7445). - CVE-2026-53795 listed only the staging family. The auxiliary-file family followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459, #7463); what remains is the per-option-family confinement.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…7465) * fix(daemon): refuse shell metacharacters in hook variable expansion A `%VAR%` reference expanded into a shell-executed hook directive is escaped for the quoting context it lands in, and refused outright when the value carries a character a shell could act on. Upstream applies this to the four `FN_LOCAL_STRING_SHELL` directives - `early exec`, `name converter`, `post-xfer exec`, `pre-xfer exec` (daemon-parm.h:349/363/365/366) - via expand_vars(str, shell_escape=1) at loadparm.c:237-325. Measured against real rsync 3.5.0 on Linux, upstream control run first: cell upstream 3.5.0 oc before daemon-exec-metachar-refused PASS FAIL daemon-exec-metachar-documented-limit PASS FAIL daemon-exec-second-shell-argument-injection PASS FAIL ⚠ THE EXPANSION LANGUAGES DIFFER, AND THAT IS THE ROOT CAUSE. Upstream expands only delimited `%NAME%` environment references, gated on an uppercase first letter plus a closing `%` (loadparm.c:250). oc's exec hooks were fed a DIFFERENT language: single-character escapes `%P %m %u %a %h %p`, which upstream does not have in config values at all - `%m` stays literal there. So `pre-xfer exec = ... %RSYNC_USER_NAME% ...` never substituted anything, and the cells failed on the POSITIVE control as much as on the refusal. Consequences that a shape-only port of upstream's guard would have missed: - The two languages COLLIDE. `%PATH%` reads as module-path + `ATH%` under the single-char rule and as getenv("PATH") upstream. They therefore cannot be layered as two passes - a value substituted by one would be rescanned by the other, which is its own injection. This is one walk, delimited names first, falling back to the single-char reading only when the candidate name is not well-formed, so `%P/%m` keeps working while `%PATH%` reads as upstream reads it. - `%u`, `%h` and `%a` substitute peer-influenced values (auth user, reverse-DNS hostname, peer address) into a shell command. Upstream has no such channel, so porting its guard alone would have left that hole open. They now take the same refusal as a `%RSYNC_*%` reference. - ⚠ Both the pre-xfer and post-xfer sites passed `username: ""` into the expansion, behind a comment presenting it as intentional. Resolving `%RSYNC_USER_NAME%` from that context yields empty, so the fix would have been INERT for the very cell it targets. Upstream sets RSYNC_USER_NAME to the authenticated user on the daemon process at clientserver.c:815, ahead of the hook retrieval at :959; both sites now do the same. Resolvable names are read from the connection context rather than the process environment, because oc sets the RSYNC_* variables on the hook CHILD while upstream sets them on the daemon process. `RSYNC_REQUEST` and `RSYNC_ARG<n>` are deliberately absent: upstream sets those inside the forked pre-exec child (clientserver.c:568), after the directive is already expanded, so they are not resolvable references on either implementation. Three false upstream citations removed. `clientserver.c - exec command strings support %P, %m, %u, %a, %h, %p` and the two claiming `log.c:lp_do_log_file()` expands single-character escapes in path contexts describe behaviour upstream does not have; they are why the divergence read as intentional. Residuals, filed rather than claimed: - Upstream expands all four directives together at clientserver.c:959-960, BEFORE the transfer, so a refusal aborts via exit_cleanup(RERR_UNSUPPORTED). oc expands per hook, so the post-xfer site can only decline to run the hook. Hoisting oc's expansion to the same point is the follow-up. - The refusal reaches the daemon log through rsync_error!, which adds the `(code N)` envelope; upstream's rprintf(FLOG, ...) is bare. - Whether oc's single-character escapes should exist in exec commands at all is a genuine question - they are redundant with the RSYNC_* environment the hook already receives, and they are the channel that needed the extra guard. * fix(daemon): log the hook refusal before writing to the peer By the time a hook runs the stream is already multiplexed, so the plain @error line can fail to land. Sending first meant the `?` propagated that failure and the refusal never reached the daemon log - the operator's only record of a fail-closed security decision, dropped silently. Measured: the transfer already failed (rc=23) but the daemon log carried no refusal line at all, so the testsuite cells still could not tell the guard from an unrelated startup failure - which is exactly what they assert. upstream: loadparm.c:270-273 emits the FLOG line and only then calls exit_cleanup(), so the order is upstream's, not an invention. * test(ci): record the three daemon-exec-metachar cells as passing Measured 3/3 GREEN against the fixed binary on Linux, upstream 3.5.0 control passing first. Row count unchanged at 345 on both pipe legs. * test(daemon): cover the shell-hook refusal and escape rules The two existing exec-command tests still compared the expansion against a &str after it started returning Result, so the daemon lib test target did not build and fmt+clippy failed before any other required check ran. Rewrite them against the new contract and add the coverage the change was missing: operator values stay verbatim, peer-influenced values are escaped for their quote context, the full refusal set fails closed, and the refusal names the token as written in the template. * test(ci): flip the metachar rows in the TCP expect manifests too The refusal is transport-independent - the daemon rejects the value while parsing the hook template, before any transfer - so all three cells pass over TCP exactly as they do over the pipe. Only the two pipe manifests were flipped, so both TCP legs saw an unexpected PASS and exited non-zero. Measured on both transports with the real 3.5.0 binary as the control: upstream PASS / oc PASS for all three. Row counts unchanged at 155 each.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…7477) The docs were last refreshed at #7423; 55 PRs have merged since, and the testsuite figures they quote had drifted far enough to understate the current state by roughly half. CHANGELOG: fill in Unreleased for everything merged since #7423. The dominant theme is routing every operator-named auxiliary file open onto the ownership walk - upstream's open_no_attacker_symlinks() applied at the call sites upstream applies it - plus a daemon hardening batch and an alt-dest correctness batch. README and SECURITY: the per-leg outcome tables were re-derived from the committed expect manifests rather than carried forward. Failures fell and the corpus grew, so every figure moved: non-root pipe 43 -> 21 fail (345 -> 349 corpus) root pipe 62 -> 29 fail (345 -> 349 corpus) non-root tcp 42 -> 29 fail (155 -> 158 corpus) root tcp 55 -> 38 fail (155 -> 158 corpus) Distinct divergences: 64 -> 31 across the two full-corpus legs, 89 -> 55 across all four. SECURITY, two CVE rows that had gone stale: - CVE-2026-53790 said "under audit". The refusal has since been applied at the live sink - oc-rsync's own single-character config expander, which upstream does not have, so an upstream-shaped port alone would have been inert (#7465, #7430, #7445). - CVE-2026-53795 listed only the staging family. The auxiliary-file family followed it onto the walk (#7421-#7426, #7439, #7441-#7443, #7459, #7463); what remains is the per-option-family confinement.
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
A
%VAR%reference expanded into a shell-executed daemon hook is now escaped for the quoting context it lands in, and refused outright when the value carries a character a shell could act on.Upstream applies this to the four
FN_LOCAL_STRING_SHELLdirectives -early exec,name converter,post-xfer exec,pre-xfer exec(daemon-parm.h:349/363/365/366) - throughexpand_vars(str, shell_escape=1)atloadparm.c:237-325. The rule is documented inrsyncd.conf.5.md:1163-1180, and the refusal exists because escaping is only correct for one level of shell parsing: a hook such assh -c '... %RSYNC_USER_NAME% ...'re-parses the word in a second shell that sees the value bare.Measured
Real rsync 3.5.0 vs
oc-rsyncon Linux (x86_64), upstream control run first in every case:daemon-exec-metachar-refuseddaemon-exec-metachar-documented-limitdaemon-exec-second-shell-argument-injectionFull nonroot pipe leg after the fix: 226 passed / 30 failed / 89 skipped = 345 rows.
⚠ The expansion languages differ, and that is the root cause
Upstream expands only delimited
%NAME%environment references, gated on an uppercase first letter plus a closing%(loadparm.c:250). oc's exec hooks were fed a different language: single-character escapes%P %m %u %a %h %p, which upstream does not have in config values at all -%mstays literal there.So
pre-xfer exec = ... %RSYNC_USER_NAME% ...never substituted anything. The cells failed on the positive control as much as on the refusal, which a shape-only port of upstream's guard would not have fixed.Three consequences that shaped the fix:
%PATH%reads as module-path +ATH%under the single-char rule and asgetenv("PATH")upstream. They cannot be layered as two passes - a value substituted by one would be rescanned by the other, which is its own injection. This is one walk, delimited names first, falling back to the single-char reading only when the candidate name is not well-formed, so%P/%mkeeps working while%PATH%reads as upstream reads it.%u,%h,%asubstitute peer-influenced values (auth user, reverse-DNS hostname, peer address) into a shell command. Upstream has no such channel, so porting its guard alone would have left that hole open. They now take the same refusal as a%RSYNC_*%reference.username: ""into the expansion, behind a comment presenting it as intentional. Resolving%RSYNC_USER_NAME%from that context yields empty - the fix would have been inert for the very cell it targets. Upstream setsRSYNC_USER_NAMEto the authenticated user on the daemon process atclientserver.c:815, ahead of the hook retrieval at:959; both sites now do the same.Resolvable names come from the connection context, not the process environment, because oc sets the
RSYNC_*variables on the hook child while upstream sets them on the daemon process.RSYNC_REQUESTandRSYNC_ARG<n>are deliberately absent: upstream sets those inside the forked pre-exec child (clientserver.c:568), after the directive is already expanded, so they are not resolvable on either implementation.⚠ The second commit is the one that made it work
The first commit refused correctly - the transfer failed with rc=23 - but the cells still failed. The refusal was written to the peer before being logged, and by the time a hook runs the stream is already multiplexed, so the plain
@ERRORline failed to land and?propagated that failure. The daemon log carried no record at all of a fail-closed security decision.Upstream logs first (
loadparm.c:270-273:rprintf(FLOG, ...)thenexit_cleanup()), so the order is upstream's, not an invention. Reading the actual daemon log is what found this - the first log I opened was a stale file from a different test's scratch dir, which showed nothing and would have sent me the wrong way.Three false upstream citations removed
clientserver.c - exec command strings support %P, %m, %u, %a, %h, %p, and two claiminglog.c:lp_do_log_file()expands single-character escapes in path contexts. Upstream does none of that. Those comments are why the divergence read as intentional.Regression check
The full nonroot leg reports 10 expected-result mismatches on this host. None are from this change -
daemon-exec, the only one in the blast radius, was A/B'd against the pre-change binary and fails identically on both. The rest are host-environment differences (skips for absent helper binaries, root-dependent symlink-race cells) against a manifest generated on GitHub Actions. CI is the authority.Residuals, filed rather than claimed
clientserver.c:959-960, before the transfer, so a refusal aborts viaexit_cleanup(RERR_UNSUPPORTED). oc expands per hook, so the post-xfer site can only decline to run the hook. Hoisting oc's expansion to the same point is the follow-up.rsync_error!, which adds the(code N)envelope; upstream'srprintf(FLOG, ...)is bare.RSYNC_*environment the hook already receives, they are the channel that needed the extra guard, and they are what collides with%NAME%. Removing them from exec commands would be the upstream-faithful choice, but it is a behaviour change for anyone using%min a hook, so I have not made it unilaterally.