Skip to content

Commit a8610f7

Browse files
committed
Don't limit channel window to 500MB
Previously the channel window and increments were limited to 500MB. That is incorrect and causes stuck connections if peers advertise a large window, then don't send an increment within the first 500MB. That's seen with SSH.NET sshnet/SSH.NET#1671
1 parent 1610699 commit a8610f7

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/common-channel.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -858,17 +858,21 @@ void common_recv_msg_channel_data(struct Channel *channel, int fd,
858858
void recv_msg_channel_window_adjust() {
859859

860860
struct Channel * channel;
861-
unsigned int incr;
861+
unsigned int incr, newwin;
862862

863863
channel = getchannel();
864864

865865
incr = buf_getint(ses.payload);
866-
TRACE(("received window increment %d", incr))
867-
incr = MIN(incr, TRANS_MAX_WIN_INCR);
866+
TRACE(("received window increment %u", incr))
868867

869-
channel->transwindow += incr;
870-
channel->transwindow = MIN(channel->transwindow, TRANS_MAX_WINDOW);
871-
868+
newwin = channel->transwindow + incr;
869+
if (newwin < channel->transwindow) {
870+
/* Integer overflow, clamp it at maximum.
871+
* Behaviour may be unexpected, senders MUST NOT overflow per rfc4254. */
872+
TRACE(("overflow window, prev %u", channel->transwindow));
873+
newwin = 0xffffffff;
874+
}
875+
channel->transwindow = newwin;
872876
}
873877

874878
/* Increment the incoming data window for a channel, and let the remote
@@ -906,7 +910,6 @@ void recv_msg_channel_open() {
906910

907911
remotechan = buf_getint(ses.payload);
908912
transwindow = buf_getint(ses.payload);
909-
transwindow = MIN(transwindow, TRANS_MAX_WINDOW);
910913
transmaxpacket = buf_getint(ses.payload);
911914
transmaxpacket = MIN(transmaxpacket, TRANS_MAX_PAYLOAD_LEN);
912915

src/sysoptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@
243243
#define RECV_MAX_PACKET_LEN (MAX(35000, ((RECV_MAX_PAYLOAD_LEN)+100)))
244244

245245
/* for channel code */
246-
#define TRANS_MAX_WINDOW 500000000 /* 500MB is sufficient, stopping overflow */
247-
#define TRANS_MAX_WIN_INCR 500000000 /* overflow prevention */
248-
249246
#define RECV_WINDOWEXTEND (opts.recv_window / 3) /* We send a "window extend" every
250247
RECV_WINDOWEXTEND bytes */
251248
#define MAX_RECV_WINDOW (10*1024*1024) /* 10 MB should be enough */

0 commit comments

Comments
 (0)