summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2020-03-13 04:01:56 +0000
committerDamien Miller <djm@mindrot.org>2020-03-14 19:39:30 +1100
commit5becbec023f2037394987f85ed7f74b9a28699e0 (patch)
treeea7a8e45ac5e4a71d95f5b99e376b51fa3f823ef
parenteef88418f9e5e51910af3c5b23b5606ebc17af55 (diff)
upstream: use sshpkt_fatal() for kex_exchange_identification()
errors. This ensures that the logged errors are consistent with other transport- layer errors and that the relevant IP addresses are logged. bz3129 ok dtucker@ OpenBSD-Commit-ID: 2c22891f0b9e1a6cd46771cedbb26ac96ec2e6ab
-rw-r--r--kex.c14
-rw-r--r--sshconnect.c7
-rw-r--r--sshd.c7
3 files changed, 19 insertions, 9 deletions
diff --git a/kex.c b/kex.c
index 899036e6e..09c7258e0 100644
--- a/kex.c
+++ b/kex.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.c,v 1.157 2020/02/26 13:40:09 jsg Exp $ */ 1/* $OpenBSD: kex.c,v 1.158 2020/03/13 04:01:56 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -1167,7 +1167,7 @@ int
1167kex_exchange_identification(struct ssh *ssh, int timeout_ms, 1167kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1168 const char *version_addendum) 1168 const char *version_addendum)
1169{ 1169{
1170 int remote_major, remote_minor, mismatch; 1170 int remote_major, remote_minor, mismatch, oerrno = 0;
1171 size_t len, i, n; 1171 size_t len, i, n;
1172 int r, expect_nl; 1172 int r, expect_nl;
1173 u_char c; 1173 u_char c;
@@ -1186,6 +1186,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1186 PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION, 1186 PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION,
1187 version_addendum == NULL ? "" : " ", 1187 version_addendum == NULL ? "" : " ",
1188 version_addendum == NULL ? "" : version_addendum)) != 0) { 1188 version_addendum == NULL ? "" : version_addendum)) != 0) {
1189 oerrno = errno;
1189 error("%s: sshbuf_putf: %s", __func__, ssh_err(r)); 1190 error("%s: sshbuf_putf: %s", __func__, ssh_err(r));
1190 goto out; 1191 goto out;
1191 } 1192 }
@@ -1193,11 +1194,13 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1193 if (atomicio(vwrite, ssh_packet_get_connection_out(ssh), 1194 if (atomicio(vwrite, ssh_packet_get_connection_out(ssh),
1194 sshbuf_mutable_ptr(our_version), 1195 sshbuf_mutable_ptr(our_version),
1195 sshbuf_len(our_version)) != sshbuf_len(our_version)) { 1196 sshbuf_len(our_version)) != sshbuf_len(our_version)) {
1196 error("%s: write: %.100s", __func__, strerror(errno)); 1197 oerrno = errno;
1198 debug("%s: write: %.100s", __func__, strerror(errno));
1197 r = SSH_ERR_SYSTEM_ERROR; 1199 r = SSH_ERR_SYSTEM_ERROR;
1198 goto out; 1200 goto out;
1199 } 1201 }
1200 if ((r = sshbuf_consume_end(our_version, 2)) != 0) { /* trim \r\n */ 1202 if ((r = sshbuf_consume_end(our_version, 2)) != 0) { /* trim \r\n */
1203 oerrno = errno;
1201 error("%s: sshbuf_consume_end: %s", __func__, ssh_err(r)); 1204 error("%s: sshbuf_consume_end: %s", __func__, ssh_err(r));
1202 goto out; 1205 goto out;
1203 } 1206 }
@@ -1233,6 +1236,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1233 r = SSH_ERR_CONN_TIMEOUT; 1236 r = SSH_ERR_CONN_TIMEOUT;
1234 goto out; 1237 goto out;
1235 } else if (r == -1) { 1238 } else if (r == -1) {
1239 oerrno = errno;
1236 error("%s: %s", 1240 error("%s: %s",
1237 __func__, strerror(errno)); 1241 __func__, strerror(errno));
1238 r = SSH_ERR_SYSTEM_ERROR; 1242 r = SSH_ERR_SYSTEM_ERROR;
@@ -1248,6 +1252,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1248 r = SSH_ERR_CONN_CLOSED; 1252 r = SSH_ERR_CONN_CLOSED;
1249 goto out; 1253 goto out;
1250 } else if (len != 1) { 1254 } else if (len != 1) {
1255 oerrno = errno;
1251 error("%s: read: %.100s", 1256 error("%s: read: %.100s",
1252 __func__, strerror(errno)); 1257 __func__, strerror(errno));
1253 r = SSH_ERR_SYSTEM_ERROR; 1258 r = SSH_ERR_SYSTEM_ERROR;
@@ -1265,6 +1270,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1265 goto invalid; 1270 goto invalid;
1266 } 1271 }
1267 if ((r = sshbuf_put_u8(peer_version, c)) != 0) { 1272 if ((r = sshbuf_put_u8(peer_version, c)) != 0) {
1273 oerrno = errno;
1268 error("%s: sshbuf_put: %s", 1274 error("%s: sshbuf_put: %s",
1269 __func__, ssh_err(r)); 1275 __func__, ssh_err(r));
1270 goto out; 1276 goto out;
@@ -1365,6 +1371,8 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1365 free(our_version_string); 1371 free(our_version_string);
1366 free(peer_version_string); 1372 free(peer_version_string);
1367 free(remote_version); 1373 free(remote_version);
1374 if (r == SSH_ERR_SYSTEM_ERROR)
1375 errno = oerrno;
1368 return r; 1376 return r;
1369} 1377}
1370 1378
diff --git a/sshconnect.c b/sshconnect.c
index 4711af782..af08be415 100644
--- a/sshconnect.c
+++ b/sshconnect.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshconnect.c,v 1.328 2020/01/25 07:17:18 djm Exp $ */ 1/* $OpenBSD: sshconnect.c,v 1.329 2020/03/13 04:01:56 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
@@ -1276,6 +1276,7 @@ ssh_login(struct ssh *ssh, Sensitive *sensitive, const char *orighost,
1276{ 1276{
1277 char *host; 1277 char *host;
1278 char *server_user, *local_user; 1278 char *server_user, *local_user;
1279 int r;
1279 1280
1280 local_user = xstrdup(pw->pw_name); 1281 local_user = xstrdup(pw->pw_name);
1281 server_user = options.user ? options.user : local_user; 1282 server_user = options.user ? options.user : local_user;
@@ -1285,8 +1286,8 @@ ssh_login(struct ssh *ssh, Sensitive *sensitive, const char *orighost,
1285 lowercase(host); 1286 lowercase(host);
1286 1287
1287 /* Exchange protocol version identification strings with the server. */ 1288 /* Exchange protocol version identification strings with the server. */
1288 if (kex_exchange_identification(ssh, timeout_ms, NULL) != 0) 1289 if ((r = kex_exchange_identification(ssh, timeout_ms, NULL)) != 0)
1289 cleanup_exit(255); /* error already logged */ 1290 sshpkt_fatal(ssh, r, "banner exchange");
1290 1291
1291 /* Put the connection into non-blocking mode. */ 1292 /* Put the connection into non-blocking mode. */
1292 ssh_packet_set_nonblocking(ssh); 1293 ssh_packet_set_nonblocking(ssh);
diff --git a/sshd.c b/sshd.c
index e59077911..6f8f11a3b 100644
--- a/sshd.c
+++ b/sshd.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sshd.c,v 1.551 2020/03/13 03:24:49 dtucker Exp $ */ 1/* $OpenBSD: sshd.c,v 1.552 2020/03/13 04:01:57 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
@@ -2155,8 +2155,9 @@ main(int ac, char **av)
2155 if (!debug_flag) 2155 if (!debug_flag)
2156 alarm(options.login_grace_time); 2156 alarm(options.login_grace_time);
2157 2157
2158 if (kex_exchange_identification(ssh, -1, options.version_addendum) != 0) 2158 if ((r = kex_exchange_identification(ssh, -1,
2159 cleanup_exit(255); /* error already logged */ 2159 options.version_addendum)) != 0)
2160 sshpkt_fatal(ssh, r, "banner exchange");
2160 2161
2161 ssh_packet_set_nonblocking(ssh); 2162 ssh_packet_set_nonblocking(ssh);
2162 2163