Skip to content

Commit efa17c8

Browse files
tgauthdjmdjm
andauthored
cherry-picks from upstream (#783)
* upstream: Don't reply to PING in preauth phase or during KEX Reported by the Qualys Security Advisory team. ok markus@ OpenBSD-Commit-ID: c656ac4abd1504389d1733d85152044b15830217 * upstream: Fix cases where error codes were not correctly set Reported by the Qualys Security Advisory team. ok markus@ OpenBSD-Commit-ID: 7bcd4ffe0fa1e27ff98d451fb9c22f5fae6e610d * fix error code case in Windows ssh-agent code --------- Co-authored-by: [email protected] <[email protected]>
1 parent e0ae79f commit efa17c8

File tree

7 files changed

+29
-7
lines changed

7 files changed

+29
-7
lines changed

contrib/win32/win32compat/ssh-agent/keyagent-request.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ process_ext_session_bind(struct sshbuf* request, struct agent_connection* con)
995995
/* record new key/sid */
996996
if (con->nsession_ids >= AGENT_MAX_SESSION_IDS) {
997997
error_f("too many session IDs recorded");
998+
r = -1;
998999
goto out;
9991000
}
10001001
con->session_ids = xrecallocarray(con->session_ids, con->nsession_ids,

krl.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: krl.c,v 1.59 2023/07/17 05:22:30 djm Exp $ */
1+
/* $OpenBSD: krl.c,v 1.60 2025/02/18 08:02:48 djm Exp $ */
22
/*
33
* Copyright (c) 2012 Damien Miller <[email protected]>
44
*
@@ -674,6 +674,7 @@ revoked_certs_generate(struct revoked_certs *rc, struct sshbuf *buf)
674674
break;
675675
case KRL_SECTION_CERT_SERIAL_BITMAP:
676676
if (rs->lo - bitmap_start > INT_MAX) {
677+
r = SSH_ERR_INVALID_FORMAT;
677678
error_f("insane bitmap gap");
678679
goto out;
679680
}
@@ -1059,6 +1060,7 @@ ssh_krl_from_blob(struct sshbuf *buf, struct ssh_krl **krlp)
10591060
}
10601061

10611062
if ((krl = ssh_krl_init()) == NULL) {
1063+
r = SSH_ERR_ALLOC_FAIL;
10621064
error_f("alloc failed");
10631065
goto out;
10641066
}

packet.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: packet.c,v 1.315 2024/05/31 08:49:35 djm Exp $ */
1+
/* $OpenBSD: packet.c,v 1.318 2025/02/18 08:02:12 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <[email protected]>
44
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
@@ -1867,6 +1867,14 @@ ssh_packet_read_poll_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
18671867
if ((r = sshpkt_get_string_direct(ssh, &d, &len)) != 0)
18681868
return r;
18691869
DBG(debug("Received SSH2_MSG_PING len %zu", len));
1870+
if (!ssh->state->after_authentication) {
1871+
DBG(debug("Won't reply to PING in preauth"));
1872+
break;
1873+
}
1874+
if (ssh_packet_is_rekeying(ssh)) {
1875+
DBG(debug("Won't reply to PING during KEX"));
1876+
break;
1877+
}
18701878
if ((r = sshpkt_start(ssh, SSH2_MSG_PONG)) != 0 ||
18711879
(r = sshpkt_put_string(ssh, d, len)) != 0 ||
18721880
(r = sshpkt_send(ssh)) != 0)

ssh-agent.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ssh-agent.c,v 1.306 2024/03/09 05:12:13 djm Exp $ */
1+
/* $OpenBSD: ssh-agent.c,v 1.310 2025/02/18 08:02:48 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <[email protected]>
44
* Copyright (c) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland
@@ -1208,6 +1208,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
12081208
"[email protected]") == 0) {
12091209
if (*dcsp != NULL) {
12101210
error_f("%s already set", ext_name);
1211+
r = SSH_ERR_INVALID_FORMAT;
12111212
goto out;
12121213
}
12131214
if ((r = sshbuf_froms(m, &b)) != 0) {
@@ -1217,6 +1218,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
12171218
while (sshbuf_len(b) != 0) {
12181219
if (*ndcsp >= AGENT_MAX_DEST_CONSTRAINTS) {
12191220
error_f("too many %s constraints", ext_name);
1221+
r = SSH_ERR_INVALID_FORMAT;
12201222
goto out;
12211223
}
12221224
*dcsp = xrecallocarray(*dcsp, *ndcsp, *ndcsp + 1,
@@ -1234,6 +1236,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
12341236
}
12351237
if (*certs != NULL) {
12361238
error_f("%s already set", ext_name);
1239+
r = SSH_ERR_INVALID_FORMAT;
12371240
goto out;
12381241
}
12391242
if ((r = sshbuf_get_u8(m, &v)) != 0 ||
@@ -1245,6 +1248,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
12451248
while (sshbuf_len(b) != 0) {
12461249
if (*ncerts >= AGENT_MAX_EXT_CERTS) {
12471250
error_f("too many %s constraints", ext_name);
1251+
r = SSH_ERR_INVALID_FORMAT;
12481252
goto out;
12491253
}
12501254
*certs = xrecallocarray(*certs, *ncerts, *ncerts + 1,
@@ -1741,6 +1745,7 @@ process_ext_session_bind(SocketEntry *e)
17411745
/* record new key/sid */
17421746
if (e->nsession_ids >= AGENT_MAX_SESSION_IDS) {
17431747
error_f("too many session IDs recorded");
1748+
r = -1;
17441749
goto out;
17451750
}
17461751
e->session_ids = xrecallocarray(e->session_ids, e->nsession_ids,

ssh-sk-client.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: ssh-sk-client.c,v 1.12 2022/01/14 03:34:00 djm Exp $ */
1+
/* $OpenBSD: ssh-sk-client.c,v 1.13 2025/02/18 08:02:48 djm Exp $ */
22
/*
33
* Copyright (c) 2019 Google LLC
44
*
@@ -570,6 +570,7 @@ sshsk_load_resident(const char *provider_path, const char *device,
570570
}
571571
if ((srk = calloc(1, sizeof(*srk))) == NULL) {
572572
error_f("calloc failed");
573+
r = SSH_ERR_ALLOC_FAIL;
573574
goto out;
574575
}
575576
srk->key = key;
@@ -581,6 +582,7 @@ sshsk_load_resident(const char *provider_path, const char *device,
581582
if ((tmp = recallocarray(srks, nsrks, nsrks + 1,
582583
sizeof(*srks))) == NULL) {
583584
error_f("recallocarray keys failed");
585+
r = SSH_ERR_ALLOC_FAIL;
584586
goto out;
585587
}
586588
debug_f("srks[%zu]: %s %s uidlen %zu", nsrks,

sshconnect2.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: sshconnect2.c,v 1.373 2024/05/17 06:38:00 jsg Exp $ */
1+
/* $OpenBSD: sshconnect2.c,v 1.377 2025/02/18 08:02:48 djm Exp $ */
22
/*
33
* Copyright (c) 2000 Markus Friedl. All rights reserved.
44
* Copyright (c) 2008 Damien Miller. All rights reserved.
@@ -103,7 +103,7 @@ verify_host_key_callback(struct sshkey *hostkey, struct ssh *ssh)
103103
options.required_rsa_size)) != 0)
104104
fatal_r(r, "Bad server host key");
105105
if (verify_host_key(xxx_host, xxx_hostaddr, hostkey,
106-
xxx_conn_info) == -1)
106+
xxx_conn_info) != 0)
107107
fatal("Host key verification failed.");
108108
return 0;
109109
}
@@ -722,6 +722,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, struct ssh *ssh)
722722
send_pubkey_telemetry("server sent unknown pkalg");
723723
#endif
724724
debug_f("server sent unknown pkalg %s", pkalg);
725+
r = SSH_ERR_INVALID_FORMAT;
725726
goto done;
726727
}
727728
if ((r = sshkey_from_blob(pkblob, blen, &key)) != 0) {
@@ -738,6 +739,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, struct ssh *ssh)
738739
error("input_userauth_pk_ok: type mismatch "
739740
"for decoded key (received %d, expected %d)",
740741
key->type, pktype);
742+
r = SSH_ERR_INVALID_FORMAT;
741743
goto done;
742744
}
743745

@@ -757,6 +759,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, struct ssh *ssh)
757759
SSH_FP_DEFAULT);
758760
error_f("server replied with unknown key: %s %s",
759761
sshkey_type(key), fp == NULL ? "<ERROR>" : fp);
762+
r = SSH_ERR_INVALID_FORMAT;
760763
goto done;
761764
}
762765
ident = format_identity(id);

sshsig.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: sshsig.c,v 1.35 2024/03/08 22:16:32 djm Exp $ */
1+
/* $OpenBSD: sshsig.c,v 1.38 2025/02/18 08:02:48 djm Exp $ */
22
/*
33
* Copyright (c) 2019 Google LLC
44
*
@@ -907,6 +907,7 @@ cert_filter_principals(const char *path, u_long linenum,
907907
}
908908
if ((principals = sshbuf_dup_string(nprincipals)) == NULL) {
909909
error_f("buffer error");
910+
r = SSH_ERR_ALLOC_FAIL;
910911
goto out;
911912
}
912913
/* success */

0 commit comments

Comments
 (0)