openvmm: virtiofs: non-exclusive FUSE_CREATE on an existing file bypasses read-only alias checks and truncates protected hard links

Open
#1,602 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

Start in vm/devices/virtio/virtiofs/src/lib.rs: compare VirtioFs::create (~lines 290-315) with VirtioFs::open (276-287) and check_open_readonly (670-700), then read VirtioFsInode::create in src/inode.rs (327-345) and policy_permits_writes in src/microvm/inode.rs (169-179). The gap is that create checks only the parent and target path, while dedup onto an existing inode happens after the host open syscall. Done means a non-exclusive FUSE_CREATE on an existing hard-linked inode with a read-only alias fails with EROFS before the host open, with a test mirroring the five reproduction steps.

Written by the indexing model from the issue text.

Description

Summary

VirtioFs::create checks writability only on the parent directory and the single child path (check_writable and check_writable_entry) before calling self.volume.open(&path, open_options | lx::O_CREAT, ...), without checking whether path already resolves to a held VirtioFsInode that is read-only through another hard-link alias. As a result, while FUSE_OPEN with O_WRONLY | O_TRUNC on a file hard-linked between a read-only path and a writable path is rejected with EROFS, a non-exclusive FUSE_CREATE (O_WRONLY | O_TRUNC without O_EXCL) at the writable hard-link path bypasses multi-alias write protection and truncates the protected host file immediately during the open syscall. Found during formal specification (blocks formal verification).

Root Cause

For FUSE_OPEN, VirtioFs::open calls VirtioFs::check_open_readonly, which inspects inode.readonly()—backed on microVM shares by VirtioFsInode::policy_permits_writes, requiring every tracked alias of the inode to lie under writable_paths.

In VirtioFs::create, however, only the parent inode and the single target path are checked before invoking VirtioFsInode::create:

let inode = self.get_inode(request.node_id())?;
self.check_writable(&inode)?;
let path = inode.child_path(name)?;
self.check_writable_entry(&inode, &path)?;
self.preflight_create_inode(&inode, name, &path)?;
self.preflight_file_insert()?;
let inode_reservation = self.reserve_inode()?;
let file_reservation = self.reserve_file()?;
let (new_inode, attr, file) =
    inode.create(name, options, arg.mode, request.uid(), request.gid())?;

VirtioFsInode::create immediately executes self.volume.open(&path, open_options | lx::O_CREAT, Some(options))? on the host. When O_EXCL is not set and path already exists on disk, O_CREAT opens the existing file—truncating it on the host if O_TRUNC is set—before inode_reservation.insert(new_inode) ever deduplicates new_inode onto the existing VirtioFsInode in self.inner.inodes.

Consequence

  • MicroVM write-policy bypass (O_TRUNC data destruction): If a host file has both a read-only path (for example marker outside writable_paths) and a hard link inside writable_paths (for example out/twin), and the guest holds the node with both aliases tracked, FUSE_OPEN(twin, O_WRONLY | O_TRUNC) fails with EROFS, yet FUSE_CREATE(out, "twin", O_WRONLY | O_TRUNC) succeeds and truncates marker to zero bytes on the host.
  • Inconsistent write-open admission: Even without O_TRUNC, a non-exclusive FUSE_CREATE with O_WRONLY or O_RDWR on that existing hard link succeeds and allocates a writable host file handle for an inode whose readonly() predicate is true, violating the rule that a read-only node cannot be opened for writing.

Reproduction

  1. On the host share root, create a protected file marker containing "host" and a hard link out/twin pointing to marker.
  2. Configure a microVM virtio-fs share with writable_paths = ["out"].
  3. Issue FUSE_LOOKUP on "out" (out_node), "out/twin" (twin_node), and "marker" (which deduplicates onto twin_node and records "marker" in its aliases).
  4. Confirm FUSE_OPEN(twin_node, O_WRONLY | O_TRUNC) fails with EROFS.
  5. Issue FUSE_CREATE on (out_node, "twin") with flags = O_WRONLY | O_TRUNC and mode = S_IFREG | 0o644: the call unexpectedly succeeds and truncates marker on the host to "".

Related: #1610, #1604, #1620.

Dominant language
Rust
Stars
831
Forks
56
Avg merge
13h 37m
Merged PRs (30d)
571

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/nvx

All issues in microsoft/nvx

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.