{"id":"XE-1787","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":301,"title":"A dead guest VM is reported as running forever: neither VM manager ever checks guest liveness, so a powered-off VM keeps charging provider capacity until settle","area":"node-api","claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":null,"status":"triaging","closed_reason":null,"github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-09T04:09:01.133742+00:00","updated_at":"2026-11-09T10:32:39.427271+00:00","source_created_at":null,"told_at":"2026-11-09T10:20:15.480689+00:00","status_changed_at":"2026-11-09T10:20:11.827363+00:00","url":"https://bounty.xe.network/XE-1787","body":"# [Medium] A dead guest VM is reported as running forever: neither VM manager ever checks guest liveness, so a powered-off VM keeps charging provider capacity until settle\n\n## Summary\n\nBoth production VM managers answer `Get` and `List` purely from an\nin-memory map, and nothing in the process ever re-checks whether the guest\nis still alive. The only liveness reaping in either manager is\n`cleanOrphans()`, which runs exactly once, at manager construction. A guest\nwhose process dies mid-run, because the tenant powers it off from inside,\nbecause the host OOM killer takes it, or because an admin kills the\ninstance, therefore leaves a phantom entry: `Get` keeps returning status\n`running`, `List` keeps charging its full vCPU, memory and disk against\nprovider capacity, `activeLeaseCount` keeps counting it, and `DialSSH`\nfails against a dead port. The phantom clears only when the lease settles\nand `finishSettle` calls teardown, or when the process restarts. Until\nthen the provider cannot sell that capacity to anyone else, reports a VM\nthat does not exist, and cannot reach the guest it believes is running.\n\n## Affected component and versions\n\n- `xeprotocol/xe`, `master` @ `02e9641` (`Merge pull request #251 from xeprotocol/fix/dao-tool-timestamp`). No PR is required.\n- `vm/lima_manager.go`: `Get` (`:199`), `List` (`:216`), `cleanOrphans` (`:325`, called only from `NewLimaManager` at `:85`).\n- `vm/qemu_manager.go`: `Get` (`:312`), `List` (`:327`), `cleanOrphans` (`:361`, called only from `NewQEMUManager` at `:139`).\n- `node/node.go`: the capacity loops that consume `List()` in\n  `autoAcceptLease` (`:1520`), `handleMarketplace` (`:1332`), and\n  `activeLeaseCount` (`:1429`); `cleanupOrphanedVMs` (`:1773`), which only\n  tears down terminal leases; `trySettleExpiredLeases` (`:1796`).\n\n## Mechanism\n\n`LimaManager.Get` and `List` are map reads with a hardcoded status:\n\n```go\n// vm/lima_manager.go:199-230\nfunc (m *LimaManager) Get(leaseHash string) (*Info, error) {\n    m.mu.RLock()\n    defer m.mu.RUnlock()\n    v, ok := m.vms[leaseHash]\n    if !ok {\n        return nil, fmt.Errorf(\"vm not found for lease %s\", leaseHash)\n    }\n    return &Info{\n        LeaseHash: leaseHash,\n        Status:    \"running\",\n        Resources: &v.resources,\n        CreatedAt: v.createdAt,\n    }, nil\n}\n```\n\n`QEMUManager.Get` and `List` are identical in shape\n(`vm/qemu_manager.go:312-340`), same hardcoded `\"running\"`, same map.\nEntries enter the map only in `Provision` (`lima_manager.go:146`,\n`qemu_manager.go:258`) and leave it only in `Teardown`. Nothing ever\nqueries the hypervisor again: `cleanOrphans` is called only from the two\nconstructors, and it does not even touch `m.vms`, it kills stray\nprocesses directly. There is no periodic reaper, no health check on read,\nand no pid liveness test anywhere in `vm/`.\n\nThree node paths then treat the phantom as a live VM:\n\n1. Capacity. `autoAcceptLease` sums `VMManager.List()` before deciding a\n   new lease fits (`node/node.go:1520-1532`), and `handleMarketplace`\n   does the same sum before offering capacity to a new request\n   (`node/node.go:1332-1344`). A dead VM's resources stay subtracted\n   from the provider's advertised capacity, so new leases are refused\n   with `insufficient resources` and new requests get no offer.\n2. Counts. `activeLeaseCount` is just `len(n.VMManager.List())`\n   (`node/node.go:1429-1434`), so the provider's own active-lease\n   number stays wrong for the whole window.\n3. Reachability. `DialSSH` dials the recorded port\n   (`lima_manager.go:182-195`, `qemu_manager.go:298-310`), which is\n   closed, so tunnels and the SSH gateway fail for a VM the node\n   reports as running. `GET /vms` reports it running too.\n\nThe node has no path that notices. `cleanupOrphanedVMs`\n(`node/node.go:1773-1794`) only tears down a VM when its lease record\nexists and is terminal; the lease here is `Accepted`, not terminal, so\nthe phantom is skipped every 10 seconds. Recovery happens only at\nsettle: `trySettleExpiredLeases` calls `settleLease`, `finishSettle`\ncalls `teardownVM`, and `Teardown` deletes the map entry even though\nthe process is already gone (its kill failure is logged and ignored).\nIf the provider misses the one hour settle grace window, the phantom\npersists until consumer force-settle or archive, which at maximum lease\nduration is 365 days plus 85 minutes.\n\nThe trigger needs no privilege beyond what the lease already grants.\nThe tenant has root inside the guest by design, and powering the guest\noff (`poweroff`, `shutdown -h now`) is a routine tenant action, not an\nexploit. A guest kernel panic, a host OOM kill, or an admin killing the\ninstance all produce the same phantom through the same missing check.\nRenewal extends the window: `RenewLease` (`node/lease_renew.go:10-86`)\nchecks lease state, the provider certificate, and the consumer balance,\nbut never checks whether the VM is alive, so a dead lease can be\nrenewed and its phantom charge extended indefinitely (code read, not\nexercised in the PoC).\n\n## Proof of concept\n\nPoC record: `~/workspace/xe-audit/poc-round11-deadvm/poc_round11_deadvm_test.go`.\nOne test, run twice against HEAD `02e9641` with Go 1.25.0\n(`go test ./vm -run 'TestDeadVM' -count=1 -v`, 0.33s and 0.42s, PASS\nboth times). The test file was copied into `~/workspace/xe/vm/` for the\nruns and deleted afterwards; the repo is clean.\n\nThe test drives the REAL `LimaManager` with a fake `limactl` shim (same\npattern as the Round 10 credential-mode PoC). The shim plays the ground\ntruth an operator sees: after the simulated guest poweroff it reports\nthe instance `Stopped` via `limactl list`.\n\n1. Provision a VM through the real manager (fake `limactl` answering\n   `--version`, `create`, `start`, and `list` with a real listening TCP\n   port as the guest SSH port). Provision succeeds.\n2. Control, guest alive: `Get` returns `running`, `List` has 1 entry,\n   `DialSSH` succeeds.\n3. Guest dies: close the listener (the guest SSH endpoint is gone) and\n   flip the shim so `limactl list` reports the instance `Stopped`.\n   Ground truth verified in-test: the shim output contains\n   `\"status\":\"Stopped\"`.\n4. Defect, all asserted: `Get` still returns status `running` with no\n   error; `List` still returns 1 entry with the dead VM's full\n   resources (1 vCPU, 1024 MB, 10 GB); the node capacity sum over\n   `List()` still charges 1/1024/10; `DialSSH` fails with connection\n   refused; repeated reads stay stale (no background reaper).\n5. Recovery bound, asserted: `Teardown` on the dead entry succeeds and\n   `List` becomes empty, confirming the phantom clears at settle time.\n\nThe QEMU path is established by code read, not execution: no GPU is\nbound on this machine, and `QEMUManager.Get`/`List`/`cleanOrphans`\nhave the identical map-only shape (cited above). The Lima execution\nproves the shared defect at the manager layer; the QEMU manager cannot\nbehave differently, because it never consults the qemu process either.\n\nReproduce:\n\n```\ncp ~/workspace/xe-audit/poc-round11-deadvm/poc_round11_deadvm_test.go ~/workspace/xe/vm/\ncd ~/workspace/xe && go test ./vm -run 'TestDeadVM' -count=1 -v\nrm ~/workspace/xe/vm/poc_round11_deadvm_test.go\n```\n\n## Impact\n\nA tenant powering off their own VM, a routine action, wedges the\nprovider's capacity accounting until the lease settles. The concrete\nharms, all proven in the PoC except where marked:\n\n- Provider capacity denial. New leases are refused and new marketplace\n  requests get no offer for the dead VM's share of capacity. The wedge\n  is total when the dead lease took a large share of a small provider\n  (for example a 1 vCPU provider whose only VM dies), and partial\n  otherwise. Normal-case duration is the remaining lease term plus up\n  to the 1 hour settle grace; renewal extends it (code read), and a\n  missed settle window extends it to force-settle or archive.\n- Phantom reporting. `GetVM` and `GET /vms` report a running VM that\n  does not exist, and `activeLeaseCount` overstates live leases, so the\n  operator's view of their own fleet is wrong for the whole window.\n- Broken access. Tunnels and the SSH gateway dial a closed port for a\n  lease the node believes is live, so the consumer gets connection\n  refused with no signal that the guest is gone rather than the network\n  being down.\n\nThis is bounded at Medium, not High. No funds are lost or stolen: settle\nis time based, so the provider is still paid and the consumer escrow\nstill settles on schedule. The provider loses resale of idle capacity,\nnot the lease payment. The phantom self-heals at settle, and a process\nrestart clears the map (at the cost XE-0114 documents: restart destroys\nlive VMs, so restart is not a usable remedy in production). The QEMU\nhalf is code-read only.\n\n## Why this is not XE-0114\n\nXE-0114 (triaging, Medium) is the opposite direction of the same map.\nIt reports that manager construction reaps LIVE VMs: `cleanOrphans`\nruns at startup and destroys instances backing Accepted leases, and\nnothing re-provisions them. R11-D1 reports that NOTHING reaps a DEAD\nVM mid-run: `cleanOrphans` runs only at construction, and `Get`/`List`\nnever check liveness afterwards. Different trigger (routine provider\nrestart versus routine tenant poweroff), different function\n(construction-time `cleanOrphans` versus read-time `Get`/`List`),\ndifferent symptom (live service destroyed versus dead VM counted\nlive), different fix (reconcile before reaping at startup versus check\nliveness on read or reap periodically). XE-0114's full body (5,918\ncharacters, read in full) contains zero mentions of `Get`, `List`,\nliveness, poweroff, or a dead guest, and its proposed fix (reconcile\nat construction) does not touch the mid-run staleness at all. Fixing\nXE-0114 would not fix R11-D1, and fixing R11-D1 would not fix XE-0114.\n\n## Why this is not XE-0615\n\nXE-0615 (closed, Medium) reports that a VM whose lease record was\nDELETED is never torn down: `cleanupOrphanedVMs` skips it because\n`GetLease` returns nil, so a live guest runs forever and its capacity\nis permanently charged. R11-D1 is the mirror image: the lease record\nEXISTS and is `Accepted`, the guest is DEAD, and the map entry is kept.\nDifferent trigger (branch unwind deleting the lease record versus\nguest poweroff), different state (live VM with no lease versus dead VM\nwith a live lease), different fix (tear down VMs with missing leases\nversus detect dead guests). XE-0615's fix would not change R11-D1 at\nall: the lease record is present, so its `cleanupOrphanedVMs` path\nstill skips the phantom. XE-0615's full body (27,907 characters, read\nin full) never mentions a dead guest, a poweroff, or `Get`/`List`\nliveness; its capacity discussion is about a live orphan consuming\nreal capacity, not a phantom consuming accounted capacity.\n\n## Why this is not XE-1053\n\nXE-1053 (closed, High) covers three VM lifecycle gaps, and item 3 is\nthe closest: a VM orphaned when `BlockLeaseAccept` or `BlockLease` is\nunwound by a branch swap, with `cleanupOrphanedVMs` skipping it and\n`autoAcceptLease` refusing to re-accept it. R11-D1 shares no trigger\nwith that item: no swap, no unwind, no missing lease. The lease here\nis `Accepted` throughout, the VM is dead, and the defect is in the\nmanagers' read path, not in the node settle or accept paths. XE-1053's\nproposed remediation (tear down VMs for missing, terminal, expired, or\n`Created` leases) does not cover an `Accepted` lease whose guest died,\nso it would leave R11-D1 exactly as it is. XE-1053's full body (5,933\ncharacters, read in full) mentions `Get` and `List` once each, only in\nthe context of the unwind skip, never as a liveness defect. Items 1\nand 2 (post-grace retention of a live VM, `finishSettle` early return)\nare about live VMs that should have been torn down; R11-D1 is about a\ndead VM that should have been noticed.\n\n## Why this is not XE-1438\n\nXE-1438 (triaging, High) reports four provisioning-time flaws,\nincluding QEMU premature SLIRP readiness: `waitForSSHPort` checks only\nTCP connectability, so `Provision` reports success while the guest is\nstill booting. That is a check that is too weak AT PROVISION TIME.\nR11-D1 is the absence of any check AFTER provision time. Different\nphase, different function (`waitForSSHPort` versus `Get`/`List`),\ndifferent fix (verify an SSH banner at provision versus verify the\nguest is alive on read or on a reaper tick). XE-1438's full body (5,360\ncharacters, read in full) mentions `Get`/`List` only in its item 4,\nabout the provisioning mutex blocking those calls, never about their\nreturn values going stale. Its `DialSSH` mentions are about tunnel\nfreezing during provision, not about dialing a dead guest.\n\n## Why this is not XE-0119\n\nXE-0119 (triaging, Medium) reports that declared resources are clamped\nup at provision time while capacity accounting only sees the declared\nnumbers, so a live guest consumes more host disk and RAM than it is\ncharged for. R11-D1 is about a guest consuming NOTHING while still\nbeing charged its full declared resources. The accounting error points\nthe other way, the trigger is different (zero-dimension lease versus\nguest poweroff), and the fix is different (record effective resources\nversus detect dead guests). XE-0119's full body (5,920 characters, read\nin full) never mentions a dead, stopped, or powered-off VM.\n\n## Why this is not XE-0678\n\nXE-0678 (closed, High) is the exact mirror image at the other end of\nthe lifecycle: `Teardown` deletes the map entry even when the kill\nfails, so a LIVE VM becomes untracked and keeps running. R11-D1 is a\nDEAD VM that stays tracked. The two defects are compatible and\nindependent: fixing XE-0678 (verify termination before removing from\nthe map) does not add any liveness check to `Get`/`List`, and fixing\nR11-D1 (check liveness) does not change `Teardown` failure handling.\nXE-0678's full body (658 characters, read in full) is entirely about\nthe teardown path.\n\n## Gates (BountyForge, Al-Mizaan, triage)\n\nTRIGGER: pass. Any tenant can trigger it with a routine action on their\nown VM (poweroff from inside the guest), no privilege, no malformed\ninput, no victim action beyond the provider's ordinary operation, and\nno key or funds beyond the lease itself. Host-side triggers (OOM kill,\nadmin kill, guest panic) produce the same phantom. IMPACT: pass with\nbounds. The loss is quantified (the dead VM's full declared resources\ncharged until settle; new leases refused; `/vms` wrong; tunnels fail)\nand demonstrated end to end in the PoC at the real manager layer; it\nis bounded at Medium because no funds move, settle still pays the\nprovider, and the phantom self-heals at settle. Al-Mizaan G1 (code read\nliterally) pass, G2 (complete chain: guest death to stale `Get`/`List`\nto capacity denial, proven in the PoC) pass, G3 (trigger is an ordinary\nunprivileged tenant, not an admin) pass, G4 (invariant breached: a\nmanager reporting a VM `running` must have a live guest behind it, and\ncapacity accounting must reflect live guests) pass, G5 (design intent:\n`cleanOrphans` exists precisely to reap dead instances, which shows\nthe design intends the registry to track live guests; it just only\nruns at construction) pass, G6 (impact quantified, bounds stated,\nrecovery paths stated) pass, G7 (PoC reproduces twice, third-party\nverifiable) pass. Triage Q1 pass (exact reproduction in the PoC), Q2\npass (desk precedent accepts Medium for VM lifecycle availability\ndefects of this shape; XE-0114 Medium and XE-0119 Medium are the\nnearest precedents), Q3 pass (xe repo, `vm` plus `node` capacity\nconsumers), Q4 pass (no privilege needed), Q5 pass with the six\nneighbours distinguished above (shared theme is VM lifecycle and\ncapacity accounting; each neighbour is a different mechanism, trigger,\nand fix), Q6 pass (impact proven at the manager layer and traced to\nthe node capacity loops, not just a code path), Q7 pass (not a\nnever-submit class). Pre-severity gate for Medium: full chain validated\nto attacker-attainable impact; the tenant walks away having wedged the\nprovider's capacity with a routine action; reproduced twice; no gating\ncheck remains (no liveness check exists to gate on); desk precedent\naccepts Medium for this class. Honest downside, recorded: a skeptical\ntriager could read this as Minor rather than Medium, because the full\nwedge needs tight capacity or a large dead lease, the phantom\nself-heals at settle, a restart clears it, and no funds are at risk.\nThe Medium claim rests on the trigger being a routine tenant action\ncombined with silent corruption of the provider's capacity, counts,\nreporting, and tunnel reachability until settle.\n\n## Suggested fix\n\nCheck liveness where the registry is read, or reap on a tick, for\nexample: `Get`/`List` verify the guest is alive (Lima: `limactl list`\nstatus; QEMU: pid alive via `kill -0` plus SSH port reachable) and drop\nor mark entries that fail; or run the existing `cleanOrphans` logic on\nthe settle loop tick and reconcile `m.vms` against it, so a dead guest\nstops charging capacity within seconds instead of at settle. Either\nfix must keep XE-0114's direction in mind: reconcile, do not blindly\nreap, so live VMs are never destroyed by the new check.\n\n## Duplicate check\n\nDesk: 549 tickets at check time (9 Nov 2026). Title sweep over all 549\ntitles for zombie, liveness, dead vm, guest, poweroff, power off,\nshutdown, process died, process exits, stopped, stale vm, phantom,\nqemu exits, lima stop, reap, health check: no title names this defect.\nFull bodies read via `GET https://bounty.xe.network/v1/tickets/<id>`:\nXE-0114 (5,918 chars), XE-1438 (5,360 chars), XE-0678 (658 chars),\nXE-0119 (5,920 chars), XE-0920 (4,781 chars), XE-0041 (7,747 chars),\nXE-1053 (5,933 chars), XE-0615 (27,907 chars). Each is distinguished\nin the sections above. No other ticket names `cleanOrphans` (XE-0114's\nown duplicate check found zero matches for it, and this round's sweep\nagrees), and no ticket names a dead guest still reported running.","patch_refs":[],"thread":[{"id":1375,"source":"desk","source_ref":"reply:884","author":"Joseph Denne","team":true,"body":"Thanks for the report. We have confirmed the reading against the current tree and it is being handled. The assessment and any award follow the fix.","created_at":"2026-11-09T10:20:10.525207+00:00"}]}