| 1 |
|
| 2 |
"""A daemon must confine a client's --link-dest/--compare-dest/--copy-dest basis |
| 3 |
dir to the served module (Leonid Bugaev May-2026 re-audit, KI-48 / CVE-53795 |
| 4 |
surface; defense-in-depth guard). |
| 5 |
|
| 6 |
basis_link_stat() joins the peer-supplied basis dir with each fname and stats it. |
| 7 |
A client sending --link-dest=../<sibling> (or an absolute path) must NOT make the |
| 8 |
daemon stat files outside the module -- that would be an existence/size/mode |
| 9 |
oracle for out-of-tree paths, even though CVE-53795 already refuses the |
| 10 |
cross-boundary hardlink itself. |
| 11 |
|
| 12 |
The daemon already clamps such a path to the module root (longstanding sanitize |
| 13 |
behavior, preserved through this branch's d33e599c path-confinement rework -- the |
| 14 |
audit's "runtime-confirmed" KI-48 was a *local* receiver, where --link-dest=.. |
| 15 |
is the operator's own intended choice, not a boundary crossing). This test locks |
| 16 |
that confinement in: it pushes with --link-dest=../<sibling> where <sibling> is a |
| 17 |
real dir next to the module root; the daemon reports "link-dest arg does not |
| 18 |
exist" (to the client, via -v) only when it could NOT reach the dir, so reaching |
| 19 |
the real out-of-tree dir (no warning) would be a regression/leak. |
| 20 |
""" |
| 21 |
|
| 22 |
import os |
| 23 |
import subprocess |
| 24 |
|
| 25 |
from rsyncfns import ( |
| 26 |
SCRATCHDIR, makepath, rmtree, rsync_argv, start_test_daemon, test_fail, |
| 27 |
write_daemon_conf, |
| 28 |
) |
| 29 |
|
| 30 |
DAEMON_PORT = 12894 |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
base = SCRATCHDIR / 'kid48' |
| 35 |
rmtree(base) |
| 36 |
mod = base / 'mod' |
| 37 |
sibling = base / 'sibling' |
| 38 |
makepath(mod) |
| 39 |
makepath(sibling) |
| 40 |
(sibling / 'probe').write_text('out-of-tree basis content\n') |
| 41 |
|
| 42 |
|
| 43 |
src = base / 'src' |
| 44 |
makepath(src) |
| 45 |
(src / 'probe').write_text('client content\n') |
| 46 |
|
| 47 |
conf = write_daemon_conf([ |
| 48 |
('mod', {'path': str(mod), 'read only': 'no'}), |
| 49 |
]) |
| 50 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 51 |
|
| 52 |
|
| 53 |
proc = subprocess.run( |
| 54 |
rsync_argv('-rv', '--link-dest=../sibling', f'{src}/', f'{url}mod/'), |
| 55 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True) |
| 56 |
out = proc.stdout or '' |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
reached_outside = 'does not exist' not in out and 'is not a dir' not in out |
| 64 |
|
| 65 |
if reached_outside: |
| 66 |
test_fail( |
| 67 |
"daemon reached outside the module via --link-dest=../sibling: the " |
| 68 |
"out-of-tree directory was stat'd (no 'arg does not exist' warning), " |
| 69 |
"leaking the existence of paths outside the module.\n--- client saw ---\n" |
| 70 |
+ out) |
| 71 |
|
| 72 |
print("daemon-link-dest-escape: --link-dest=../sibling was confined to the " |
| 73 |
"module (out-of-tree basis dir not reachable)") |