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

オープン
#1,602 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Rust
スター
848
フォーク
63
平均マージ
13時間 37分
マージ済み PR(30日)
571

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/nvx のほかの issue

microsoft/nvx の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。