The analysis focused on the provided commit 7292932d45d55c7199324ab0027cc86e8198aa22 for the golang/crypto repository. The commit message explicitly states: 'ssh: limit the size of the internal packet queue while waiting for KEX'. It describes that while a key exchange is in progress, packets were added to an internal queue (pendingPackets) without a limit. This could lead to high memory usage or exhaustion if the other party was slow or unresponsive during key exchange.
The diff for ssh/handshake.go shows changes primarily in the handshakeTransport struct and its methods. The key change is within the writePacket method.
Before the patch, the code was:
if t.sentInitMsg != nil {
// Copy the packet so the writer can reuse the buffer.
cp := make([]byte, len(p))
copy(cp, p)
t.pendingPackets = append(t.pendingPackets, cp)
return nil
}
This section shows that if t.sentInitMsg is not nil (meaning a key exchange is in progress), the packet p is copied and appended to t.pendingPackets without any size check on t.pendingPackets.
The patch introduces a check for len(t.pendingPackets) < maxPendingPackets and a loop that waits on t.writeCond.Wait() if the queue is full, thus mitigating the unbounded growth of pendingPackets.
Therefore, the (*handshakeTransport).writePacket function is identified as the vulnerable function because it's where the unbounded queuing of packets occurred during a pending key exchange, leading to potential DoS.