Skip to content

Commit

Permalink
ssh: Fix cases where error codes were not correctly set
Browse files Browse the repository at this point in the history
Obtained from:	OpenSSH 38df39ecf278
Security:	CVE-2025-26465
Security:	FreeBSD-SA-25:05.openssh
Approved by:	so
Sponsored by:	The FreeBSD Foundation

(cherry picked from commit 170059d6d33cf4e890067097f3c0beb3061cabbd)
(cherry picked from commit 4ad8c195cf54411e3b3fa0bec227eb83ca078404)
  • Loading branch information
emaste authored and fichtner committed Feb 21, 2025
1 parent b1697b6 commit 3cce750
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion crypto/openssh/krl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: krl.c,v 1.59 2023/07/17 05:22:30 djm Exp $ */
/* $OpenBSD: krl.c,v 1.60 2025/02/18 08:02:48 djm Exp $ */
/*
* Copyright (c) 2012 Damien Miller <djm@mindrot.org>
*
Expand Down Expand Up @@ -674,6 +674,7 @@ revoked_certs_generate(struct revoked_certs *rc, struct sshbuf *buf)
break;
case KRL_SECTION_CERT_SERIAL_BITMAP:
if (rs->lo - bitmap_start > INT_MAX) {
r = SSH_ERR_INVALID_FORMAT;
error_f("insane bitmap gap");
goto out;
}
Expand Down Expand Up @@ -1059,6 +1060,7 @@ ssh_krl_from_blob(struct sshbuf *buf, struct ssh_krl **krlp)
}

if ((krl = ssh_krl_init()) == NULL) {
r = SSH_ERR_ALLOC_FAIL;
error_f("alloc failed");
goto out;
}
Expand Down
5 changes: 5 additions & 0 deletions crypto/openssh/ssh-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
"restrict-destination-v00@openssh.com") == 0) {
if (*dcsp != NULL) {
error_f("%s already set", ext_name);
r = SSH_ERR_INVALID_FORMAT;
goto out;
}
if ((r = sshbuf_froms(m, &b)) != 0) {
Expand All @@ -1235,6 +1236,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
while (sshbuf_len(b) != 0) {
if (*ndcsp >= AGENT_MAX_DEST_CONSTRAINTS) {
error_f("too many %s constraints", ext_name);
r = SSH_ERR_INVALID_FORMAT;
goto out;
}
*dcsp = xrecallocarray(*dcsp, *ndcsp, *ndcsp + 1,
Expand All @@ -1252,6 +1254,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
}
if (*certs != NULL) {
error_f("%s already set", ext_name);
r = SSH_ERR_INVALID_FORMAT;
goto out;
}
if ((r = sshbuf_get_u8(m, &v)) != 0 ||
Expand All @@ -1263,6 +1266,7 @@ parse_key_constraint_extension(struct sshbuf *m, char **sk_providerp,
while (sshbuf_len(b) != 0) {
if (*ncerts >= AGENT_MAX_EXT_CERTS) {
error_f("too many %s constraints", ext_name);
r = SSH_ERR_INVALID_FORMAT;
goto out;
}
*certs = xrecallocarray(*certs, *ncerts, *ncerts + 1,
Expand Down Expand Up @@ -1759,6 +1763,7 @@ process_ext_session_bind(SocketEntry *e)
/* record new key/sid */
if (e->nsession_ids >= AGENT_MAX_SESSION_IDS) {
error_f("too many session IDs recorded");
r = -1;
goto out;
}
e->session_ids = xrecallocarray(e->session_ids, e->nsession_ids,
Expand Down
4 changes: 3 additions & 1 deletion crypto/openssh/ssh-sk-client.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $OpenBSD: ssh-sk-client.c,v 1.12 2022/01/14 03:34:00 djm Exp $ */
/* $OpenBSD: ssh-sk-client.c,v 1.13 2025/02/18 08:02:48 djm Exp $ */
/*
* Copyright (c) 2019 Google LLC
*
Expand Down Expand Up @@ -439,6 +439,7 @@ sshsk_load_resident(const char *provider_path, const char *device,
}
if ((srk = calloc(1, sizeof(*srk))) == NULL) {
error_f("calloc failed");
r = SSH_ERR_ALLOC_FAIL;
goto out;
}
srk->key = key;
Expand All @@ -450,6 +451,7 @@ sshsk_load_resident(const char *provider_path, const char *device,
if ((tmp = recallocarray(srks, nsrks, nsrks + 1,
sizeof(*srks))) == NULL) {
error_f("recallocarray keys failed");
r = SSH_ERR_ALLOC_FAIL;
goto out;
}
debug_f("srks[%zu]: %s %s uidlen %zu", nsrks,
Expand Down
5 changes: 4 additions & 1 deletion crypto/openssh/sshconnect2.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ verify_host_key_callback(struct sshkey *hostkey, struct ssh *ssh)
options.required_rsa_size)) != 0)
fatal_r(r, "Bad server host key");
if (verify_host_key(xxx_host, xxx_hostaddr, hostkey,
xxx_conn_info) == -1)
xxx_conn_info) != 0)
fatal("Host key verification failed.");
return 0;
}
Expand Down Expand Up @@ -700,6 +700,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, struct ssh *ssh)

if ((pktype = sshkey_type_from_name(pkalg)) == KEY_UNSPEC) {
debug_f("server sent unknown pkalg %s", pkalg);
r = SSH_ERR_INVALID_FORMAT;
goto done;
}
if ((r = sshkey_from_blob(pkblob, blen, &key)) != 0) {
Expand All @@ -710,6 +711,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, struct ssh *ssh)
error("input_userauth_pk_ok: type mismatch "
"for decoded key (received %d, expected %d)",
key->type, pktype);
r = SSH_ERR_INVALID_FORMAT;
goto done;
}

Expand All @@ -729,6 +731,7 @@ input_userauth_pk_ok(int type, u_int32_t seq, struct ssh *ssh)
SSH_FP_DEFAULT);
error_f("server replied with unknown key: %s %s",
sshkey_type(key), fp == NULL ? "<ERROR>" : fp);
r = SSH_ERR_INVALID_FORMAT;
goto done;
}
ident = format_identity(id);
Expand Down
1 change: 1 addition & 0 deletions crypto/openssh/sshsig.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ cert_filter_principals(const char *path, u_long linenum,
}
if ((principals = sshbuf_dup_string(nprincipals)) == NULL) {
error_f("buffer error");
r = SSH_ERR_ALLOC_FAIL;
goto out;
}
/* success */
Expand Down

0 comments on commit 3cce750

Please sign in to comment.