Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,296 changes: 1,217 additions & 1,079 deletions doc/openvmm-upstream-roadmap.md

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions nvx-rs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,11 @@ capture, at most `MAX_MANIFEST_LEN` bytes of a regular file that is not a link
or other reparse point, and refuses another snapshot format version, an unknown,
mistyped, or repeated field, truncated bytes, and a capture that is not a
template's: a platform-tier capture for clones, with a read-only `distro` whose
identity is unbound, a fresh scratch, and the dormant filesystem slot. The
restores of [`run`](#run) read the host attachments of the machine contract of
any microVM snapshot's manifest through the same reader, with every check but
those that make a manifest a template's.
identity is unbound, a fresh scratch, and the dormant filesystem slot. Of the
snapshot ID that OpenVMM's SaveVM records, which a microVM capture leaves zero,
it checks only the length. The restores of [`run`](#run) read the host
attachments of the machine contract of any microVM snapshot's manifest through
the same reader, with every check but those that make a manifest a template's.

`CaptureClass` holds the invariant inputs of a capture, known before it: the
runtime, the guest's build, the backend, the requested CPU profile, the
Expand Down
17 changes: 15 additions & 2 deletions nvx-rs/src/host/template/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ const SHA256_LEN: usize = 32;
/// Bytes of a host or boot identity.
const HOST_IDENTITY_LEN: usize = 16;

/// Bytes of a snapshot ID, a GUID.
const SNAPSHOT_ID_LEN: usize = 16;

/// Nanoseconds in a second.
const NANOS_PER_SECOND: i32 = 1_000_000_000;

Expand Down Expand Up @@ -663,7 +666,8 @@ impl Machine {
/// format does not have, a field that is not of its type or that appears twice, truncated bytes,
/// and a manifest that is not a template's: a platform-tier capture of a microVM, for clones, with
/// a read-only `distro` whose identity is unbound, a fresh scratch, and the dormant filesystem
/// slot. It never reads another artifact of the snapshot.
/// slot. Of the snapshot ID in field 18, which OpenVMM's SaveVM records and a microVM capture
/// leaves zero, it checks only the length. It never reads another artifact of the snapshot.
///
/// A template's [`TemplateKey`](super::TemplateKey) projects its machine. The rest is the
/// capture's own: when it was taken, its [`TimeContract`]'s anchor, host, boot, and lineage
Expand Down Expand Up @@ -1019,7 +1023,7 @@ fn decode_manifest(data: &[u8]) -> Result<RawManifest, String> {
decode(
data,
what,
&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 18],
&[],
|field| {
match field.number {
Expand All @@ -1042,6 +1046,15 @@ fn decode_manifest(data: &[u8]) -> Result<RawManifest, String> {
13 => raw.tier = field.text().map_err(&wire)?.to_owned(),
14 => raw.restore_policy = field.text().map_err(&wire)?.to_owned(),
15 => raw.consumed_sections = field.uint32().map_err(&wire)?,
18 => {
let id = field.bytes().map_err(&wire)?;
if id.len() != SNAPSHOT_ID_LEN {
return Err(format!(
"{what} has a snapshot ID of {} bytes, not {SNAPSHOT_ID_LEN}",
id.len()
));
}
}
_ => unreachable!("the message refuses unknown fields"),
}
Ok(())
Expand Down
31 changes: 29 additions & 2 deletions nvx-rs/src/host/template/manifest/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ fn other_versions_of_the_format_are_unsupported() {
#[test]
fn fields_that_the_format_does_not_have_are_refused() {
let template = ManifestSpec::template();
// Fields 16 and later do not exist yet.
for number in [16, 17, 18, 63, 64, 1000] {
// Fields 16 and 17, and 19 and later, do not exist yet.
for number in [16, 17, 19, 20, 63, 64, 1000] {
let message = refusal(
&template.encode_with(Proto::default().varint(number, 1)),
ErrorCode::Io,
Expand Down Expand Up @@ -369,6 +369,25 @@ fn fields_that_the_format_does_not_have_are_refused() {
);
}

#[test]
fn only_the_length_of_the_snapshot_id_is_checked() {
// A manifest of an earlier OpenVMM has no snapshot ID, and one that SaveVM wrote has one
// that is not zero.
let template = parse(&ManifestSpec::template());
for snapshot_id in [None, Some(vec![0xa5; 16])] {
let mut spec = ManifestSpec::template();
spec.snapshot_id = snapshot_id;
assert_eq!(parse(&spec), template);
}
for len in [0, 15, 17] {
assert_refused(
|spec| spec.snapshot_id = Some(vec![0; len]),
ErrorCode::Io,
&format!("it has a snapshot ID of {len} bytes, not 16"),
);
}
}

#[test]
fn malformed_manifests_are_refused() {
let template = ManifestSpec::template();
Expand Down Expand Up @@ -427,7 +446,15 @@ fn malformed_manifests_are_refused() {
#[test]
fn truncated_manifests_are_refused() {
let bytes = ManifestSpec::template().encode();
// The snapshot ID comes last, so the manifest without it, one of an earlier OpenVMM, is the one
// prefix that is whole.
let mut earlier = ManifestSpec::template();
earlier.snapshot_id = None;
let earlier = earlier.encode();
for len in 0..bytes.len() {
if bytes[..len] == earlier[..] {
continue;
}
let error =
TemplateManifest::parse(&bytes[..len]).expect_err("a truncated manifest is refused");
// A manifest that ends between its fields lacks some, such as its format magic.
Expand Down
14 changes: 10 additions & 4 deletions nvx-rs/src/host/template/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,8 @@ pub(super) struct ManifestSpec {
pub(super) restore_policy: String,
/// Field 17.
pub(super) consumed_sections: u32,
/// Field 18: the snapshot ID, which a microVM capture leaves zero, if it is written.
pub(super) snapshot_id: Option<Vec<u8>>,
}

/// The kernel command line of the template of [`ManifestSpec::template`].
Expand Down Expand Up @@ -817,6 +819,7 @@ impl ManifestSpec {
tier: "platform".to_owned(),
restore_policy: "clone".to_owned(),
consumed_sections: 1,
snapshot_id: Some(vec![0; 16]),
}
}

Expand Down Expand Up @@ -929,15 +932,18 @@ impl ManifestSpec {
if let Some(contract) = &self.contract {
message = message.message(9, contract.encode());
}
message
message = message
.bytes(10, &self.magic)
.varint(11, self.schema_version.into())
.text(12, &self.root_type)
.text(13, &self.tier)
.text(14, &self.restore_policy)
.varint(15, self.consumed_sections.into())
.raw(&extra.finish())
.finish()
.varint(15, self.consumed_sections.into());
// `mesh` writes the snapshot ID, a fixed-size value, even when it is zero.
if let Some(snapshot_id) = &self.snapshot_id {
message = message.always_bytes(18, snapshot_id);
}
message.raw(&extra.finish()).finish()
}

/// Encodes the manifest.
Expand Down
2 changes: 1 addition & 1 deletion openvmm
Submodule openvmm updated 176 files
Loading