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
7 changes: 4 additions & 3 deletions doc/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -1486,9 +1486,10 @@ otherwise read or change: `provision` refuses a share whose resolved host path
equals, contains, or lies inside the sandbox's state directory, its image, its
scratch image, or the OpenVMM, kernel, or initramfs of the artifact root, or
the OpenVMM that `NVX_OPENVMM` names, before it records the sandbox, and
`start` refuses one again before it launches the VM. The `start` of a restored
sandbox also refuses a share that reaches its snapshot store, whose files the
view of each restore links, before it takes the snapshot's lock.
`start` refuses one again before it launches the VM. A restored sandbox also
refuses a share that reaches its snapshot store, whose files the view of each
restore links: the provision of `snapshot restore` before it records the
sandbox, and each `start` before it takes the snapshot's lock.
`start` resolves the recorded host paths again, so a share that came to reach
one of these files through a link since `provision` is refused too. A
`provision` that finds no artifact root leaves the artifacts to `start`. A
Expand Down
49 changes: 49 additions & 0 deletions nvx/src/host/cli/sandbox/lifecycle/start/tests/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,55 @@ fn snapshot_restore_records_its_source_and_starts_a_restore_of_it() {
assert!(!state.exists());
}

/// `snapshot restore` refuses a share that reaches its snapshot store, whose files the view of
/// each restore links, as every start of its sandbox would refuse it: before it records the
/// sandbox, so that no provisioned sandbox stays behind, which a corrected restore into the same
/// state directory would find provisioned.
#[test]
fn snapshot_restore_refuses_a_share_of_its_snapshot_store_before_it_provisions() {
let fixture = Fixture::new(false);
let root = artifact_root(&fixture.state("checkout"));
let layer = fixture.state("distro.erofs");
fs::write(&layer, "distro").unwrap();
let store = fixture.root.path().join("store");
let state = fixture.state("command");
// The store itself, and a directory inside it.
for shared in [store.clone(), store.join("snapshots")] {
let arguments = [
"restore",
"source",
"--store-dir",
store.to_str().unwrap(),
"--state-dir",
state.to_str().unwrap(),
"--layer",
&format!(
"distro,{},11111111-1111-1111-1111-111111111111",
layer.display()
),
"--upper",
"ram",
"--hypervisor",
if cfg!(windows) { "whp" } else { "kvm" },
"--mount",
&format!("/data,{},ro", shared.display()),
]
.map(str::to_owned);
let (command, unrecognized) = snapshots::parse(&arguments).unwrap();
assert!(unrecognized.is_empty(), "{unrecognized:?}");
let error = snapshots::run(Some(&root), command).unwrap_err();
assert_eq!(error.code(), Some(ErrorCode::Unsupported), "{error:?}");
let message = error.message().unwrap_or_default();
assert!(
message.contains("overlaps the sandbox's snapshot store"),
"{message}"
);
assert!(!state.exists(), "{}", shared.display());
}
assert!(fixture.snapshot_free());
assert!(fixture.spawned().is_empty());
}

/// `snapshot restore` refuses a hypervisor that this host's operating system cannot run, which
/// every start of its sandbox would fail on, before it opens the store or locks the snapshot, so
/// that it reports that refusal and leaves the store as it was, whatever the snapshot.
Expand Down
11 changes: 11 additions & 0 deletions nvx/src/host/cli/sandbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,17 @@ fn run_from(root: Option<&str>, options: Options, source: Option<&Source>) -> Re
export.as_ref().map(|export| &export.description),
located.as_ref(),
)?;
// The view of each restore links the snapshot's files, which a share of the store
// would give the guest to change, so every start of a restored sandbox refuses it.
if let Some(source) = source {
refuse_own_files(
Some(("snapshot store", &source.store)),
layer.path(),
scratch.as_deref(),
export.as_ref().map(|export| &export.description),
None,
)?;
}
lifecycle::provision(
state_dir,
&layer,
Expand Down
Loading