Commit Graph

3 Commits

Author SHA1 Message Date
e34c9e1abe Harden envd concurrency and fix CoW loop device leaks
envd (0.6.0):
- Run blocking syscalls (sync/drop_caches, directory walks and
  removals, stdin/pty writes) on the blocking pool so health checks
  and exec streams don't stall during snapshot quiesce or large-tree
  operations
- Stop writing sandbox metadata into envd's own environment at init;
  it was undefined behavior with the async runtime running
- Retry a memory preload that previously failed or was cancelled
  instead of blocking every future pause until the next init
- Match RAM ranges against kernel core segments on page boundaries so
  preload no longer rejects kernels with unaligned low-memory ranges
- Tolerate a concurrent request creating a directory first

host agent:
- Detach the copy-on-write loop device when snapshot removal fails so
  deleting its backing file can no longer orphan it permanently
- Clean the sandbox directory on pause rollback, and skip paused
  restore for directories still owned by a live VM that failed to
  re-attach
2026-07-07 20:48:39 +06:00
7e1ce86413 fix(sandbox): prevent memory corruption in lazy-restore snapshots
Snapshotting or pausing a sandbox restored with
memory_restore_mode=ondemand silently zeroed all never-faulted guest
memory: envd's preload walked the vmalloc region instead of physical
RAM (/proc/kcore exposes one PT_LOAD per RAM range, never one segment
covering all of RAM), so no pages were materialised and ch.snapshot
wrote holes that read back as zeros on the next restore.

- match kcore segments to /proc/iomem ranges via a derived direct-map
  base; hard-error instead of walking the wrong segment
- guard preload state with a lifecycle generation so a loader thread
  frozen across pause/resume cannot publish a stale "done"
- verify preload against envd before pause/snapshot: self-heal from
  idle, hard-fail on failure; persist the lazy-restore flag so the
  guard survives host-agent restarts and re-attach
- fix loop refcount double-release on pause-then-destroy that detached
  the shared base image under sibling sandboxes
- release runtime resources when a VM dies mid-pause
- detach CoW loops before deleting their backing files; never release
  a live CH process's slot or loop on a failed re-attach

Guest images must be rebuilt (scripts/update-minimal-rootfs.sh);
snapshots taken before this fix carry the old envd and stay unsafe.
2026-07-07 17:27:36 +06:00
067a6b1c9d Move host-agent runtime packages to pkg/ for external reuse
Relocate the sandbox runtime (sandbox, vm, network, devicemapper,
envdclient, layout, models) from internal/ to pkg/ so external
consumers like the wr CLI can embed the orchestration layer without
a control plane. Add cross-process re-attach support for running
sandboxes (state files, restore_running) and bump agent/cp versions.
2026-07-03 03:54:46 +06:00