Skip to content

Commit b9fba5f

Browse files
committed
fix(sandbox): inherit snapshot sandbox id in from_snapshot
from_snapshot() was constructing a fresh MultiUseSandbox via from_uninit(), which assigns a new monotonically-increasing sandbox id. The loaded snapshot still carries the id of the sandbox it was originally captured from, so the very first restore() call after from_snapshot trips SnapshotSandboxMismatch and aborts before any guest code runs. Conceptually the snapshot IS this sandbox's identity when loaded from disk — the sandbox it was captured from no longer exists. Inherit the snapshot's sandbox_id and register the loaded snapshot as this sandbox's active snapshot so subsequent restores match. Signed-off-by: danbugs <danilochiarlone@gmail.com>
1 parent 5ec0bfc commit b9fba5f

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/hyperlight_host/src/sandbox/initialized_multi_use.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,24 @@ impl MultiUseSandbox {
248248
#[cfg(gdb)]
249249
let dbg_mem_wrapper = Arc::new(Mutex::new(hshm.clone()));
250250

251-
Ok(MultiUseSandbox::from_uninit(
251+
// Inherit the snapshot's sandbox id, and treat the loaded
252+
// snapshot as this sandbox's active snapshot. Without this,
253+
// a caller who does `from_snapshot(s)` and then immediately
254+
// `restore(s)` hits `SnapshotSandboxMismatch`: the new
255+
// sandbox would get a fresh id from `from_uninit` while the
256+
// snapshot still carries the originating sandbox's id.
257+
// Conceptually the snapshot IS this sandbox's identity when
258+
// loaded from disk, so the ids should agree from the start.
259+
let mut sbox = MultiUseSandbox::from_uninit(
252260
host_funcs,
253261
hshm,
254262
vm,
255263
#[cfg(gdb)]
256264
dbg_mem_wrapper,
257-
))
265+
);
266+
sbox.id = snapshot.sandbox_id();
267+
sbox.snapshot = Some(snapshot.clone());
268+
Ok(sbox)
258269
}
259270

260271
/// Creates a snapshot of the sandbox's current memory state.

0 commit comments

Comments
 (0)