Skip to content

openvmm: a writerless FIFO snapshot artifact hangs restore before validation #1154

Closed

Description

@tangruize

A FIFO substituted for a snapshot artifact can block restore indefinitely. The regular-file check occurs only after an open that waits for a writer.

In openvmm/openvmm_helpers/src/snapshot/fs.rs, OpenedSnapshotDirectory::open_regular_file opens Linux entries without nonblocking mode:

            let fd = nix::fcntl::openat(
                &self.file,
                name,
                OFlag::O_RDONLY | OFlag::O_CLOEXEC | OFlag::O_NOFOLLOW,
                Mode::empty(),
            )
            .map_err(nix_error)
            .with_context(|| {
                format!(
                    "failed to open {description} at {}",
                    self.display_path(name).display()
                )
            })?;

O_NOFOLLOW prevents following a symlink, but does not prevent opening a FIFO. A read-only FIFO open waits until a writer appears, so execution never reaches validate_opened_regular_file. The path-based Unix regular-file opener has the same problem. Length-checked and paired-scratch access also use these helpers.

Trigger

Place a FIFO with no writer at manifest.bin, state.bin or memory.bin, then request restore. Opening the substituted artifact hangs rather than rejecting it as nonregular.

Fix

Add O_NONBLOCK to directory-relative Linux opens and path-based Unix opens, retaining O_NOFOLLOW and the existing handle-based regular-file validation. The FIFO open then returns without waiting and its type is rejected. Nonblocking mode does not alter regular-file I/O.

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/fs.rs b/openvmm/openvmm_helpers/src/snapshot/fs.rs
    index 03ba222c2..56c853b3b 100644
    --- a/openvmm/openvmm_helpers/src/snapshot/fs.rs
    +++ b/openvmm/openvmm_helpers/src/snapshot/fs.rs
    @@ -769,7 +769,7 @@ pub(super) fn open_regular_file(
                 let fd = nix::fcntl::openat(
                     &self.file,
                     name,
    -                OFlag::O_RDONLY | OFlag::O_CLOEXEC | OFlag::O_NOFOLLOW,
    +                OFlag::O_RDONLY | OFlag::O_CLOEXEC | OFlag::O_NOFOLLOW | OFlag::O_NONBLOCK,
                     Mode::empty(),
                 )
                 .map_err(nix_error)
    @@ -953,7 +953,7 @@ fn open_regular_file_impl(path: &Path, description: &str) -> anyhow::Result<std:
         #[cfg(unix)]
         {
             use std::os::unix::fs::OpenOptionsExt;
    -        options.custom_flags(libc::O_CLOEXEC | libc::O_NOFOLLOW);
    +        options.custom_flags(libc::O_CLOEXEC | libc::O_NOFOLLOW | libc::O_NONBLOCK);
         }
         #[cfg(windows)]
         {
    @@ -1215,6 +1215,26 @@ pub(super) fn sync_directory(_path: &Path) -> anyhow::Result<()> {
     mod tests {
         use super::*;
     
    +    #[test]
    +    fn regular_file_open_rejects_fifo_without_a_writer() {
    +        let dir = tempfile::tempdir().unwrap();
    +        let path = dir.path().join("manifest.bin");
    +        nix::unistd::mkfifo(&path, nix::sys::stat::Mode::S_IRUSR).unwrap();
    +        let directory = OpenedSnapshotDirectory::open(dir.path()).unwrap();
    +        for result in [
    +            directory.open_regular_file("manifest.bin", "manifest"),
    +            open_regular_file(&path, "manifest"),
    +            directory.open_file_with_length("manifest.bin", 0, "manifest"),
    +        ] {
    +            assert!(
    +                result
    +                    .unwrap_err()
    +                    .to_string()
    +                    .contains("not a regular file")
    +            );
    +        }
    +    }
    +
         #[test]
         fn sparse_copy_fallbacks_preserve_extents_and_clone_independence() {
             const MEMORY_SIZE: u64 = 16 * 1024 * 1024;
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

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions