summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-09-20 05:47:25 +0000
committerDamien Miller <djm@mindrot.org>2020-09-20 16:16:46 +1000
commit107eb3eeafcd390e1fa7cc7672a05e994d14013e (patch)
treeb7957a7b8b6e4ff24a31de33b7ce537e509e8c4b
parentacfe2ac5fe033e227ad3a56624fbbe4af8b5da04 (diff)
upstream: cap channel input buffer size at 16MB; avoids high memory use
when peer advertises a large window but is slow to consume the data we send (e.g. because of a slow network) reported by Pierre-Yves David fix with & ok markus@ OpenBSD-Commit-ID: 1452771f5e5e768876d3bfe2544e3866d6ade216
-rw-r--r--channels.c5
-rw-r--r--channels.h5
2 files changed, 8 insertions, 2 deletions
diff --git a/channels.c b/channels.c
index 71c94f6cc..e4917f3c9 100644
--- a/channels.c
+++ b/channels.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.c,v 1.401 2020/07/03 07:25:18 djm Exp $ */ 1/* $OpenBSD: channels.c,v 1.402 2020/09/20 05:47:25 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -354,6 +354,7 @@ channel_new(struct ssh *ssh, char *ctype, int type, int rfd, int wfd, int efd,
354 struct ssh_channels *sc = ssh->chanctxt; 354 struct ssh_channels *sc = ssh->chanctxt;
355 u_int i, found; 355 u_int i, found;
356 Channel *c; 356 Channel *c;
357 int r;
357 358
358 /* Try to find a free slot where to put the new channel. */ 359 /* Try to find a free slot where to put the new channel. */
359 for (i = 0; i < sc->channels_alloc; i++) { 360 for (i = 0; i < sc->channels_alloc; i++) {
@@ -383,6 +384,8 @@ channel_new(struct ssh *ssh, char *ctype, int type, int rfd, int wfd, int efd,
383 (c->output = sshbuf_new()) == NULL || 384 (c->output = sshbuf_new()) == NULL ||
384 (c->extended = sshbuf_new()) == NULL) 385 (c->extended = sshbuf_new()) == NULL)
385 fatal("%s: sshbuf_new failed", __func__); 386 fatal("%s: sshbuf_new failed", __func__);
387 if ((r = sshbuf_set_max_size(c->input, CHAN_INPUT_MAX)) != 0)
388 fatal("%s: sshbuf_set_max_size: %s", __func__, ssh_err(r));
386 c->ostate = CHAN_OUTPUT_OPEN; 389 c->ostate = CHAN_OUTPUT_OPEN;
387 c->istate = CHAN_INPUT_OPEN; 390 c->istate = CHAN_INPUT_OPEN;
388 channel_register_fds(ssh, c, rfd, wfd, efd, extusage, nonblock, 0); 391 channel_register_fds(ssh, c, rfd, wfd, efd, extusage, nonblock, 0);
diff --git a/channels.h b/channels.h
index ee818880e..74e9b3f87 100644
--- a/channels.h
+++ b/channels.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: channels.h,v 1.134 2020/07/05 23:59:45 djm Exp $ */ 1/* $OpenBSD: channels.h,v 1.135 2020/09/20 05:47:25 djm Exp $ */
2 2
3/* 3/*
4 * Author: Tatu Ylonen <ylo@cs.hut.fi> 4 * Author: Tatu Ylonen <ylo@cs.hut.fi>
@@ -223,6 +223,9 @@ struct Channel {
223/* Read buffer size */ 223/* Read buffer size */
224#define CHAN_RBUF (16*1024) 224#define CHAN_RBUF (16*1024)
225 225
226/* Maximum channel input buffer size */
227#define CHAN_INPUT_MAX (16*1024*1024)
228
226/* Hard limit on number of channels */ 229/* Hard limit on number of channels */
227#define CHANNELS_MAX_CHANNELS (16*1024) 230#define CHANNELS_MAX_CHANNELS (16*1024)
228 231