diff --git a/usr.bin/ssh/cipher.c b/usr.bin/ssh/cipher.c index e1138ec4ea5..beead59665b 100644 --- a/usr.bin/ssh/cipher.c +++ b/usr.bin/ssh/cipher.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cipher.c,v 1.127 2026/05/13 05:58:58 djm Exp $ */ +/* $OpenBSD: cipher.c,v 1.128 2026/05/31 04:37:56 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -177,6 +177,12 @@ cipher_is_cbc(const struct sshcipher *c) return (c->flags & CFLAG_CBC) != 0; } +u_int +cipher_is_internal(const struct sshcipher *c) +{ + return (c->flags & CFLAG_INTERNAL) != 0; +} + u_int cipher_ctx_is_plaintext(struct sshcipher_ctx *cc) { diff --git a/usr.bin/ssh/cipher.h b/usr.bin/ssh/cipher.h index 6533ff2bbde..061a26b2001 100644 --- a/usr.bin/ssh/cipher.h +++ b/usr.bin/ssh/cipher.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cipher.h,v 1.56 2023/10/10 06:49:54 tb Exp $ */ +/* $OpenBSD: cipher.h,v 1.57 2026/05/31 04:37:56 djm Exp $ */ /* * Author: Tatu Ylonen @@ -68,6 +68,7 @@ u_int cipher_seclen(const struct sshcipher *); u_int cipher_authlen(const struct sshcipher *); u_int cipher_ivlen(const struct sshcipher *); u_int cipher_is_cbc(const struct sshcipher *); +u_int cipher_is_internal(const struct sshcipher *); u_int cipher_ctx_is_plaintext(struct sshcipher_ctx *); diff --git a/usr.bin/ssh/packet.c b/usr.bin/ssh/packet.c index cc3c575d769..8aec8fd9736 100644 --- a/usr.bin/ssh/packet.c +++ b/usr.bin/ssh/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.336 2026/05/31 04:24:39 djm Exp $ */ +/* $OpenBSD: packet.c,v 1.337 2026/05/31 04:37:56 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -2513,7 +2513,9 @@ newkeys_from_blob(struct sshbuf *m, struct ssh *ssh, int mode) (r = sshbuf_get_string(b, &enc->key, &keylen)) != 0 || (r = sshbuf_get_string(b, &enc->iv, &ivlen)) != 0) goto out; - if ((enc->cipher = cipher_by_name(enc->name)) == NULL) { + if ((enc->cipher = cipher_by_name(enc->name)) == NULL || + enc->block_size != cipher_blocksize(enc->cipher) || + cipher_is_internal(enc->cipher)) { r = SSH_ERR_INVALID_FORMAT; goto out; } @@ -2525,7 +2527,7 @@ newkeys_from_blob(struct sshbuf *m, struct ssh *ssh, int mode) if ((r = sshbuf_get_u32(b, (u_int *)&mac->enabled)) != 0 || (r = sshbuf_get_string(b, &mac->key, &maclen)) != 0) goto out; - if (maclen > mac->key_len) { + if (maclen != mac->key_len) { r = SSH_ERR_INVALID_FORMAT; goto out; } @@ -2571,6 +2573,10 @@ kex_from_blob(struct sshbuf *m, struct kex **kexp) (r = sshbuf_get_stringb(m, kex->session_id)) != 0 || (r = sshbuf_get_u32(m, &kex->flags)) != 0) goto out; + if (kex->we_need > 1024) { + r = SSH_ERR_INVALID_FORMAT; + goto out; + } kex->server = 1; kex->done = 1; r = 0;