{"id":"XE-10126","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":730,"title":"P2P Inbound Connection Overflow: NetworkGater.InterceptSecured time-of-check to time-of-use race permits unbounded connection exhaustion","area":"p2p-sync","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-12T10:07:41.348030+00:00","updated_at":"2026-11-20T00:33:18.792007+00:00","source_created_at":null,"told_at":"2026-11-20T00:33:18.832488+00:00","status_changed_at":"2026-11-20T00:33:18.799031+00:00","url":"https://bounty.xe.network/XE-10126","body":"## Vulnerability Summary\n\nIn `net/netcheck.go:310-350`, `NetworkGater` manages connection limits for inbound peers:\n\n```go\nfunc (g *NetworkGater) InterceptSecured(dir network.Direction, p peer.ID, _ network.ConnMultiaddrs) bool {\n\tif g.isBanned(p) {\n\t\treturn false\n\t}\n\n\tif dir == network.DirInbound && !g.isTrusted(p) {\n\t\tmax := atomic.LoadInt64(&g.maxInbound)\n\t\tif max > 0 && g.inbound.Load() >= max {\n\t\t\tg.inboundRefused.Add(1)\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\n// ConnectedF increments inbound count only AFTER handshake and negotiation complete\n\th.Network().Notify(&network.NotifyBundle{\n\t\tConnectedF: func(_ network.Network, conn network.Conn) {\n\t\t\tif conn.Stat().Direction == network.DirInbound {\n\t\t\t\tgater.inbound.Add(1)\n\t\t\t}\n\t\t\tgo verifyPeer(h, conn.RemotePeer(), gater)\n\t\t},\n\t\tDisconnectedF: func(_ network.Network, conn network.Conn) {\n\t\t\tif conn.Stat().Direction == network.DirInbound {\n\t\t\t\tif gater.inbound.Add(-1) < 0 {\n\t\t\t\t\tgater.inbound.Store(0)\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t})\n```\n\nA critical Time-of-Check to Time-of-Use (TOCTOU) concurrency vulnerability exists:\n1. Non-Atomic Check: In `InterceptSecured`, `g.inbound.Load() >= max` reads the current count, but does not atomically reserve or increment a connection slot.\n2. Deferred Accounting: `gater.inbound.Add(1)` is only executed in the asynchronous `ConnectedF` notification bundle *after* the connection completes transport security (TLS/Noise) and stream multiplexer negotiation.\n3. Concurrency Burst Bypass: When an attacker initiates hundreds or thousands of simultaneous TCP connections, all concurrent connections evaluate `InterceptSecured` before any of them trigger `ConnectedF`. At evaluation time, `g.inbound.Load()` remains below `maxInbound` (default 256).\n\nAs a result, all connections pass the security gater check. Once upgraded, `ConnectedF` runs repeatedly, blowing past `defaultMaxInboundConns` without constraint.\n\n## Impact & Severity\n\n1. File Descriptor & Socket Starvation: Thousands of unauthorized concurrent libp2p connections saturate host file descriptors (`EMFILE`) and kernel TCP buffers.\n2. Memory Exhaustion: Each established peer session allocates multiplexer buffers (yamux/mplex), exhausting validator RAM and triggering kernel OOM termination.\n3. Consensus & Sync Disruption: Legitimate validators and timekeepers are unable to dial or maintain P2P gossip streams with the node.\n\n## Proposed Remediation\n\n1. Atomically reserve slots in `InterceptSecured`:\n   ```go\n   if dir == network.DirInbound && !g.isTrusted(p) {\n       max := atomic.LoadInt64(&g.maxInbound)\n       if max > 0 {\n           if cur := g.inbound.Add(1); cur > max {\n               g.inbound.Add(-1)\n               g.inboundRefused.Add(1)\n               return false\n           }\n       }\n   }\n   ```\n2. Remove the delayed increment from `ConnectedF` and ensure that `DisconnectedF` (or handshake failure) decrements the counter reliably.","patch_refs":[],"thread":[{"id":13218,"source":"desk","source_ref":"reply:11240","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-10126 and says what differs; it is read like any other.","created_at":"2026-11-20T00:33:18.792007+00:00"}]}