net/sync: syncTracker recreates per-peer state after removePeer, leaking a full frontier map per throwaway peer ID
Report
Summary
syncTracker.recordSync stores a full copy of the local frontier map keyed by peer ID without checking that the connection still exists. removePeer is called only from DisconnectedF, so a disconnect that happens while requestSync is still running removes the entry first and the later recordSync recreates it. No second DisconnectedF fires for that peer ID, so the copy survives for the process lifetime. The window is not a narrow race: the apply phase (up to 10 retries over up to 10,000 blocks) runs before recordSync and performs no network I/O, so the peer can disconnect at leisure while the node applies attacker-chosen blocks. recordRejections has the same shape with a narrower window.
Affected code
| Location | Fact |
|---|---|
net/sync.go:70-72,84-86 |
lastFrontiers map[peer.ID]map[string]string and initialisation |
net/sync.go:127-136 |
recordSync copies the whole frontier map and assigns st.lastFrontiers[pid] = cp, no liveness check |
net/sync.go:145-150 |
removePeer — the only cleaner (delete over three maps) |
net/sync.go:320-342 |
ConnectedF → requestSync → recordSync (336); DisconnectedF → removePeer (341) |
net/sync.go:345-376 |
periodic resync path, second recordSync call site (376) |
net/sync.go:602-604,648 |
apply loop of up to 10 passes over up to 10,000 blocks; requestSync always returns nil |
net/messages.go:21-26, net/sync.go:556-563 |
SyncResponse.Rejected []string has no element/length bound (up to 10 MB decoded per page) |
Reproduction
- Connect to a node with a fresh libp2p identity (identities are free; connection limits are per IP, so a handful of identities suffice).
- Serve a terminal page plus blocks so the apply loop runs, then close the connection during the apply phase.
DisconnectedF→removePeer(pid)runs first;recordSync(pid, ledger.Frontiers())then resurrectslastFrontiers[pid].- Repeat with new peer IDs; each iteration leaves one full frontier-map copy that nothing can delete.
Evidence
- No liveness guard in
recordSync(net/sync.go:127-136). removePeerhas exactly one call site (net/sync.go:341); no other path deletes these entries.- Harness result on the pinned commit: two leak assertions FAIL (state resurrected for a disconnected peer) and two control assertions PASS (full-copy-per-peer confirmed; healthy delete confirmed).
- Per-identity cost measured on the same scratch harness:
recordSync≈ 82.6 KB at a 1,000-account lattice and ≈ 1.31 MB at 20,000 accounts (≈ 65 B per entry); theRejectedamplification path ≈ 5.75 MB per identity with 50,000 attacker-chosen strings.
Impact
Monotonic, attacker-paced memory growth on every syncing node, keyed on identities that cost nothing to mint. Enough identities exhaust RAM; the state persists until restart.
Suggested fix
Check connection liveness inside recordSync (or gate it on a disconnect generation counter), bound the Rejected list length, and make the disconnect handler authoritative regardless of callback ordering.
Notes
- Duplicate check: checked issues — no duplicate as of 2026-11-11 (closest: #59 in-flight guard OOM within one round, #44 per-round page allocation, #254/#265 dirty-flag poisoning via
MarkDirtyFromPeer, #219/#245 truncation/retry, #223recordSynctiming semantics; none covers state resurrected afterremovePeer). - Evidence status: code-level plus scratch harness heap measurements; no end-to-end run against the live testnet.
- XE Address for Reward:
b83e7e31358b8c1e1509de6cd34e7540425eb17a190e48b486909df11080033d
Reward address updated to the official desk-bound address.
Thread
Thanks for the report. We have read it against the code and it is being handled. The assessment and any award follow the fix.
Thanks for the update, I'll wait for the fix and assessment