Bounty
XE-1438 · Bounty

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

Triaging claimed High web filed 2026-11-08 09:07 UTC by Ashev Ardiansyah

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:

  1. QEMUManager.Provision configures QEMU user-mode networking with hostfwd=tcp::%d-:22 (omitting 127.0.0.1), binding the guest VM's SSH port on 0.0.0.0:22000 across all host network interfaces and bypassing the XE SSH gateway and libp2p tunnel.
  2. QEMU's SLIRP stack listens and completes TCP 3-way handshakes on the host-forwarded port as soon as the qemu-system-x86_64 process starts, before guest UEFI (OVMF), kernel boot, cloud-init, or sshd initialization. Because waitForSSHPort in vm/qemu_manager.go:418-429 only performs net.DialTimeout("tcp", ...) and closes the socket without reading an SSH-2.0- banner, Provision reports success immediately while the guest OS is still booting and unready.
  3. If waitForQEMUPID or waitForSSHPort fails in QEMUManager.Provision after QEMU has started with -device vfio-pci,host=<BDF>, the error path kills QEMU but never removes workDir (guest.qcow2, seed.iso, OVMF_VARS.fd) and never invokes m.cfg.VFIO.ResetGPU(), leaving the physical GPU in a dirty PCIe state and leaking disk overlays.
  4. LimaManager.Provision and LimaManager.Teardown hold the exclusive mutex m.mu.Lock() across synchronous multi-minute subprocess calls (up to 9 minutes in Provision: 2m limactl create + 5m limactl start + 2m waitForSSHPort), blocking DialSSH, Get, List, and Teardown for 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

  1. Direct Host Port Exposure & Premature Lease Acceptance: Guest SSH (port 22000) is bound on 0.0.0.0:22000 on the provider host. Because SLIRP accepts TCP connections on 22000 before the guest boots, waitForSSHPort returns nil immediately, causing the provider to publish BlockLeaseAccept and start billing the consumer before the guest kernel, cloud-init (which writes authorized_keys), or sshd has started.
  2. Wedged VFIO GPU and Disk Leak on Boot Timeout: Any failure in waitForQEMUPID or waitForSSHPort skips m.cfg.VFIO.ResetGPU() and os.RemoveAll(workDir), leaving the GPU unreset for subsequent leases and leaking disk overlays under workRoot.
  3. Cross-Tenant SSH Tunnel Freeze: While LimaManager.Provision or Teardown is running (up to 9 minutes on slow boots or image setup), DialSSH blocks on m.mu.RLock(), freezing new SSH gateway and libp2p tunnel sessions for all other active leases on the provider.

Remediation

  1. Bind QEMU hostfwd explicitly to loopback (hostfwd=tcp:127.0.0.1:%d-:22).
  2. In QEMUManager's waitForSSHPort, set a read deadline on conn and verify that the remote peer sends an SSH-2.0- protocol banner (or complete an SSH handshake) after cloud-init finishes before returning nil.
  3. On waitForQEMUPID and waitForSSHPort error paths in QEMUManager.Provision, call _ = os.RemoveAll(workDir) and _ = m.cfg.VFIO.ResetGPU().
  4. In LimaManager.Provision and Teardown, insert a per-lease provisioning state under m.mu.Lock(), release m.mu during limactl subprocess execution and SSH polling, and re-acquire m.mu.Lock() only to update m.vms.

Thread

Joseph Denneteam2026-11-08 20:34 UTCdesk

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.