diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2020-09-20 05:47:26 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2020-09-20 05:47:26 +0000 |
commit | 6c3d69ff34d5199c48c9088ab9e76a264d47a097 (patch) | |
tree | 7646c2ef1236477128d2dafe3501925367f31336 /usr.bin/ssh | |
parent | c58ba806fcd4cba57ac8c3eb2d2f006daed3d83f (diff) |
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@
Diffstat (limited to 'usr.bin/ssh')
-rw-r--r-- | usr.bin/ssh/channels.c | 5 | ||||
-rw-r--r-- | usr.bin/ssh/channels.h | 5 |
2 files changed, 8 insertions, 2 deletions
diff --git a/usr.bin/ssh/channels.c b/usr.bin/ssh/channels.c index fbb2fce445c..b678f973e6c 100644 --- a/usr.bin/ssh/channels.c +++ b/usr.bin/ssh/channels.c @@ -1,4 +1,4 @@ -/* $OpenBSD: channels.c,v 1.401 2020/07/03 07:25:18 djm Exp $ */ +/* $OpenBSD: channels.c,v 1.402 2020/09/20 05:47:25 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -344,6 +344,7 @@ channel_new(struct ssh *ssh, char *ctype, int type, int rfd, int wfd, int efd, struct ssh_channels *sc = ssh->chanctxt; u_int i, found; Channel *c; + int r; /* Try to find a free slot where to put the new channel. */ for (i = 0; i < sc->channels_alloc; i++) { @@ -373,6 +374,8 @@ channel_new(struct ssh *ssh, char *ctype, int type, int rfd, int wfd, int efd, (c->output = sshbuf_new()) == NULL || (c->extended = sshbuf_new()) == NULL) fatal("%s: sshbuf_new failed", __func__); + if ((r = sshbuf_set_max_size(c->input, CHAN_INPUT_MAX)) != 0) + fatal("%s: sshbuf_set_max_size: %s", __func__, ssh_err(r)); c->ostate = CHAN_OUTPUT_OPEN; c->istate = CHAN_INPUT_OPEN; channel_register_fds(ssh, c, rfd, wfd, efd, extusage, nonblock, 0); diff --git a/usr.bin/ssh/channels.h b/usr.bin/ssh/channels.h index 0abaec88720..262a59179ea 100644 --- a/usr.bin/ssh/channels.h +++ b/usr.bin/ssh/channels.h @@ -1,4 +1,4 @@ -/* $OpenBSD: channels.h,v 1.134 2020/07/05 23:59:45 djm Exp $ */ +/* $OpenBSD: channels.h,v 1.135 2020/09/20 05:47:25 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> @@ -220,6 +220,9 @@ struct Channel { /* Read buffer size */ #define CHAN_RBUF (16*1024) +/* Maximum channel input buffer size */ +#define CHAN_INPUT_MAX (16*1024*1024) + /* Hard limit on number of channels */ #define CHANNELS_MAX_CHANNELS (16*1024) |