SSH Gateway Connection Pool Starvation: handleDirectTCPIP lacks read/idle timeouts permitting permanent semaphore DoS
Report
Vulnerability Summary
In node/ssh_gateway.go:179-209, SSHGateway.handleDirectTCPIP handles SSH port forwarding channels to tunnel consumer traffic to provider VMs:
func (gw *SSHGateway) handleDirectTCPIP(channel ssh.Channel, lease *core.Lease) {
defer func() { _ = channel.Close() }()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
...
tunnel, err := gw.backend.OpenTunnel(ctx, providerPeer, lease.LeaseHash)
if err != nil {
return
}
defer func() { _ = tunnel.Close() }()
var wg sync.WaitGroup
wg.Add(2)
go func() { defer wg.Done(); _, _ = io.Copy(channel, tunnel) }()
go func() { defer wg.Done(); _, _ = io.Copy(tunnel, channel) }()
wg.Wait()
}
The gateway constrains total concurrent connections via a semaphore channel with a static capacity:
const maxSSHConnections = 100
...
connSem: make(chan struct{}, maxSSHConnections),
The tunnel forwarding goroutines io.Copy(channel, tunnel) and io.Copy(tunnel, channel) do not enforce any read/write deadlines, idle timeouts, or keepalive heartbeats. If a client opens an SSH direct-tcpip channel and ceases transmitting data (or half-closes the connection), wg.Wait() blocks indefinitely.
Because gw.connSem has only 100 slots, an attacker (or slow/hanging consumer clients) holding 100 idle TCP connections will exhaust the connection pool. Subsequent connection attempts block or fail, completely preventing all legitimate consumers from accessing their active VMs.
Root Cause Analysis
- Absence of Idle Deadline:
io.Copyperforms blocking reads without TCP keep-alive or application-level idle timers. - Unbounded WaitGroup Blocking:
wg.Wait()hangs forever if neither side sends an EOF or closes the channel. - Global Semaphore Depletion: Each connection consumes 1 of 100
connSemslots. Holding 100 idle channels permanently starves the gateway.
Proposed Remediation
- Implement an idle timeout on the underlying tunnel and channel (e.g. 15 minutes of inactivity triggers context cancellation).
- Configure TCP keepalive probes on
net.Conninstances. - Automatically terminate sessions when leases settle, cancel, or expire.
Thread
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-10005 and says what differs; it is read like any other.