|
| 1 | +From 0832aac79517611dd4de93ad0a83577994d9c907 Mon Sep 17 00:00:00 2001 |
| 2 | +From: "djm@openbsd.org" <djm@openbsd.org> |
| 3 | +Date: Tue, 18 Feb 2025 08:02:48 +0000 |
| 4 | +Subject: [PATCH] upstream: Fix cases where error codes were not correctly set |
| 5 | + |
| 6 | +Reported by the Qualys Security Advisory team. ok markus@ |
| 7 | + |
| 8 | +OpenBSD-Commit-ID: 7bcd4ffe0fa1e27ff98d451fb9c22f5fae6e610d |
| 9 | +--- |
| 10 | + krl.c | 4 +++- |
| 11 | + ssh-agent.c | 7 ++++++- |
| 12 | + ssh-sk-client.c | 4 +++- |
| 13 | + sshconnect2.c | 7 +++++-- |
| 14 | + sshsig.c | 3 ++- |
| 15 | + 5 files changed, 19 insertions(+), 6 deletions(-) |
| 16 | + |
| 17 | +diff --git a/krl.c b/krl.c |
| 18 | +index e2efdf0667a7..0d0f69534182 100644 |
| 19 | +--- a/krl.c |
| 20 | ++++ b/krl.c |
| 21 | +@@ -674,6 +674,7 @@ revoked_certs_generate(struct revoked_certs *rc, struct sshbuf *buf) |
| 22 | + break; |
| 23 | + case KRL_SECTION_CERT_SERIAL_BITMAP: |
| 24 | + if (rs->lo - bitmap_start > INT_MAX) { |
| 25 | ++ r = SSH_ERR_INVALID_FORMAT; |
| 26 | + error_f("insane bitmap gap"); |
| 27 | + goto out; |
| 28 | + } |
| 29 | +@@ -1059,6 +1060,7 @@ ssh_krl_from_blob(struct sshbuf *buf, struct ssh_krl **krlp) |
| 30 | + } |
| 31 | + |
| 32 | + if ((krl = ssh_krl_init()) == NULL) { |
| 33 | ++ r = SSH_ERR_ALLOC_FAIL; |
| 34 | + error_f("alloc failed"); |
| 35 | + goto out; |
| 36 | + } |
| 37 | +diff --git a/ssh-agent.c b/ssh-agent.c |
| 38 | +index 48973b2c142a..c27c5a956f2c 100644 |
| 39 | +--- a/ssh-agent.c |
| 40 | ++++ b/ssh-agent.c |
| 41 | +@@ -1220,6 +1220,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp, |
| 42 | + "restrict-destination-v00@openssh.com") == 0) { |
| 43 | + if (*dcsp != NULL) { |
| 44 | + error_f("%s already set", ext_name); |
| 45 | ++ r = SSH_ERR_INVALID_FORMAT; |
| 46 | + goto out; |
| 47 | + } |
| 48 | + if ((r = sshbuf_froms(m, &b)) != 0) { |
| 49 | +@@ -1229,6 +1230,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp, |
| 50 | + while (sshbuf_len(b) != 0) { |
| 51 | + if (*ndcsp >= AGENT_MAX_DEST_CONSTRAINTS) { |
| 52 | + error_f("too many %s constraints", ext_name); |
| 53 | ++ r = SSH_ERR_INVALID_FORMAT; |
| 54 | + goto out; |
| 55 | + } |
| 56 | + *dcsp = xrecallocarray(*dcsp, *ndcsp, *ndcsp + 1, |
| 57 | +@@ -1246,6 +1248,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp, |
| 58 | + } |
| 59 | + if (*certs != NULL) { |
| 60 | + error_f("%s already set", ext_name); |
| 61 | ++ r = SSH_ERR_INVALID_FORMAT; |
| 62 | + goto out; |
| 63 | + } |
| 64 | + if ((r = sshbuf_get_u8(m, &v)) != 0 || |
| 65 | +@@ -1257,6 +1260,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp, |
| 66 | + while (sshbuf_len(b) != 0) { |
| 67 | + if (*ncerts >= AGENT_MAX_EXT_CERTS) { |
| 68 | + error_f("too many %s constraints", ext_name); |
| 69 | ++ r = SSH_ERR_INVALID_FORMAT; |
| 70 | + goto out; |
| 71 | + } |
| 72 | + *certs = xrecallocarray(*certs, *ncerts, *ncerts + 1, |
| 73 | +@@ -1757,6 +1761,7 @@ process_ext_session_bind(SocketEntry *e) |
| 74 | + /* record new key/sid */ |
| 75 | + if (e->nsession_ids >= AGENT_MAX_SESSION_IDS) { |
| 76 | + error_f("too many session IDs recorded"); |
| 77 | ++ r = -1; |
| 78 | + goto out; |
| 79 | + } |
| 80 | + e->session_ids = xrecallocarray(e->session_ids, e->nsession_ids, |
| 81 | +diff --git a/ssh-sk-client.c b/ssh-sk-client.c |
| 82 | +index 321fe53a2d91..06fad22134fb 100644 |
| 83 | +--- a/ssh-sk-client.c |
| 84 | ++++ b/ssh-sk-client.c |
| 85 | +@@ -439,6 +439,7 @@ sshsk_load_resident(const char *provider_path, const char *device, |
| 86 | + } |
| 87 | + if ((srk = calloc(1, sizeof(*srk))) == NULL) { |
| 88 | + error_f("calloc failed"); |
| 89 | ++ r = SSH_ERR_ALLOC_FAIL; |
| 90 | + goto out; |
| 91 | + } |
| 92 | + srk->key = key; |
| 93 | +@@ -450,6 +451,7 @@ sshsk_load_resident(const char *provider_path, const char *device, |
| 94 | + if ((tmp = recallocarray(srks, nsrks, nsrks + 1, |
| 95 | + sizeof(*srks))) == NULL) { |
| 96 | + error_f("recallocarray keys failed"); |
| 97 | ++ r = SSH_ERR_ALLOC_FAIL; |
| 98 | + goto out; |
| 99 | + } |
| 100 | + debug_f("srks[%zu]: %s %s uidlen %zu", nsrks, |
| 101 | +diff --git a/sshconnect2.c b/sshconnect2.c |
| 102 | +index a69c4da18773..1ee6000ab0cc 100644 |
| 103 | +--- a/sshconnect2.c |
| 104 | ++++ b/sshconnect2.c |
| 105 | +@@ -99,7 +99,7 @@ verify_host_key_callback(struct sshkey *hostkey, struct ssh *ssh) |
| 106 | + options.required_rsa_size)) != 0) |
| 107 | + fatal_r(r, "Bad server host key"); |
| 108 | + if (verify_host_key(xxx_host, xxx_hostaddr, hostkey, |
| 109 | +- xxx_conn_info) == -1) |
| 110 | ++ xxx_conn_info) != 0) |
| 111 | + fatal("Host key verification failed."); |
| 112 | + return 0; |
| 113 | + } |
| 114 | +@@ -699,6 +699,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, struct ssh *ssh) |
| 115 | + |
| 116 | + if ((pktype = sshkey_type_from_name(pkalg)) == KEY_UNSPEC) { |
| 117 | + debug_f("server sent unknown pkalg %s", pkalg); |
| 118 | ++ r = SSH_ERR_INVALID_FORMAT; |
| 119 | + goto done; |
| 120 | + } |
| 121 | + if ((r = sshkey_from_blob(pkblob, blen, &key)) != 0) { |
| 122 | +@@ -709,6 +710,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, struct ssh *ssh) |
| 123 | + error("input_userauth_pk_ok: type mismatch " |
| 124 | + "for decoded key (received %d, expected %d)", |
| 125 | + key->type, pktype); |
| 126 | ++ r = SSH_ERR_INVALID_FORMAT; |
| 127 | + goto done; |
| 128 | + } |
| 129 | + |
| 130 | +@@ -728,6 +730,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, struct ssh *ssh) |
| 131 | + SSH_FP_DEFAULT); |
| 132 | + error_f("server replied with unknown key: %s %s", |
| 133 | + sshkey_type(key), fp == NULL ? "<ERROR>" : fp); |
| 134 | ++ r = SSH_ERR_INVALID_FORMAT; |
| 135 | + goto done; |
| 136 | + } |
| 137 | + ident = format_identity(id); |
| 138 | +diff --git a/sshsig.c b/sshsig.c |
| 139 | +index 6e03c0b06d85..3da005d621f9 100644 |
| 140 | +--- a/sshsig.c |
| 141 | ++++ b/sshsig.c |
| 142 | +@@ -879,6 +879,7 @@ cert_filter_principals(const char *path, u_long linenum, |
| 143 | + } |
| 144 | + if ((principals = sshbuf_dup_string(nprincipals)) == NULL) { |
| 145 | + error_f("buffer error"); |
| 146 | ++ r = SSH_ERR_ALLOC_FAIL; |
| 147 | + goto out; |
| 148 | + } |
| 149 | + /* success */ |
0 commit comments