Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

vmm: one-shot mode allocates CIDs outside the IdPool and is invisible to the VMM

未关闭
#997 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
冷清
技术栈
rust

调研方向

从 vmm/src/one_shot.rs 开始,重点查看 run_one_shot 和 CID 扫描,然后跟踪 app.rs reload_vms/reload_vms_sync 以及 crates/dstackup/src/cid.rs。比较提出的协调方案,并确定应如何在现有分配机制中表示 one-shot CID。完成的标准是:并发的 one-shot 分配和主服务分配不能选择同一个 CID。

由索引模型根据 Issue 内容生成。

描述

Summary

One-shot mode (vmm/src/one_shot.rs) and the main VMM service allocate vsock CIDs from the same configured range through two mechanisms that do not know about each other. Nothing prevents them from picking the same CID.

The two allocators

Main service — IdPool over [cid_start, cid_start + cid_pool_size), rebuilt on reload from the supervisor's process list (app.rs, reload_vms / reload_vms_sync).

One-shot — one_shot.rs:24-56:

// scan `ps aux` for qemu-system-x86_64 ... guest-cid=<n>
let mut one_shot_cid = config.cvm.cid_start;
while existing_cids.contains(&one_shot_cid) {
    one_shot_cid += 1;
    ...
}

It starts at cid_start, avoids collisions by scraping ps aux, and never touches the pool.

Why they can collide

One-shot launches QEMU directly (cmd.status() at the end of run_one_shot) rather than registering the process with the supervisor. occupied_cids in both reload paths is built from supervisor.list(), so a one-shot VM's CID is invisible to the main service and never gets occupied in the pool.

The blindness is one-directional:

sees the other's CIDs? via
one-shot → main service yes ps aux finds the qemu processes
main service → one-shot no one-shot never reaches the supervisor

So the main service can allocate a CID that a running one-shot VM already holds.

Two secondary issues in the same code path:

  • TOCTOU — the ps aux scan and the QEMU launch are not atomic; a concurrent allocation in the window collides regardless.
  • Parsing — CIDs are recovered by string-splitting ps aux output on guest-cid=, which is sensitive to how QEMU arguments are formatted.

Note on #907

Before #907, IdPool::allocate() had an off-by-one that made it skip cid_start entirely, while one-shot starts at cid_start. That incidentally kept the two apart. #907 fixed the off-by-one (correctly — one_shot.rs:48 and crates/dstackup/src/cid.rs both already treat the window as [start, start+size)), which removes the accidental separation.

This is not a regression introduced by #907. The protection only ever held for exactly one one-shot VM: a second one takes cid_start + 1, which was already inside the main pool's allocation range. The underlying problem is that the two allocators were never coordinated.

Possible directions

  1. Register one-shot processes with the supervisor so the existing pool machinery covers them.
  2. Reserve a dedicated range for one-shot outside [cid_start, cid_start + cid_pool_size).
  3. Have one-shot allocate through IdPool rather than ps aux.

(1) seems most consistent with how the rest of the system tracks VMs, but one-shot is deliberately a lighter path, so (2) may be the cheaper fix.

Confidence

The code paths are confirmed by reading: one-shot starts at cid_start, does not register with the supervisor, and both reload paths source occupied_cids from supervisor.list() only. Not verified on hardware — I have not observed an actual vsock CID collision, and I do not know how much one-shot mode is used in practice, which bounds how much this matters.

Found while reviewing #907.

主要语言
Rust
星标
551
派生
97
平均合并
1 天 8 小时
30 天内合并 PR
182

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Dstack-TEE/dstack 的其他 Issue

查看 Dstack-TEE/dstack 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。