<!-- XE-10126 · P2P Inbound Connection Overflow: NetworkGater.InterceptSecured time-of-check to time-of-use race permits unbounded connection exhaustion · testnet -->
*Markdown view of <https://bounty.xe.network/XE-10126>. The page is the record; this is the same page for reading.*

XE-10126 · Bounty

# P2P Inbound Connection Overflow: NetworkGater.InterceptSecured time-of-check to time-of-use race permits unbounded connection exhaustion

Closed · duplicate
—
web
filed 2026-11-12 10:07 UTC
by xe:e4cd6974

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   P2P / sync

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 00:33 UTC

Told
:   2026-11-20 00:33 UTC

### Patches

None linked.

### History

- [552459](https://bounty.xe.network/log/552459) 2026-11-20 00:33 UTC proposal.adopted
- [552458](https://bounty.xe.network/log/552458) 2026-11-20 00:33 UTC reply.sent
- [552457](https://bounty.xe.network/log/552457) 2026-11-20 00:33 UTC ticket.status new → closed
- [551850](https://bounty.xe.network/log/551850) 2026-11-20 00:33 UTC proposal.adopted
- [551849](https://bounty.xe.network/log/551849) 2026-11-20 00:33 UTC ticket.facts area
- [551848](https://bounty.xe.network/log/551848) 2026-11-20 00:33 UTC proposal.adopted
- [551847](https://bounty.xe.network/log/551847) 2026-11-20 00:33 UTC ticket.facts
- [551846](https://bounty.xe.network/log/551846) 2026-11-20 00:33 UTC proposal.adopted
- [551845](https://bounty.xe.network/log/551845) 2026-11-20 00:33 UTC ticket.facts
- [550939](https://bounty.xe.network/log/550939) 2026-11-20 00:31 UTC note.added
- [550938](https://bounty.xe.network/log/550938) 2026-11-20 00:31 UTC proposal.created
- [550937](https://bounty.xe.network/log/550937) 2026-11-20 00:31 UTC proposal.created

[Full history](https://bounty.xe.network/log?ref=XE-10126) · [JSON](https://bounty.xe.network/v1/tickets/XE-10126) · [markdown](https://bounty.xe.network/XE-10126.md)

### Report

## Vulnerability Summary

In `net/netcheck.go:310-350`, `NetworkGater` manages connection limits for inbound peers:

```
func (g *NetworkGater) InterceptSecured(dir network.Direction, p peer.ID, _ network.ConnMultiaddrs) bool {
	if g.isBanned(p) {
		return false
	}

	if dir == network.DirInbound && !g.isTrusted(p) {
		max := atomic.LoadInt64(&g.maxInbound)
		if max > 0 && g.inbound.Load() >= max {
			g.inboundRefused.Add(1)
			return false
		}
	}
	return true
}

// ConnectedF increments inbound count only AFTER handshake and negotiation complete
	h.Network().Notify(&network.NotifyBundle{
		ConnectedF: func(_ network.Network, conn network.Conn) {
			if conn.Stat().Direction == network.DirInbound {
				gater.inbound.Add(1)
			}
			go verifyPeer(h, conn.RemotePeer(), gater)
		},
		DisconnectedF: func(_ network.Network, conn network.Conn) {
			if conn.Stat().Direction == network.DirInbound {
				if gater.inbound.Add(-1) < 0 {
					gater.inbound.Store(0)
				}
			}
		},
	})
```

A critical Time-of-Check to Time-of-Use (TOCTOU) concurrency vulnerability exists:

1. Non-Atomic Check: In `InterceptSecured`, `g.inbound.Load() >= max` reads the current count, but does not atomically reserve or increment a connection slot.
2. 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.
3. 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).

As a result, all connections pass the security gater check. Once upgraded, `ConnectedF` runs repeatedly, blowing past `defaultMaxInboundConns` without constraint.

## Impact \& Severity

1. File Descriptor \& Socket Starvation: Thousands of unauthorized concurrent libp2p connections saturate host file descriptors (`EMFILE`) and kernel TCP buffers.
2. Memory Exhaustion: Each established peer session allocates multiplexer buffers (yamux/mplex), exhausting validator RAM and triggering kernel OOM termination.
3. Consensus \& Sync Disruption: Legitimate validators and timekeepers are unable to dial or maintain P2P gossip streams with the node.

## Proposed Remediation

1. Atomically reserve slots in `InterceptSecured`:

   ```
   if dir == network.DirInbound && !g.isTrusted(p) {
       max := atomic.LoadInt64(&g.maxInbound)
       if max > 0 {
           if cur := g.inbound.Add(1); cur > max {
               g.inbound.Add(-1)
               g.inboundRefused.Add(1)
               return false
           }
       }
   }
   ```
2. Remove the delayed increment from `ConnectedF` and ensure that `DisconnectedF` (or handshake failure) decrements the counter reliably.

### Thread

**Joseph Denne**team2026-11-20 00:33 UTCdesk

Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the
first verifiable submission, so this one closes as a duplicate. If you believe it is a different
bug, file a new report that links https://bounty.xe.network/XE-10126 and says what differs; it is read like any other.
