Skip to content

feat: vsock support with CID allocation and UDS validation#8

Open
jasonhernandez wants to merge 2 commits intoaljoscha:mainfrom
jasonhernandez:feat/vsock-cid-allocator
Open

feat: vsock support with CID allocation and UDS validation#8
jasonhernandez wants to merge 2 commits intoaljoscha:mainfrom
jasonhernandez:feat/vsock-cid-allocator

Conversation

@jasonhernandez
Copy link
Copy Markdown
Collaborator

Summary

Complete virtio-vsock support for host-guest communication, including proper CID allocation.

  • vsock device: --vsock flag on ember vm create / ember vm fork and vsock: true YAML config
  • Firecracker (Linux): PUT /vsock API — UDS at <state_dir>/vms/<name>/vsock.sock
  • AVF (macOS): VZVirtioSocketDeviceConfiguration + ember-vz bidirectional UDS↔vsock bridge
  • CID allocator: unique per-VM CIDs persisted in vsock/cids.json, freed on delete, lowest-first reuse. Read-modify-write under exclusive flock (via new StateStore::update method) to prevent TOCTOU races between concurrent processes.
  • UDS path validation: checks macOS sun_path limit (104 bytes) before allocating resources
  • vsock bridge fix: data forwarding corrected on macOS AVF

Both platforms expose the same UDS interface — Thermite sees identical behavior.

Files changed

File What
crates/ember-core/src/state/vm.rs VsockInfo struct, field on VmMetadata
crates/ember-core/src/state/vsock.rs CID allocator — allocate/release, persisted to vsock/cids.json
crates/ember-core/src/state/store.rs update() method for atomic read-modify-write under flock
crates/ember-core/src/config/vm.rs vsock: Option<bool> in YAML config
crates/ember-core/src/error.rs Vsock error variant
crates/ember-linux/src/firecracker/api.rs Vsock type + put_vsock()
crates/ember-linux/src/firecracker/config.rs vsock in config builder
crates/ember-linux/src/vm.rs Wire vsock → Firecracker
crates/ember-macos/src/vm.rs Pass --vsock-path to ember-vz
ember-vz/Sources/EmberVZ/Start.swift VZVirtioSocketDeviceConfiguration + UDS bridge
src/cli/vm.rs --vsock flag, CID allocation in create/fork/delete, UDS validation, vsock in inspect
tests/vsock.rs 6 integration tests (CID uniqueness/reuse, inspect, UDS connectivity)

Test plan

  • 29 unit tests pass (cargo test --workspace) — 9 CID allocator + 3 UDS validation + 17 existing
  • cargo build clean on macOS, cargo clippy --workspace clean, cargo fmt clean
  • cargo test --test vsock -- --ignored on macOS with ember-vz built
  • cargo test --test vsock -- --ignored on Linux with Firecracker + KVM

Refs: Thermite SEC-254/SEC-257

🤖 Generated with Claude Code

jasonhernandez and others added 2 commits April 14, 2026 17:07
Add vsock device support across both Firecracker (Linux) and AVF (macOS)
backends, enabling structured host↔guest communication over a Unix domain
socket instead of SSH polling.

CLI: `ember vm create myvm --image base --vsock`
YAML config: `vsock: true`
UDS created at: `<state_dir>/vms/<name>/vsock.sock`

Linux (Firecracker):
- New `PUT /vsock` API call with guest CID and UDS path
- Firecracker natively creates the UDS and bridges to guest AF_VSOCK

macOS (AVF):
- VZVirtioSocketDeviceConfiguration added to VM config
- ember-vz implements a UDS bridge: accepts host connections on the UDS
  and proxies them to guest vsock port 1024, and accepts guest-initiated
  connections on port 1024 and bridges them back to the UDS

Both platforms expose the same UDS interface — Thermite's code path is
identical regardless of the underlying hypervisor.

Co-Authored-By: Claude <noreply@anthropic.com>
Replace hardcoded guest_cid=3 with a proper CID allocator that assigns
unique CIDs per VM, persisted in vsock/cids.json. Uses the new
StateStore::update() method for atomic read-modify-write under exclusive
flock, preventing TOCTOU races between concurrent processes.

Also validates UDS path length against macOS sun_path limit (104 bytes)
before allocating resources, and adds 6 integration tests covering CID
uniqueness, reuse, inspect output, and end-to-end UDS connectivity.
@jasonhernandez jasonhernandez force-pushed the feat/vsock-cid-allocator branch from 2d633f9 to 6b3a556 Compare April 15, 2026 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant