[Bug 4055] New: ssh -w tunnel disconnects with "peer ignored channel window"
bugzilla-daemon at mindrot.org
bugzilla-daemon at mindrot.org
Fri Nov 13 10:41:54 AEDT 2026
https://bugzilla.mindrot.org/show_bug.cgi?id=4055
Bug ID: 4055
Summary: ssh -w tunnel disconnects with "peer ignored channel
window"
Product: Portable OpenSSH
Version: 9.9p1
Hardware: amd64
OS: Linux
Status: NEW
Severity: normal
Priority: P5
Component: sshd
Assignee: unassigned-bugs at mindrot.org
Reporter: tpocklington at scalecomputing.com
Created attachment 4024
--> https://bugzilla.mindrot.org/attachment.cgi?id=4024&action=edit
Proposed patch: don't count datagram length headers in the window
Overview
--------
A tun forwarding channel (`ssh -w`) under sustained load is
disconnected by the side receiving most of the traffic, with OpenSSH on
both ends:
sshd: Disconnecting user root 192.168.250.1 port 55030: channel 0:
peer ignored channel window
ssh: Received disconnect from 192.168.250.2 port 22:2: channel 0:
peer ignored channel window
The two ends disagree about how much a datagram takes out of the
channel window. The sender subtracts the datagram's length N, the
receiver subtracts N + 4, and later the receiver adds N + 4 back to its
own copy and tells the sender to do the same. The sender's copy of the
window therefore gains 4 bytes per datagram. Each time the window runs
out, the sender overruns the receiver by the accumulated difference.
Once that accumulated difference is more than 10% of the window, the
receiver disconnects. This looks like the same problem reported in the
October 2025 openssh-unix-dev thread "Tunnel disconnects with 'peer
ignored channel window'". The full analysis, a patch and test results
are below.
The mismatch is old: it dates from OpenSSH 6.9 (2015). Until 9.6, the
receiver dropped the excess, logging `rcvd too much data`, and kept the
connection. The only effect was some lost tunnel packets each time the
window ran out, which TCP traffic in the tunnel recovers from by
retransmitting. 9.6 (0cb50eefd, "stricter handling of channel window
limits") made the receiver disconnect once a peer exceeds the window by
more than 10% of its maximum size. I encountered this when the
receiving side's Linux distribution moved its sshd from 8.7p1 to 9.9p1.
Steps to reproduce
------------------
With OpenSSH 9.6 or later as the receiving sshd, and traffic flowing
from the client to the server:
1. Set up an `ssh -w` tunnel: `PermitTunnel point-to-point` in the
server's sshd_config, `ssh -N -w 0:0 root at server` on the client, and
point-to-point addresses on the two tun devices.
2. Send comfortably more than 52,429 datagrams through the tunnel to
the server (UDP to the server's tunnel address, for example), at a rate
the server keeps up with, so that the window doesn't run out. Each one
puts the client's copy of the window 4 bytes further ahead of the
server's, so after 52,429 the difference is more than 209,715 bytes,
10% of the default 2 MiB window. Only the number of datagrams matters,
not their size, so small ones are quickest. The reproducer below sends
120,000.
3. Make the window run out: stop the server's sshd processes for the
connection (sshd-session, since 9.8) with SIGSTOP, and while they're
stopped, send more than the window plus that difference through the
tunnel; 4 MB is plenty. With LogLevel DEBUG1, the client logs `channel
0: datagram too big` for each datagram it drops once its copy of the
window is used up.
4. Resume the server's processes with SIGCONT. As the server reads the
backlog, it logs `channel 0: rcvd too much data N, win W/2097152
(excess M)` for each datagram beyond the window, and disconnects with
`peer ignored channel window` once M passes 209,715.
Step 3 only works if the TCP connection can hold what's sent while the
server is stopped. Otherwise the client stops reading from its tun
device before its window runs out, and nothing happens. On a fast local
link, raise the default of the client's `net.ipv4.tcp_wmem` and the
server's `net.ipv4.tcp_rmem` to 4 MiB (`4096 4194304 8388608`).
With the patch on the server, the window still runs out in step 3, but
in step 4 the server logs no overruns and the connection stays up.
The attached tarball automates these steps and checks the data that
comes through. It has the reproducer and a README with more details. To
run it on a Linux host with Docker:
tar -xzf tun-window-repro.tar.gz
cd tun-window-repro
git clone https://github.com/openssh/openssh-portable
repro/build-image.sh
repro/run.sh stock
repro/run.sh fix
`build-image.sh` builds master (1d28115e0) with and without the patch
into a container image. Each `run.sh` runs the reproducer in a
disposable privileged container, in about 30 seconds: `stock` with
master on both ends, `fix` with the patched server and a stock client.
The README shows the output to expect, and how to run the script
directly as root without Docker.
Each run puts the two ends in network namespaces joined by a veth pair,
with the TCP buffers raised, and follows the steps above: 10,000 bulk
datagrams, then 120,000 small ones (16-byte payloads), then a 2-second
stop while 4.2 MB more is sent, then 10,000 more bulk datagrams, on a
new connection if the first was lost.
Actual results
--------------
With master on both ends, the server disconnects in step 4, with the
messages above. In the reproducer's runs, it first logs 148 lines of
`channel 0: rcvd too much data N, win W/2097152 (excess M)`, with the
largest excess 210,500 bytes, just over the 209,715-byte limit. The
datagrams that were in flight at the disconnect are lost (1,758 to
1,854 per disconnect across these runs), and the client has to
reconnect.
Expected results
----------------
No overruns between two OpenSSH peers. When the window runs out, the
sender waits for window adjusts (for tun it drops the datagrams it has
no window for, by design), the receiver never receives more than it
advertised, and the connection stays up.
Build and platform
------------------
First seen with a Linux distribution's OpenSSH 9.9p1 sshd receiving
from distribution builds of OpenSSH 7.4p1 and 8.7p1, on an ssh -w
point-to-point tunnel between two Linux hosts.
Reproduced with openssh-portable master 1d28115e0 (2026-11-09) on both
ends, built against OpenSSL 3.5.7 on Debian 13 (trixie), x86_64, with
both ends in network namespaces on one host, and also with master
538af298a. All the numbers in this report are from master.
Additional builds and platforms
-------------------------------
On the same hosts and load, an 8.7p1 sshd in place of 9.9p1 (a
distribution build with no changes to window handling) logged `rcvd too
much data` each time the window ran out and dropped the excess, but
never disconnected.
Apart from those, not tested on any other release or operating system,
or with ssh as the receiver.
Additional information
----------------------
Cause. Each end keeps its own copy of the channel window. For a
datagram of N bytes:
1. Sender (`channel_output_poll_input_open()`): subtracts N from its
copy, `c->remote_window -= plen`. It has done this since f715afebe
(OpenSSH 6.9), which changed it from N + 4.
2. Receiver, on arrival (`channel_input_data()`): `win_len = data_len;
if (c->datagram) win_len += 4;`, so it subtracts N + 4 from its copy.
This came in with 7d4571894 (OpenSSH 5.6), when the sender also
subtracted N + 4.
3. Receiver, after writing the datagram out (`channel_handle_wfd()`):
`c->local_consumed += olen - sshbuf_len(c->output)`. The datagram was
queued in c->output as an SSH string, so this adds back N + 4. The next
window adjust tells the sender to add the same N + 4 back to its copy.
The receiver's copy returns to where it started, but the sender's copy
ends up 4 bytes larger per datagram. Since 9.6 (0cb50eefd) the receiver
disconnects once the excess passes `local_window_max / 10`, 209,715
bytes with the default window. That takes about 52,000 datagrams
between the times the window runs out, and then something has to make
it run out: a burst, for example, or a receiver that stalls briefly.
Removing only `win_len += 4`, as suggested in the 2025 thread, isn't
enough: the receiver then subtracts N on arrival but still adds back N
+ 4, so both copies grow by 4 bytes per datagram without bound, and
once the window passes `local_window_max` the receiver sends a window
adjust for nearly every datagram. (Tested with only that line removed;
that build isn't part of the attached reproducer.)
Patch (attached): "channels: Don't count datagram length headers in the
window". The receiver subtracts N when a datagram arrives and adds back
N once it has been written out, matching the sender. It is a
receiver-only change, so it works with every sender since 6.9.
Non-datagram channels are unaffected. It applies to 9.9p1 as well, with
line offsets only.
Results with the patch, against master 1d28115e0, stock client, server
as listed. The raw output of every run is in `results.txt` in the
tarball:
window overrun largest
server ran out lines excess disconnect
master yes 148 210,500 yes
+ patch yes 0 - no
The reproducer checks every datagram byte for byte. Across about 3.1
million, none was corrupted, duplicated or reordered, and with the
patch none was lost in the tunnel. The channel-related regression tests
pass with and without the patch.
Compatibility. Senders from OpenSSH 6.8 and earlier subtract N + 4. A
receiver with the patch adds back only N, so those senders' copy of the
window shrinks 4 bytes per datagram, and the channel stalls after about
2 MiB / 4 datagrams. In a test with master's sender changed to subtract
N + 4 (not part of the attached reproducer), the tunnel stopped after
about 500,000 datagrams, with nothing corrupted or lost. Against a
stock receiver it is fine. Not tested against a real 6.8 or older
sender. If that matters, the receiver could keep the +4 for those peers
through a compat flag.
--
You are receiving this mail because:
You are watching the assignee of the bug.
More information about the openssh-bugs
mailing list