From 0ec0fae1106f9e3bbe725c7e2e851b4253da6917 Mon Sep 17 00:00:00 2001 From: Troy Pocklington Date: Wed, 28 Oct 2026 16:40:15 -0500 Subject: [PATCH] channels: Don't count datagram length headers in the window When a datagram (tun) channel's sender sends a datagram, it subtracts the datagram's length from its copy of the window. When the datagram arrives, the receiver subtracts its length plus 4 from its own copy, for the length header it is queued with in c->output. Once the datagram has been written out, the receiver adds the same length plus 4 back, and tells the sender to add it back too. So the receiver's copy returns to where it was, but the sender's copy ends up 4 bytes larger for every datagram. The difference accumulates until the window next runs out, when the sender sends up to that much more than the receiver will accept. Before OpenSSH 9.6 the receiver dropped the excess ("rcvd too much data"). Since 9.6 it disconnects with "peer ignored channel window" once the excess passes 10% of the window, which with the default window takes about 52,000 datagrams between the times it runs out. Count only the datagram itself, both when it arrives and when it is added back, as the sender does. --- channels.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/channels.c b/channels.c index 4ac7d98ee..6843b9766 100644 --- a/channels.c +++ b/channels.c @@ -2441,7 +2441,13 @@ channel_handle_wfd(struct ssh *ssh, Channel *c) if ((r = sshbuf_consume(c->output, len)) != 0) fatal_fr(r, "channel %i: consume", c->self); out: - c->local_consumed += olen - sshbuf_len(c->output); + /* + * Datagrams are queued in c->output as SSH strings. The peer did + * not subtract their 4-byte length header from the window, so + * don't add it back to the window either. + */ + c->local_consumed += olen - sshbuf_len(c->output) - + (c->datagram ? 4 : 0); return 1; } @@ -3610,8 +3616,6 @@ channel_input_data(int type, uint32_t seq, struct ssh *ssh) fatal_fr(r, "channel %i: get data", c->self); win_len = data_len; - if (c->datagram) - win_len += 4; /* string length header */ /* * The sending side reduces its window as it sends data, so we -- 2.56.0