| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
import os |
| 21 |
import subprocess |
| 22 |
|
| 23 |
from rsyncfns import ( |
| 24 |
SCRATCHDIR, find_attacker_uid, rmtree, rsync_argv, start_test_daemon, |
| 25 |
test_fail, test_skipped, write_daemon_conf, |
| 26 |
) |
| 27 |
|
| 28 |
DAEMON_PORT = 12901 |
| 29 |
CANARY = "audit_daemon_optout_canary" |
| 30 |
|
| 31 |
if os.geteuid() != 0: |
| 32 |
test_skipped("requires root to plant a symlink owned by a non-self uid") |
| 33 |
ATT = find_attacker_uid() |
| 34 |
if ATT is None: |
| 35 |
test_skipped("no untrusted-uid user available for cross-uid plant") |
| 36 |
|
| 37 |
base = SCRATCHDIR / 'daemonoptout' |
| 38 |
rmtree(base) |
| 39 |
base.mkdir() |
| 40 |
escape_target = base / 'escape_target' |
| 41 |
escape_target.mkdir() |
| 42 |
(escape_target / CANARY).write_text("must-not-be-served\n") |
| 43 |
|
| 44 |
plant = base / 'plant' |
| 45 |
os.symlink(escape_target, plant) |
| 46 |
os.lchown(plant, ATT, ATT) |
| 47 |
|
| 48 |
conf = write_daemon_conf([('mod', {'path': plant, 'read only': 'yes'})]) |
| 49 |
url = start_test_daemon(conf, DAEMON_PORT) |
| 50 |
|
| 51 |
|
| 52 |
proc = subprocess.run( |
| 53 |
rsync_argv('-M--insecure-links', f'{url}mod/'), |
| 54 |
stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) |
| 55 |
|
| 56 |
if CANARY in proc.stdout: |
| 57 |
test_fail( |
| 58 |
"the daemon honored a peer-forwarded --insecure-links and disabled its " |
| 59 |
f"module-chdir confinement: the foreign-owned symlink {plant} -> " |
| 60 |
f"{escape_target} was followed (canary {CANARY!r} in the listing). A " |
| 61 |
"daemon must never let a client switch off its symlink confinement; the " |
| 62 |
"opt-out must be gated on !am_daemon, not bare insecure_links.") |
| 63 |
print("daemon ignores peer-forwarded --insecure-links: confinement held") |