openvmm: virtiofs: non-exclusive FUSE_CREATE on an existing file bypasses read-only alias checks and truncates protected hard links
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
- Domain
- operating-systems, security
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_TRUNCdata destruction): If a host file has both a read-only path (for examplemarkeroutsidewritable_paths) and a hard link insidewritable_paths(for exampleout/twin), and the guest holds the node with both aliases tracked,FUSE_OPEN(twin, O_WRONLY | O_TRUNC)fails withEROFS, yetFUSE_CREATE(out, "twin", O_WRONLY | O_TRUNC)succeeds and truncatesmarkerto zero bytes on the host. - Inconsistent write-open admission: Even without
O_TRUNC, a non-exclusiveFUSE_CREATEwithO_WRONLYorO_RDWRon that existing hard link succeeds and allocates a writable host file handle for an inode whosereadonly()predicate istrue, violating the rule that a read-only node cannot be opened for writing.
Reproduction
- On the host share root, create a protected file
markercontaining"host"and a hard linkout/twinpointing tomarker. - Configure a microVM virtio-fs share with
writable_paths = ["out"]. - Issue
FUSE_LOOKUPon"out"(out_node),"out/twin"(twin_node), and"marker"(which deduplicates ontotwin_nodeand records"marker"in itsaliases). - Confirm
FUSE_OPEN(twin_node, O_WRONLY | O_TRUNC)fails withEROFS. - Issue
FUSE_CREATEon(out_node, "twin")withflags = O_WRONLY | O_TRUNCandmode = S_IFREG | 0o644: the call unexpectedly succeeds and truncatesmarkeron 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/nvx
-
area: ci
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
area: ci
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
openvmm: virtiofs: aggregate synthetic root st_nlink counts single-file shares as subdirectoriesOpenarea: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
microsoft/nvx#1632 · 1 comment ·
Maintainers usually reply within 1 day
-
area: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
microsoft/nvx#1628 · 1 comment ·
Maintainers usually reply within 1 day
-
area: openvmm
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
microsoft/nvx#1629 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
good first issue help wanted
Difficulty 1/5 Under an hour Newbie friendliness 87/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jolars/panache#627 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
swc-project/swc-next-issues#490 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
oxc-project/tsrs#1010 ·
Maintainers usually reply within 1 day
-
Link is deadOpen
Difficulty 1/5 Under an hour Newbie friendliness 63/100
nicholas-ochoa/OpenSC2K#104 ·