Repository navigation
Conversation
Keep asserted layer digests separate from computed or verified hashes. Ordinary load/save avoids rehashing trusted memory, while checked_save continues to verify and repair content. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Add load_overlay and checked_load_overlay methods that require a declared whole-snapshot base and reuse matching immutable layers. Persist snapshot IDs and inherit provenance through capture and compaction without retaining unused layers or adding memory-manager bookkeeping. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
There was a problem hiding this comment.
🟡 Changes recommended
Newly saved configs break compatibility with existing v6 readers, which reject the added provenance fields despite the unchanged media type and ABI.
3 open issues
What changed in this PR
This PR adds provenance-validated snapshot overlay loading to Hyperlight’s host snapshot APIs. Descendants can reuse immutable memory layers from a caller-authorized base while supplying their complete saved state.
Changes:
- Add ordinary and checked overlay loaders with provenance, digest, and geometry checks.
- Persist snapshot identities and ancestry through capture and compaction.
- Reuse declared digests on ordinary saves, with tests and documentation for verification and trust requirements.
| File | Description |
|---|---|
src/hyperlight_host/src/sandbox/snapshot/mod.rs |
Inherit base provenance during capture. |
src/hyperlight_host/src/sandbox/snapshot/memory/mod.rs |
Store snapshot IDs, ancestors, and declared digests. |
src/hyperlight_host/src/sandbox/snapshot/memory/backing.rs |
Expose backing snapshot memory for provenance inheritance. |
src/hyperlight_host/src/sandbox/snapshot/file/mod.rs |
Implement overlay loading and declared-digest reuse. |
src/hyperlight_host/src/sandbox/snapshot/file/config.rs |
Serialize and validate provenance fields. |
src/hyperlight_host/src/sandbox/snapshot/file_tests.rs |
Cover provenance, layer sharing, verification, and legacy loading. |
src/hyperlight_host/src/sandbox/snapshot/compact.rs |
Preserve ancestry and record explicit compaction bases. |
docs/snapshot-oci-format.md |
Describe overlay semantics and trust requirements. |
CHANGELOG.md |
Document the public APIs and save behavior. |
Review effort: Balanced
Emit config v7 with explicit loader dispatch and require its snapshot ID. Keep strict v6 loading without provenance, update schema and ABI tripwires, and cover legacy and mislabeled layouts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Clear base provenance when compacting without a base. With a base, replace target ancestry with that base inherited list and ID. Copy the validated ordered list directly instead of quadratic membership scans, and cover config-limit recovery and repeated checkpoint cycles. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
This comment has been minimized.
This comment has been minimized.
Drop the derived snapshot as well as the trusted base before shortening their shared blob. Windows rejects truncation while either snapshot retains the mapped section. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Benchmark ResultsMeasured commit: kvm / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
kvm / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / amd (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
mshv3 / intel (Linux) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / amd (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
hyperv-ws2025 / intel (Windows) (➖ stable)No benchmark improved or regressed. Benchmark Resultsfunction_call_codec
payload_allocation
sandboxes
slot_pool
snapshot_files
virtq_readonly
virtq_readwrite
Reported by |
yoshuawuyts
left a comment
There was a problem hiding this comment.
Thanks for filing this @jprendes! - I'm not yet in a position where I can review the correctness of the implementation, so I will defer that to someone else. But I took a pass on reviewing the actual code and read the PR line by line, and I hope that's helpful too.
| #[serde(default, skip_serializing_if = "Option::is_none")] | ||
| pub(super) snapshot_id: Option<String>, | ||
| #[serde(default, skip_serializing_if = "Vec::is_empty")] | ||
| pub(super) bases: Vec<String>, |
There was a problem hiding this comment.
These fields should probably carry comments
| if id.is_nil() { | ||
| return Err(crate::new_error!("snapshot provenance ID must not be nil")); | ||
| } | ||
| if !ids.insert(id) { | ||
| return Err(crate::new_error!("duplicate snapshot provenance ID")); | ||
| } |
There was a problem hiding this comment.
Not necessarily in scope for this PR, but it sure would be nice if we had an ensure! macro for this. See: Domain-specific error macros - Yosh Wuyts.
| let digest = if verify_blobs { | ||
| Digest256::from_bytes(bytes) | ||
| } else if let Some(hex) = blob.sha256.get().or(blob.declared_sha256.as_ref()) { | ||
| Digest256 { hex: hex.clone() } | ||
| } else { | ||
| let hex = blob.sha256.get_or_init(|| Digest256::from_bytes(bytes).hex); | ||
| Digest256 { hex: hex.clone() } | ||
| }; |
There was a problem hiding this comment.
Nit: the control-flow here feels a bit messy to me. I think it's the branching on the boolean param that feels off to me in the first place, and now we're changing that somewhat by adding an intermediate fallback that checks two fields. Maybe it's not worth addressing here and now, but I wanted to at least flag it.
| }; | ||
| layout.set_code_gva(code_gva)?; | ||
| layout.ensure_page_tables_fit(cfg.layers[cfg.page_table_layer].page_table_len)?; | ||
| if base.is_some_and(|base| base.state.layout != layout) { |
There was a problem hiding this comment.
Entirely optional/stylistic: I didn't know what is_some_and did so it took me a little longer to read this than I would have liked to. I think that now that Rust has if-let chaining we can rewrite this using language features instead.
| if base.is_some_and(|base| base.state.layout != layout) { | |
| if let Some(base) && base.state.layout != layout { |
Imo the right direction for Rust would probably be to consider deprecating the is_some_and combinator now that it's directly part of the language, and point people to use the language feature instead. But that's something for me to bring up there I think.
| #[test] | ||
| fn load_accepts_wrong_content_digest_but_rejects_wrong_size() { | ||
| let snapshot = create_snapshot(); | ||
| let dir = tempfile::tempdir().unwrap(); | ||
| let tag = OciTag::new("latest").unwrap(); | ||
| snapshot.save(dir.path(), &tag).unwrap(); | ||
| let path = find_snapshot_blob(dir.path()); | ||
| let mut bytes = std::fs::read(&path).unwrap(); | ||
| bytes[0] ^= 1; | ||
| std::fs::write(&path, &bytes).unwrap(); | ||
| assert!(Snapshot::checked_load(dir.path(), tag.clone()).is_err()); | ||
| let trusted = Snapshot::load(dir.path(), tag.clone()).unwrap(); | ||
| let derived = snapshot_with_shared_blobs(&trusted, Some(&trusted)); | ||
| let derived_dir = tempfile::tempdir().unwrap(); | ||
| derived.save(derived_dir.path(), &tag).unwrap(); | ||
| assert!( | ||
| trusted | ||
| .checked_load_overlay(derived_dir.path(), tag.clone()) | ||
| .is_err() | ||
| ); | ||
| let output = tempfile::tempdir().unwrap(); | ||
| trusted.save(output.path(), &tag).unwrap(); | ||
| assert!(Snapshot::checked_load(output.path(), tag.clone()).is_err()); | ||
| trusted.checked_save(output.path(), &tag).unwrap(); | ||
| Snapshot::checked_load(output.path(), tag.clone()).unwrap(); | ||
| drop(derived); | ||
| drop(trusted); | ||
| bytes.pop(); | ||
| std::fs::write(path, bytes).unwrap(); | ||
| assert!(Snapshot::load(dir.path(), tag).is_err()); | ||
| } |
There was a problem hiding this comment.
I know it's not the existing norm in the Hyperlight tests here, but I'm struggling a little to read the tests checked into this file. There clearly seems to be a setup phase and testing phase, but I don't actually know what operations we're performing or which conditions we're testing.
Some light use of comments and newlines within the tests themselves feels like it would make it easier to follow the intent behind the tests. Which at least would help me as I'm trying to better understand the codebase.


Summary
Add explicit, provenance-validated loading of snapshot descendants while reusing immutable memory layers from a caller-authorized base.
Atomic commits
Semantics and trust
Validation
Review follow-ups
compact(None)clears provenance.compact(Some(base))replaces the target's history with the selected base's inherited list plus its ID. This provides an explicit reset while retaining a caller-selected base, rather than silently imposing an ancestry cap.