Bounty
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

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 Denneteam2026-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.