summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-01-22 22:58:50 +0000
committerDamien Miller <djm@mindrot.org>2019-01-23 10:44:34 +1100
commitd691588b8e29622c66abf8932362b522cf7f4051 (patch)
tree38473381f76258ceb0bae3c977b8dcb2b5d2eaee
parentf99ef8de967949a1fc25a5c28263ea32736e5943 (diff)
upstream: backoff reading messages from active connections when the
input buffer is too full to read one, or if the output buffer is too full to enqueue a response; feedback & ok dtucker@ OpenBSD-Commit-ID: df3c5b6d57c968975875de40d8955cbfed05a6c8
-rw-r--r--ssh-agent.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/ssh-agent.c b/ssh-agent.c
index 6baebc313..d06ecfd98 100644
--- a/ssh-agent.c
+++ b/ssh-agent.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ssh-agent.c,v 1.232 2018/11/09 02:57:58 djm Exp $ */ 1/* $OpenBSD: ssh-agent.c,v 1.233 2019/01/22 22:58:50 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
@@ -96,6 +96,8 @@
96 96
97/* Maximum accepted message length */ 97/* Maximum accepted message length */
98#define AGENT_MAX_LEN (256*1024) 98#define AGENT_MAX_LEN (256*1024)
99/* Maximum bytes to read from client socket */
100#define AGENT_RBUF_LEN (4096)
99 101
100typedef enum { 102typedef enum {
101 AUTH_UNUSED, 103 AUTH_UNUSED,
@@ -839,7 +841,7 @@ handle_socket_read(u_int socknum)
839static int 841static int
840handle_conn_read(u_int socknum) 842handle_conn_read(u_int socknum)
841{ 843{
842 char buf[1024]; 844 char buf[AGENT_RBUF_LEN];
843 ssize_t len; 845 ssize_t len;
844 int r; 846 int r;
845 847
@@ -946,6 +948,7 @@ prepare_poll(struct pollfd **pfdp, size_t *npfdp, int *timeoutp, u_int maxfds)
946 struct pollfd *pfd = *pfdp; 948 struct pollfd *pfd = *pfdp;
947 size_t i, j, npfd = 0; 949 size_t i, j, npfd = 0;
948 time_t deadline; 950 time_t deadline;
951 int r;
949 952
950 /* Count active sockets */ 953 /* Count active sockets */
951 for (i = 0; i < sockets_alloc; i++) { 954 for (i = 0; i < sockets_alloc; i++) {
@@ -983,8 +986,19 @@ prepare_poll(struct pollfd **pfdp, size_t *npfdp, int *timeoutp, u_int maxfds)
983 case AUTH_CONNECTION: 986 case AUTH_CONNECTION:
984 pfd[j].fd = sockets[i].fd; 987 pfd[j].fd = sockets[i].fd;
985 pfd[j].revents = 0; 988 pfd[j].revents = 0;
986 /* XXX backoff when input buffer full */ 989 /*
987 pfd[j].events = POLLIN; 990 * Only prepare to read if we can handle a full-size
991 * input read buffer and enqueue a max size reply..
992 */
993 if ((r = sshbuf_check_reserve(sockets[i].input,
994 AGENT_RBUF_LEN)) == 0 &&
995 (r = sshbuf_check_reserve(sockets[i].output,
996 AGENT_MAX_LEN)) == 0)
997 pfd[j].events = POLLIN;
998 else if (r != SSH_ERR_NO_BUFFER_SPACE) {
999 fatal("%s: buffer error: %s",
1000 __func__, ssh_err(r));
1001 }
988 if (sshbuf_len(sockets[i].output) > 0) 1002 if (sshbuf_len(sockets[i].output) > 0)
989 pfd[j].events |= POLLOUT; 1003 pfd[j].events |= POLLOUT;
990 j++; 1004 j++;