Skip to content

openvmm: nonregular paired scratch is accepted before a resume generation can be consumed #1157

Closed

Description

@tangruize

A paired scratch.img that is a directory, symlink or special file can pass initial snapshot opening. Restore preparation can then consume the single-use resume claim before scratch access fails, making the generation unavailable for another restore attempt.

In openvmm/openvmm_helpers/src/snapshot/restore.rs, OpenedSnapshot::open opens the three primary artifacts but only checks directory contents for paired scratch:

        let directory = OpenedSnapshotDirectory::open(dir)?;
        let manifest_file = directory.open_regular_file(MANIFEST_FILE_NAME, "snapshot manifest")?;
        let state_file = directory.open_regular_file(STATE_FILE_NAME, "saved state")?;
        let memory_file = directory.open_regular_file(MEMORY_FILE_NAME, "snapshot memory")?;
        let manifest = decode_snapshot_manifest(&manifest_file)?;
        validate_snapshot_directory(&directory, &manifest)?;

validate_snapshot_directory verifies that the expected scratch name is present, not that it identifies a regular file. The scratch opener is reached later, after the snapshot has already been accepted.

Trigger

Publish a paired-scratch resume snapshot, replace scratch.img with a directory, and open the snapshot. Opening succeeds; subsequent preparation can create the resume claim before failing to open or materialize scratch.

Fix

When the manifest declares paired scratch, validate it through the retained directory's regular-file opener before OpenedSnapshot::open succeeds.

This moves type rejection ahead of the resume claim. Writerless FIFO liveness also requires the separate nonblocking-open change: a type check after a blocking open cannot reject a FIFO until that open returns.

Activity

  1. tangruize commented on Nov 1, 2026

    @tangruize
    ContributorAuthor

    Proposed patch

    Patch against OpenVMM 998b9f2402050cd16d1faa897bc831ef1434be48. Save the contents below as fix.patch and run git apply fix.patch.

    fix.patch
    diff --git a/openvmm/openvmm_helpers/src/snapshot/restore.rs b/openvmm/openvmm_helpers/src/snapshot/restore.rs
    index 5b9b05e25..773819afb 100644
    --- a/openvmm/openvmm_helpers/src/snapshot/restore.rs
    +++ b/openvmm/openvmm_helpers/src/snapshot/restore.rs
    @@ -57,6 +57,9 @@ pub fn open(dir: &Path) -> anyhow::Result<Self> {
             let memory_file = directory.open_regular_file(MEMORY_FILE_NAME, "snapshot memory")?;
             let manifest = decode_snapshot_manifest(&manifest_file)?;
             validate_snapshot_directory(&directory, &manifest)?;
    +        if microvm::paired_scratch_block(&manifest).is_some() {
    +            directory.open_regular_file(SCRATCH_FILE_NAME, "paired scratch")?;
    +        }
             anyhow::ensure!(
                 manifest.state_size_bytes <= MAX_SAVED_STATE_SIZE_BYTES,
                 "state.bin length in the manifest exceeds the maximum size of \
    @@ -501,7 +504,6 @@ mod tests {
         use super::super::microvm::paired_scratch_manifest;
         use super::super::microvm::test_machine_contract;
         use super::super::publish::write_snapshot;
    -    #[cfg(target_os = "linux")]
         use super::super::publish::write_snapshot_from_memory_and_scratch_files;
         use super::super::tests::test_manifest;
         use super::*;
    @@ -515,6 +517,40 @@ mod tests {
         #[cfg(any(target_os = "linux", windows))]
         use std::io::Write;
     
    +    #[test]
    +    fn snapshot_open_rejects_nonregular_paired_scratch_before_claim() {
    +        let scratch = vec![0x5a; 512];
    +        let mut manifest = paired_scratch_manifest(&scratch);
    +        manifest.snapshot_tier = SNAPSHOT_TIER_INSTANCE_CHECKPOINT.to_owned();
    +        manifest.restore_policy = SNAPSHOT_RESTORE_POLICY_RESUME.to_owned();
    +        manifest
    +            .machine_contract
    +            .as_mut()
    +            .unwrap()
    +            .set_effective_command_line(
    +                "console=hvc0 nvx_snapshot_tier=instance-checkpoint".to_owned(),
    +            );
    +        let dir = tempfile::tempdir().unwrap();
    +        let destination = dir.path().join("snapshot");
    +        let memory_path = dir.path().join("memory.bin");
    +        let source_scratch = dir.path().join("scratch.img");
    +        std::fs::write(&memory_path, vec![0; 1024]).unwrap();
    +        std::fs::write(&source_scratch, &scratch).unwrap();
    +        write_snapshot_from_memory_and_scratch_files(
    +            &destination,
    +            &manifest,
    +            b"state",
    +            &std::fs::File::open(memory_path).unwrap(),
    +            Some(&std::fs::File::open(source_scratch).unwrap()),
    +        )
    +        .unwrap();
    +        let scratch_path = destination.join(SCRATCH_FILE_NAME);
    +        std::fs::remove_file(&scratch_path).unwrap();
    +        std::fs::create_dir(&scratch_path).unwrap();
    +        assert!(OpenedSnapshot::open(&destination).is_err());
    +        assert!(!destination.join(RESUME_CLAIM_FILE_NAME).exists());
    +    }
    +
         #[cfg(target_os = "linux")]
         #[test]
         fn copy_on_write_scratch_clone_is_independent() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions