From 02d8590f2a67d5dbfbf6837d6d9b9660ab9b0d95 Mon Sep 17 00:00:00 2001
From: zhaoyonghao <zhaoyonghao10@h-partners.com>
Date: Sat, 28 Mar 2026 08:39:41 +0000
Subject: [PATCH] fix CVE-2026-3497
Reference:https://www.openwall.com/lists/oss-security/2026/03/12/3/2
kexgssc.c | 24 ++++++++++++------------
kexgsss.c | 9 +++++----
packet.c | 6 +++---
3 files changed, 20 insertions(+), 19 deletions(-)
@@ -52,8 +52,8 @@ kexgss_client(struct ssh *ssh)
{
struct kex *kex = ssh->kex;
gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER,
- recv_tok = GSS_C_EMPTY_BUFFER,
- gssbuf, msg_tok = GSS_C_EMPTY_BUFFER, *token_ptr;
+ recv_tok = GSS_C_EMPTY_BUFFER, gssbuf = GSS_C_EMPTY_BUFFER,
+ msg_tok = GSS_C_EMPTY_BUFFER, *token_ptr;
Gssctxt *ctxt;
OM_uint32 maj_status, min_status, ret_flags;
struct sshbuf *server_blob = NULL;
@@ -205,11 +205,11 @@ kexgss_client(struct ssh *ssh)
fatal("Failed to read token: %s", ssh_err(r));
/* If we're already complete - protocol error */
if (maj_status == GSS_S_COMPLETE)
- sshpkt_disconnect(ssh, "Protocol error: received token when complete");
+ ssh_packet_disconnect(ssh, "Protocol error: received token when complete");
} else {
/* No token included */
if (maj_status != GSS_S_COMPLETE)
- sshpkt_disconnect(ssh, "Protocol error: did not receive final token");
+ ssh_packet_disconnect(ssh, "Protocol error: did not receive final token");
}
if ((r = sshpkt_get_end(ssh)) != 0) {
fatal("Expecting end of packet.");
@@ -225,7 +225,7 @@ kexgss_client(struct ssh *ssh)
fatal("sshpkt_get failed: %s", ssh_err(r));
fatal("GSSAPI Error: \n%.400s", msg);
default:
- sshpkt_disconnect(ssh, "Protocol error: didn't expect packet type %d",
+ ssh_packet_disconnect(ssh, "Protocol error: didn't expect packet type %d",
type);
}
token_ptr = &recv_tok;
@@ -298,7 +298,7 @@ kexgss_client(struct ssh *ssh)
/* Verify that the hash matches the MIC we just got. */
if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
- sshpkt_disconnect(ssh, "Hash's MIC didn't verify");
+ ssh_packet_disconnect(ssh, "Hash's MIC didn't verify");
gss_release_buffer(&min_status, &msg_tok);
@@ -330,8 +330,8 @@ kexgssgex_client(struct ssh *ssh)
{
struct kex *kex = ssh->kex;
gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER,
- recv_tok = GSS_C_EMPTY_BUFFER, gssbuf,
- msg_tok = GSS_C_EMPTY_BUFFER, *token_ptr;
+ recv_tok = GSS_C_EMPTY_BUFFER, gssbuf = GSS_C_EMPTY_BUFFER,
+ msg_tok = GSS_C_EMPTY_BUFFER, *token_ptr;
Gssctxt *ctxt;
OM_uint32 maj_status, min_status, ret_flags;
struct sshbuf *shared_secret = NULL;
@@ -502,11 +502,11 @@ kexgssgex_client(struct ssh *ssh)
fatal("sshpkt failed: %s", ssh_err(r));
/* If we're already complete - protocol error */
if (maj_status == GSS_S_COMPLETE)
- sshpkt_disconnect(ssh, "Protocol error: received token when complete");
+ ssh_packet_disconnect(ssh, "Protocol error: received token when complete");
} else {
/* No token included */
if (maj_status != GSS_S_COMPLETE)
- sshpkt_disconnect(ssh, "Protocol error: did not receive final token");
+ ssh_packet_disconnect(ssh, "Protocol error: did not receive final token");
}
break;
case SSH2_MSG_KEXGSS_ERROR:
@@ -519,7 +519,7 @@ kexgssgex_client(struct ssh *ssh)
fatal("sshpkt failed: %s", ssh_err(r));
fatal("GSSAPI Error: \n%.400s", msg);
default:
- sshpkt_disconnect(ssh, "Protocol error: didn't expect packet type %d",
+ ssh_packet_disconnect(ssh, "Protocol error: didn't expect packet type %d",
type);
}
token_ptr = &recv_tok;
@@ -581,7 +581,7 @@ kexgssgex_client(struct ssh *ssh)
/* Verify that the hash matches the MIC we just got. */
if (GSS_ERROR(ssh_gssapi_checkmic(ctxt, &gssbuf, &msg_tok)))
- sshpkt_disconnect(ssh, "Hash's MIC didn't verify");
+ ssh_packet_disconnect(ssh, "Hash's MIC didn't verify");
gss_release_buffer(&min_status, &msg_tok);
@@ -168,7 +168,7 @@ kexgss_server(struct ssh *ssh)
fatal("sshpkt failed: %s", ssh_err(r));
break;
default:
- sshpkt_disconnect(ssh,
+ ssh_packet_disconnect(ssh,
"Protocol error: didn't expect packet type %d",
type);
}
@@ -267,7 +267,8 @@ kexgssgex_server(struct ssh *ssh)
*/
OM_uint32 ret_flags = 0;
- gss_buffer_desc gssbuf, recv_tok, msg_tok;
+ gss_buffer_desc gssbuf = GSS_C_EMPTY_BUFFER,
+ recv_tok = GSS_C_EMPTY_BUFFER, msg_tok = GSS_C_EMPTY_BUFFER;
gss_buffer_desc send_tok = GSS_C_EMPTY_BUFFER;
Gssctxt *ctxt = NULL;
struct sshbuf *shared_secret = NULL;
@@ -324,7 +325,7 @@ kexgssgex_server(struct ssh *ssh)
min, nbits, max);
kex->dh = PRIVSEP(choose_dh(min, nbits, max));
if (kex->dh == NULL) {
- sshpkt_disconnect(ssh, "Protocol error: no matching group found");
+ ssh_packet_disconnect(ssh, "Protocol error: no matching group found");
fatal("Protocol error: no matching group found");
}
@@ -364,7 +365,7 @@ kexgssgex_server(struct ssh *ssh)
fatal("sshpkt failed: %s", ssh_err(r));
break;
default:
- sshpkt_disconnect(ssh,
+ ssh_packet_disconnect(ssh,
"Protocol error: didn't expect packet type %d",
type);
}
@@ -1455,10 +1455,10 @@ ssh_packet_read_expect(struct ssh *ssh, u_int expected_type)
if ((r = ssh_packet_read_seqnr(ssh, &type, NULL)) != 0)
return r;
if (type != expected_type) {
- if ((r = sshpkt_disconnect(ssh,
+ ssh_packet_disconnect(ssh,
"Protocol error: expected packet type %d, got %d",
- expected_type, type)) != 0)
- return r;
+ expected_type, type);
+
return SSH_ERR_PROTOCOL_ERROR;
}
return 0;
--
2.33.0