| 1 | #!/usr/bin/env python3 |
| 2 | # A /./ inner-module chroot daemon must not use an out-of-inner-module file as a |
| 3 | # --copy-dest basis (here reached via inner/linkparent -> ../outside). |
| 4 | # |
| 5 | # Detection is CONTENT-based, not atime-based: poison outside/f with distinct |
| 6 | # content but an identical size+mtime, so the --copy-dest size+mtime quick-check |
| 7 | # would still accept it if confinement were bypassed -- and copy_file() would then |
| 8 | # copy the poison bytes into dest. If the confinement holds, the basis is refused |
| 9 | # and dest is transferred from src. (The previous atime oracle false-positived on |
| 10 | # macOS: Spotlight, mds/mdworker_shared, indexes the freshly-created scratch files |
| 11 | # and reads outside/f, advancing its atime independently of rsync. Any external |
| 12 | # reader -- indexer, AV, backup -- defeats an atime signal; content does not.) |
| 13 | |
| 14 | import os |
| 15 | import shutil |
| 16 | |
| 17 | from rsyncfns import run_checked, setup_chroot_inner |
| 18 | from rsyncfns import makepath, rsync_argv, test_fail |
| 19 | |
| 20 | base, inner, outside, src, url = setup_chroot_inner('chroot-copydest-inner') |
| 21 | makepath(inner / 'dest') |
| 22 | (src / 'f').write_text('same\n') # 5 bytes |
| 23 | shutil.copy2(src / 'f', outside / 'f') # same size + mtime as src/f |
| 24 | (outside / 'f').write_text('PWND\n') # distinct content, same 5 bytes |
| 25 | src_mtime = (src / 'f').stat().st_mtime |
| 26 | os.utime(outside / 'f', (src_mtime, src_mtime)) # restore mtime for the quick-check |
| 27 | |
| 28 | proc, out = run_checked(rsync_argv('-a', '--copy-dest=../linkparent', f'{src}/', f'{url}mod/dest/')) |
| 29 | dest = inner / 'dest' / 'f' |
| 30 | if not dest.exists(): |
| 31 | test_fail(f"copy-dest transfer did not create destination file:\n{out}") |
| 32 | # A real escape copies the out-of-module basis content into dest; a confined |
| 33 | # daemon transfers from src instead. |
| 34 | if dest.read_text() != (src / 'f').read_text(): |
| 35 | test_fail("copy-dest read an outside-inner-module basis file: dest got the " |
| 36 | f"out-of-module content {dest.read_text()!r}:\n{out}") |
| 37 | print("chroot-copy-dest-inner-module: outside copy-dest basis was not read") |