GitHub advisory · PyPI
AsyncSSH: asyncio event-loop freeze via SSH maximum packet size = 0 in SSH_MSG_CHANNEL_OPEN / OPEN_CONFIRMATION
Description
A malicious SSH server can wedge an AsyncSSH client, and an authenticated
client can wedge an AsyncSSH server, by sending a channel maximum packet size of 0 in SSH_MSG_CHANNEL_OPEN_CONFIRMATION (server→client) or
SSH_MSG_CHANNEL_OPEN (client→server). AsyncSSH stores the peer-supplied value
verbatim with no lower-bound check; the first time channel data is written,
SSHChannel._flush_send_buf enters a synchronous infinite loop that cannot
be interrupted by asyncio.wait_for or any timeout. The loop body has no
await, so it blocks the entire asyncio event loop — for a server, one
malicious authenticated channel freezes all current and future connections.
RFC 4254 §5.1 leaves receiver behavior for a peer-reported "maximum packet size = 0" undefined, so the value must be rejected rather than stored.
asyncssh/channel.py:
# process_open (server side) -- line 465
self._send_pktsize = send_pktsize # peer value, no >= 1 check
# process_open_confirmation (client) -- line 528
self._send_pktsize = send_pktsize # peer value, no >= 1 check
# _flush_send_buf -- lines 305-320
while self._send_buf and self._send_window:
pktsize = min(self._send_window, self._send_pktsize) # 0 when peer sends 0
buf, datatype = self._send_buf[0]
if len(buf) > pktsize: # True for any buffered data
data = buf[:pktsize] # empty (b'')
del buf[:pktsize] # no-op
...
self._send_window -= len(data) # -= 0, unchanged
With _send_pktsize == 0, pktsize is 0, so buf[:0] is empty,
del buf[:0] is a no-op, and _send_window is never decremented — the
while condition is permanently true, and with no await in the body the
event loop is blocked.
maximum packet size = 0; the client wedges on its first
channel write. The…Manual fix · PyPI
pip install --upgrade "asyncssh>=2.24.0"Sources