vmm: one-shot mode allocates CIDs outside the IdPool and is invisible to the VMM
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 45/100
- Tipo de issue
- Bug
- Clareza
- Razoavelmente clara
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- rust
- Domínio
- infrastructure
Direção de pesquisa
Comece por vmm/src/one_shot.rs, especialmente por run_one_shot e pela varredura de CID; depois, acompanhe app.rs reload_vms/reload_vms_sync e crates/dstackup/src/cid.rs. Compare as abordagens de coordenação propostas e determine como os CIDs one-shot devem ser representados no mecanismo de alocação existente. Considera-se concluído quando alocações simultâneas one-shot e do serviço principal não puderem selecionar o mesmo CID.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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 auxscan and the QEMU launch are not atomic; a concurrent allocation in the window collides regardless. - Parsing — CIDs are recovered by string-splitting
ps auxoutput onguest-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
- Register one-shot processes with the supervisor so the existing pool machinery covers them.
- Reserve a dedicated range for one-shot outside
[cid_start, cid_start + cid_pool_size). - Have one-shot allocate through
IdPoolrather thanps 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.
- Linguagem predominante
- Rust
- Estrelas
- 551
- Forks
- 97
- Merge médio
- 1d 8h
- PRs com merge (30d)
- 182
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de Dstack-TEE/dstack
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 35/100
Dstack-TEE/dstack#1384 ·
-
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 30/100
Dstack-TEE/dstack#1301 ·
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 55/100
Dstack-TEE/dstack#1300 ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
Dstack-TEE/dstack#1299 ·
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 48/100
Dstack-TEE/dstack#1298 ·
Todas as issues de Dstack-TEE/dstack
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
TheLarkInn/aipm#2413 ·
-
documentation
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 90/100
alexgorbatchev/simple-ptt#15 ·
-
tooling
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
-
todo:ticket
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 70/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
taikoxyz/taiko-mono#22168 · 1 comentário ·