{"id":"XE-0114","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"191","source_url":"https://github.com/xeprotocol/xe/issues/191","reporter_id":36,"title":"[Node/VM] Provider restart destroys VMs backing live Accepted leases — both VM backends reap every instance at startup with no ledger reconciliation, and nothing re-provisions them","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":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:29.244997+00:00","updated_at":"2026-11-10T00:11:48.904477+00:00","source_created_at":"2026-10-29T10:52:39+00:00","told_at":"2026-11-08T20:18:56+00:00","status_changed_at":"2026-11-08T20:17:47.677040+00:00","url":"https://bounty.xe.network/XE-0114","body":"Suggested severity: Medium (2,500 XE)\nArea: node / VM lifecycle (vm/lima_manager.go, vm/qemu_manager.go, node lease watch)\nRepo pin: 9787859 (testnet-0005)\n\n## Summary\n\nA provider node's VM managers destroy the VMs of still-live Accepted leases at every startup, and nothing ever re-provisions them. Both backends reap unconditionally at manager construction, with no check against ledger lease state:\n\n- Lima: NewLimaManager calls cleanOrphans() (vm/lima_manager.go:85, defined :325), which lists instances via limactl and issues stop + delete --force for EVERY instance whose name has the prefix xe- — including instances backing leases that are Accepted and mid-term on-chain. The manager takes no ledger input at all.\n- QEMU: NewQEMUManager likewise calls cleanOrphans() (vm/qemu_manager.go, in the constructor), which SIGKILLs every qemu-system process matching the node's workRoot — again including VMs backing live Accepted leases.\n\nThe loss is permanent for the lease term: VM registries are in-memory only, and the node's lease loop never reconciles them against the ledger. leaseWatchTick (node/node.go:1670) only auto-accepts UNACCEPTED leases — Accepted leases are explicitly skipped (leaseAlreadyAccepted) — and provisionVM's only call site is the accept path (node/node.go:1554, inside autoAcceptLease). No startup or periodic path re-registers or re-provisions a VM for an already-Accepted lease.\n\n## Mechanism\n\n1. Provider runs normally; one or more leases are Accepted; VMs are running (Lima instances named xe-<leasehash12>, or daemonized QEMU processes under the node's workRoot).\n2. The node process restarts — upgrade, crash recovery, host reboot, operator restart. This is a routine operational event, not an attack.\n3. Manager construction reaps every existing VM of both backends unconditionally (details above). No code compares the instance/process list against ledger lease state (Created/Accepted/Settled/Cancelled) before reaping.\n4. After startup, the ledger still shows the leases as Accepted (they are), but their VMs are gone. leaseWatchTick skips them as already-accepted; settle/teardown bookkeeping iterates the fresh (empty) registry and can no longer reach them either.\n5. The consumer's paid service is silently gone for the remainder of the lease term; escrow unwinds only at expiry/settle per the normal schedule.\n\n## Trigger\n\nA single ordinary provider restart. No attacker action, no malformed input, no race. The defect is the absence of startup reconciliation between the VM layer and ledger lease state.\n\n## Proof of concept\n\nExercised in a scratch copy of the pinned tree (repo tree left clean); independently re-run and reproduced by the reporter:\n\n- Lima (load-bearing): TestSeg1DRun105LimaRestartDeletesLiveVMs stands up the REAL NewLimaManager against a fake limactl that reports a Running xe- instance and a non-xe instance. Construction issues stop + delete --force for the xe- instance (the manager log prints \"Cleaning orphaned Lima VM: xe-abcdef123456 (status: Running)\") and leaves the non-xe instance untouched (negative control). PASS.\n- Registry loss: TestSeg1DRun105RegistryLossAcrossRestart — a fresh manager over the same world lists 0 VMs and teardown of a pre-restart lease fails as not-found. PASS.\n- QEMU kill-at-construction is established by direct code read (cleanOrphans SIGKILLs workRoot-matching qemu processes from the constructor); it is not separately executed in the PoC.\n\nReproduce: `go test ./vm -run TestSeg1DRun105 -count=1 -v`\n\n## Impact\n\n- Consumers: a paid, Accepted lease loses its VM — and therefore the leased service — for the rest of its term after any provider restart, with no on-chain signal that anything is wrong (the lease remains Accepted).\n- Providers: honest providers silently break live service obligations on every routine restart (upgrades included), and lose teardown/reachability for those leases afterwards.\n- The defect fires on 100% of restarts for 100% of live leases on the affected provider; it is not a race or an edge case.\n\n## Honest limits\n\n- The trigger is the provider's own restart (a routine event), not a remote attacker action. The claim is an implementation correctness/availability defect in the node software, in the same family as other accepted node-behaviour reports (e.g. #60 shutdown handling, #161 vote-store growth).\n- Proven locally (real manager construction + fake limactl; code read for QEMU). No live provider was restarted and no live lease was harmed.\n- No claim is made that a provider can profit from this: any settle-after-destruction question belongs to the already-reported settle-validation reports (#90/#21) and is NOT relied on here.\n\n## Duplicate check\n\nNo match. Live searches on 2026-10-29: \"cleanOrphans\" 0 results; \"reprovision\" 0 results; \"lima\" 1 result (#154, tunnel access control — different mechanism); \"orphan\"/\"restart\" neighbours are #60 (SIGTERM during sync hangs shutdown — different), #161 (gossiped-vote store growth — different), #51 (DAO vote replay cache — different). Distinct from #90/#21 (ledger settle-validation gaps; this is node VM-lifecycle reconciliation — different deviation source, different remediation), from #4/#154/#104 (tunnel/SSH access control), and from #38/#43 (ledger conflict unwinds).\n\n## Suggested fix\n\nAt manager construction, reconcile before reaping: cross-check discovered instances/processes against ledger lease state and reap only those whose lease is terminal (Settled/Cancelled/expired) or unknown to the ledger; adopt or re-provision VMs backing Accepted leases (rebuild the registry from ledger state), so a restart is transparent to live leases.\n\n## Reporter\n\nXE payout address: 24b1be6a99de922902aceccce2456abc3769e4ab1cac463ea86fb23496b868b3\nDiscovered: 2026-10-29, against the public testnet implementation at the pinned commit. Reproduction was local only; no other users' funds, keys or workloads were touched.","patch_refs":[{"id":186,"repo":"xeprotocol/xe","kind":"pr","ref":"192","title":"fix(vm/node): adopt running VMs and reconcile active leases across provider restarts (fixes #191)","url":"https://github.com/xeprotocol/xe/pull/192","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":1165,"source":"github","source_ref":"6726597217","author":"Joseph Denne","team":true,"body":"Thank you for the report. We have confirmed the behaviour you describe in the provider's VM lifecycle and it is being handled; we will update this ticket as the fix progresses.","created_at":"2026-11-08T20:18:56+00:00"},{"id":3139,"source":"github","source_ref":"6787323134","author":"zafrans","team":false,"body":"**Payout address update**\n\nHi team — a quick addition to this report.\n\nThis report did not list a payout address. For the record, my XE payout address for this report is:\n\n`5dc48847412ffe94e4f7097b81ee111b9e207b47c9c1f3bab988f08b63bcc7e3`\n\nPlease use this address for any award for this report. I am posting the same update on my other reports (#175, #183, #184, #191). Thank you.","created_at":"2026-11-11T04:49:02+00:00"},{"id":3140,"source":"github","source_ref":"6787341219","author":"zafrans","team":false,"body":"Small correction to my comment above: this report did list the previous payout address (`24b1be6a99de922902aceccce2456abc3769e4ab1cac463ea86fb23496b868b3`) in its Reporter section. That address is no longer accessible to me — please disregard it and use `5dc48847412ffe94e4f7097b81ee111b9e207b47c9c1f3bab988f08b63bcc7e3` for any award for this report, as stated above. Sorry for the confusion.","created_at":"2026-11-11T04:50:20+00:00"},{"id":3141,"source":"github","source_ref":"6829657711","author":"Reyzz95","team":false,"body":"Still reproduces at HEAD `89a542e` (testnet-0005, 2026-11-10).\n\n`NewLimaManager` still calls `cleanOrphans()` (deletes every `xe-`-prefixed Lima instance) and `NewQEMUManager` likewise kills every qemu process under the work root. After a provider restart the in-memory VM map is empty, so every pre-restart VM is an orphan. `Node.Stop()` tears down nothing and re-provisions nothing on start — VMs backing live Accepted leases are destroyed.","created_at":"2026-11-12T16:37:14+00:00"},{"id":20624,"source":"github","source_ref":"7121268897","author":"kinoy-1","team":false,"body":"Additional trigger for the same root cause (settle pays on time alone; no VM-existence / liveness reconciliation) — found while re-auditing at HEAD `8cc209d` (testnet-0006):\n\nThe VM can die *without* any provider restart, and nothing notices:\n\n- `Lima Get()`/`List()` (`vm/lima_manager.go:199-229`) and QEMU `Get()`/`List()` (`vm/qemu_manager.go:312-340`) return the stored `\"running\"` status with no process/instance liveness check, and no ticker ever re-checks VM health.\n- So a guest panic, an OOM-kill, or a manual `limactl stop`/`kill` of the guest leaves the lease `Accepted` with a dead VM, and settle still pays the full `LeaseTotalEmission` on time alone (`node/node.go:2030-2040`, `core/ledger.go:2252+`); cancel after a finalized accept is refused (`core/ledger.go:1883-1924`).\n\n#191 proves the restart trigger; this is the same defect with a wider trigger set (any guest death, not just restart). No new issue filed — recording here as evidence for this report.\n\nPayout address (reporter kinoy-1): `19f0b012f28b5954679765cad3c5795380fabec1f050f7a57e1f4dc34caf13c7`","created_at":"2026-11-24T03:37:24+00:00"}]}