QEMU and Lima VM managers bind guest SSH on 0.0.0.0, report premature SLIRP readiness, skip GPU FLR on fail, and hold global lock
Report
- Area:
vm-isolation - Claimed Tier:
high - Affected Files:
xe/vm/qemu_manager.go:144-296, 418-429(Provision,Teardown,waitForSSHPort)xe/vm/lima_manager.go:94-228, 303-322(Provision,Teardown,DialSSH,Get,List,runLimactlWithTimeout)
Summary
The Linux QEMUManager and macOS/Linux LimaManager contain four isolation and lifecycle flaws in VM provisioning and teardown:
QEMUManager.Provisionconfigures QEMU user-mode networking withhostfwd=tcp::%d-:22(omitting127.0.0.1), binding the guest VM's SSH port on0.0.0.0:22000across all host network interfaces and bypassing the XE SSH gateway and libp2p tunnel.- QEMU's SLIRP stack listens and completes TCP 3-way handshakes on the host-forwarded port as soon as the
qemu-system-x86_64process starts, before guest UEFI (OVMF), kernel boot,cloud-init, orsshdinitialization. BecausewaitForSSHPortinvm/qemu_manager.go:418-429only performsnet.DialTimeout("tcp", ...)and closes the socket without reading anSSH-2.0-banner,Provisionreports success immediately while the guest OS is still booting and unready. - If
waitForQEMUPIDorwaitForSSHPortfails inQEMUManager.Provisionafter QEMU has started with-device vfio-pci,host=<BDF>, the error path kills QEMU but never removesworkDir(guest.qcow2,seed.iso,OVMF_VARS.fd) and never invokesm.cfg.VFIO.ResetGPU(), leaving the physical GPU in a dirty PCIe state and leaking disk overlays. LimaManager.ProvisionandLimaManager.Teardownhold the exclusive mutexm.mu.Lock()across synchronous multi-minute subprocess calls (up to 9 minutes inProvision: 2mlimactl create+ 5mlimactl start+ 2mwaitForSSHPort), blockingDialSSH,Get,List, andTeardownfor all other active VMs on the provider.
Root Cause
In xe/vm/qemu_manager.go:219-246:
"-netdev", fmt.Sprintf("user,id=n0,hostfwd=tcp::%d-:22", m.cfg.SSHHostfwdPort),
"-device", "virtio-net-pci,netdev=n0",
"-device", fmt.Sprintf("vfio-pci,host=%s,multifunction=on", m.cfg.VFIO.BDF),
}
if m.cfg.VFIO.AudioBDF != "" {
args = append(args, "-device", fmt.Sprintf("vfio-pci,host=%s", m.cfg.VFIO.AudioBDF))
}
out, err := exec.Command(m.cfg.SudoBinary, args...).CombinedOutput()
if err != nil {
_ = os.RemoveAll(workDir)
return nil, fmt.Errorf("launch qemu: %w (output: %s)", err, strings.TrimSpace(string(out)))
}
pid, err := waitForQEMUPID(name, 60*time.Second)
if err != nil {
m.killQEMUByName(name)
return nil, fmt.Errorf("find qemu pid: %w", err)
}
_ = pidPath
if err := waitForSSHPort(m.cfg.SSHHostfwdPort, 2*time.Minute); err != nil {
_ = m.killQEMU(pid)
return nil, fmt.Errorf("ssh not ready: %w", err)
}
And waitForSSHPort in xe/vm/qemu_manager.go:418-429 checks only TCP connectability:
func waitForSSHPort(port int, timeout time.Duration) error {
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
conn, err := net.DialTimeout("tcp", fmt.Sprintf("127.0.0.1:%d", port), 2*time.Second)
if err == nil {
_ = conn.Close()
return nil
}
time.Sleep(2 * time.Second)
}
return fmt.Errorf("ssh port %d not ready after %s", port, timeout)
}
In xe/vm/lima_manager.go:94-180, Provision and Teardown hold m.mu.Lock() across runLimactlWithTimeout and waitForSSHPort, while DialSSH (line 183), Get (line 200), and List (line 217) require m.mu.RLock(). In addition, LimaManager.Provision checks m.vms[leaseHash] by full hash (line 98) but creates the Lima instance using only a 12-hex-character prefix name := fmt.Sprintf("xe-%s", leaseHash[:12]) (line 107).
Impact
- Direct Host Port Exposure & Premature Lease Acceptance: Guest SSH (
port 22000) is bound on0.0.0.0:22000on the provider host. Because SLIRP accepts TCP connections on22000before the guest boots,waitForSSHPortreturnsnilimmediately, causing the provider to publishBlockLeaseAcceptand start billing the consumer before the guest kernel,cloud-init(which writesauthorized_keys), orsshdhas started. - Wedged VFIO GPU and Disk Leak on Boot Timeout: Any failure in
waitForQEMUPIDorwaitForSSHPortskipsm.cfg.VFIO.ResetGPU()andos.RemoveAll(workDir), leaving the GPU unreset for subsequent leases and leaking disk overlays underworkRoot. - Cross-Tenant SSH Tunnel Freeze: While
LimaManager.ProvisionorTeardownis running (up to 9 minutes on slow boots or image setup),DialSSHblocks onm.mu.RLock(), freezing new SSH gateway and libp2p tunnel sessions for all other active leases on the provider.
Remediation
- Bind QEMU
hostfwdexplicitly to loopback (hostfwd=tcp:127.0.0.1:%d-:22). - In
QEMUManager'swaitForSSHPort, set a read deadline onconnand verify that the remote peer sends anSSH-2.0-protocol banner (or complete an SSH handshake) aftercloud-initfinishes before returningnil. - On
waitForQEMUPIDandwaitForSSHPorterror paths inQEMUManager.Provision, call_ = os.RemoveAll(workDir)and_ = m.cfg.VFIO.ResetGPU(). - In
LimaManager.ProvisionandTeardown, insert a per-lease provisioning state underm.mu.Lock(), releasem.muduringlimactlsubprocess execution and SSH polling, and re-acquirem.mu.Lock()only to updatem.vms.
Thread
Thanks for the report. We have confirmed the behaviour you describe in the VM provisioning path and it is being handled. Two of the four points you raised were already on the desk from earlier reports and are tracked there; the ticket at https://bounty.xe.network/XE-1438 covers the remainder. We will update you when the fix has shipped.