openvmm: virtiofs: inode deduplication key omits host device number (st_dev)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 半日
- 初心者へのやさしさ
- 64/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
Start in vm/devices/virtio/virtiofs/src/inode.rs at the DedupKey::Ino variant and VirtioFsInode::dedup_key, then follow its use into InodeMap::insert in vm/devices/virtio/virtiofs/src/lib.rs. The fix carries device_nr in the stable-ID key, so check every construction and match site of DedupKey::Ino. Done means the two-inode construction in step 5 of the report yields distinct node IDs; run the virtiofs crate tests via cargo nextest to confirm nothing else shifts.
索引モデルが issue の本文から書いたものです。
説明
Summary
On volumes that report stable file IDs, VirtioFs deduplicates inodes in InodeMap by (volume_id, inode_nr) instead of (volume_id, device_nr, inode_nr). When a single shared directory tree spans multiple host st_dev values — such as nested bind mounts or btrfs subvolumes, where every subvolume root has st_ino == 256 on its own anonymous st_dev — two distinct host objects with the same st_ino collide onto one FUSE node ID and overwrite that node's stored host path. Found by testing (also blocks formal verification).
Root Cause
In vm/devices/virtio/virtiofs/src/inode.rs, DedupKey::Ino omits stat.device_nr, and VirtioFsInode::dedup_key keys stable-ID volumes solely by (self.volume_id(), self.inode_nr()):
#[derive(Clone, PartialEq, Eq, Hash)]
pub(crate) enum DedupKey {
/// `(volume_id, host_inode_number)`, for stable-id volumes.
Ino(u32, lx::ino_t),
/// `(volume_id, host_path)`, for volumes that recycle inode numbers.
Path(u32, PathBuf),
}
pub(crate) fn dedup_key(&self) -> DedupKey {
if self.volume.supports_stable_file_id() {
return DedupKey::Ino(self.volume_id(), self.inode_nr());
}
DedupKey::Path(self.volume_id(), self.get_path().clone())
}
When a lookup resolves a second host object with the same st_ino and file type on a different st_dev, InodeMap::insert takes the Entry::Occupied branch and calls VirtioFsInode::lookup, replacing existing.path with new_path and returning existing's node_id.
Consequence
In POSIX, file identity is (st_dev, st_ino), not st_ino alone. On btrfs, unprivileged users can create subvolumes whose root directory always has st_ino == 256 with a distinct st_dev; container rootfs layers, bind mounts, and nested mounts inside a shared directory produce the same condition on ext4/xfs/overlayfs. If the share root is a btrfs subvolume (FUSE_ROOT_ID == 1, st_ino == 256, path == "") and contains a nested subvolume sub (st_ino == 256, path == "sub"), looking up sub returns nodeid == 1 (producing a directory cycle in the guest VFS) and overwrites the root inode's stored path from "" to "sub", causing subsequent lookups at the share root to resolve inside "sub" and making entries outside "sub" disappear with ENOENT. Colliding regular files across subvolumes or nested mounts likewise alias onto one FUSE node ID, misdirecting path-based operations (getattr, open, setattr, unlink, and microVM subtree policy checks) to whichever path was looked up most recently, and causing microVM save_microvm_state to fail when validate_saved_identity detects that a single inode's recorded aliases have different device_nr values.
Reproduction
- On a Linux host with btrfs (for example by running
cargo nextestwithTMPDIRon a btrfs filesystem), create a btrfs subvolumeroot, create a nested btrfs subvolumeroot/sub, and create a regular fileroot/only_in_root. - Instantiate
VirtioFs::new(&root_path, None)soFUSE_ROOT_ID(1) refers toroot(st_ino == 256). - Call
fs.lookup(&request(FUSE_ROOT_ID), lx::LxStr::from_bytes(b"sub")). It erroneously returnssub.nodeid == FUSE_ROOT_ID(1) and rewrites node1's path from""to"sub". - Call
fs.lookup(&request(FUSE_ROOT_ID), lx::LxStr::from_bytes(b"only_in_root")). It fails withENOENTbecauseVirtioFsresolves"sub/only_in_root"instead of"only_in_root". - Without btrfs, constructing two
VirtioFsInodevalues viaVirtioFsInode::with_attrwith(device_nr: 1, inode_nr: 256)at"a"and(device_nr: 2, inode_nr: 256)at"b"and inserting both intoInodeMapreproduces the same node ID collision deterministically on any host filesystem.
Related: #1605, #1619, #1602.
- 主要言語
- Rust
- スター
- 848
- フォーク
- 63
- 平均マージ
- 13時間 37分
- マージ済み PR(30日)
- 571
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/nvx のほかの issue
-
area: ci
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
area: ci
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
openvmm: virtiofs: aggregate synthetic root st_nlink counts single-file shares as subdirectoriesオープンarea: openvmm
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
microsoft/nvx#1632 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area: openvmm
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
microsoft/nvx#1628 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area: openvmm
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
microsoft/nvx#1629 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
priority: low
難易度 1/5 1〜3時間 初心者へのやさしさ 83/100
storytold/vectorcraft#8387 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
area:desktop kind:test priority:p3 ready
難易度 2/5 1〜3時間 初心者へのやさしさ 91/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
obi1kenobi/cargo-semver-checks#1814 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
BurntSushi/jiff#715 ·
メンテナーはふだん 1 日以内に返信