[openssh-commits] [openssh] 05/18: upstream: set a hard maximum (32) on the number of unuspported
git+noreply at mindrot.org
git+noreply at mindrot.org
Wed Nov 25 19:56:00 AEDT 2026
This is an automated email from the git hooks/post-receive script.
djm pushed a commit to branch master
in repository openssh.
commit 0224803da7816f3bf4a7173ded2080885f3efb6f
Author: djm at openbsd.org <djm at openbsd.org>
AuthorDate: Wed Nov 25 06:57:05 2026 +0000
upstream: set a hard maximum (32) on the number of unuspported
packets that sshd will accept in the preauthentication phase to avoid
logspam.
Note: this is separate to strict-kex which, when activated, will not accept
any unumplemented packet types. That kicks in later however.
Anthropic ANT-2026-7KV3V8P7 (with different fix)
OpenBSD-Commit-ID: f8e926ced70f8f38dfc598205cd7d19dd92d17ce
---
dispatch.c | 5 +++--
kex.c | 5 +++--
packet.c | 21 ++++++++++++++++++++-
packet.h | 3 ++-
ssh.h | 6 +++++-
5 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/dispatch.c b/dispatch.c
index dd962a1b4..58fabbca1 100644
--- a/dispatch.c
+++ b/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.35 2026/03/03 09:57:25 dtucker Exp $ */
+/* $OpenBSD: dispatch.c,v 1.36 2026/11/25 06:57:05 djm Exp $ */
/*
* Copyright (c) 2000 Markus Friedl. All rights reserved.
*
@@ -42,7 +42,8 @@ dispatch_protocol_error(int type, uint32_t seq, struct ssh *ssh)
int r;
logit_f("type %d seq %u", type, seq);
- if ((r = sshpkt_start(ssh, SSH2_MSG_UNIMPLEMENTED)) != 0 ||
+ if ((r = sshpkt_record_unimplemented(ssh, type, seq)) != 0 ||
+ (r = sshpkt_start(ssh, SSH2_MSG_UNIMPLEMENTED)) != 0 ||
(r = sshpkt_put_u32(ssh, seq)) != 0 ||
(r = sshpkt_send(ssh)) != 0 ||
(r = ssh_packet_write_wait(ssh)) != 0)
diff --git a/kex.c b/kex.c
index d9959077f..f11418a0f 100644
--- a/kex.c
+++ b/kex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kex.c,v 1.198 2026/10/30 04:36:21 djm Exp $ */
+/* $OpenBSD: kex.c,v 1.199 2026/11/25 06:57:05 djm Exp $ */
/*
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
*
@@ -239,7 +239,8 @@ kex_protocol_error(int type, uint32_t seq, struct ssh *ssh)
"unexpected packet type %u (seqnr %u)", type, seq);
}
error_f("type %u seq %u", type, seq);
- if ((r = sshpkt_start(ssh, SSH2_MSG_UNIMPLEMENTED)) != 0 ||
+ if ((r = sshpkt_record_unimplemented(ssh, type, seq)) != 0 ||
+ (r = sshpkt_start(ssh, SSH2_MSG_UNIMPLEMENTED)) != 0 ||
(r = sshpkt_put_u32(ssh, seq)) != 0 ||
(r = sshpkt_send(ssh)) != 0)
return r;
diff --git a/packet.c b/packet.c
index 24e3ba4f0..1c3e72df8 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.350 2026/10/31 03:29:22 dtucker Exp $ */
+/* $OpenBSD: packet.c,v 1.351 2026/11/25 06:57:05 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo at cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo at cs.hut.fi>, Espoo, Finland
@@ -89,6 +89,7 @@
#include "sshbuf.h"
#include "version.h"
#include "utf8.h"
+#include "ssh.h"
#ifdef PACKET_DEBUG
#define DBG(x) x
@@ -228,6 +229,9 @@ struct session_state {
/* Set to permanently poison this connection instance */
int poisoned;
+ /* Number of packets of unsupported type recevied in preauth */
+ int nunimpl_packets;
+
/* Hook for fuzzing inbound packets */
ssh_packet_hook_fn *hook_in;
void *hook_in_ctx;
@@ -3010,6 +3014,21 @@ sshpkt_protocol_error(struct ssh *ssh, const char *fmt,...)
return SSH_ERR_PROTOCOL_ERROR;
}
+/*
+ * Record reception of an unknown packet type.
+ * We limit these in preauth to avoid logspam.
+ */
+int
+sshpkt_record_unimplemented(struct ssh *ssh, int type, uint32_t seq)
+{
+ if (ssh == NULL || ssh->state == NULL ||
+ ssh->state->after_authentication || !ssh->state->server_side)
+ return 0;
+ if (++ssh->state->nunimpl_packets < SSH_MAX_PREAUTH_UNIMPL_MESSAGES)
+ return 0;
+ return sshpkt_protocol_error(ssh, "too many unknown packets");
+}
+
/* roundup current message to pad bytes */
int
sshpkt_add_padding(struct ssh *ssh, u_char pad)
diff --git a/packet.h b/packet.h
index 35a5f8a6e..fdf2a9d80 100644
--- a/packet.h
+++ b/packet.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.h,v 1.109 2026/10/30 04:36:21 djm Exp $ */
+/* $OpenBSD: packet.h,v 1.110 2026/11/25 06:57:05 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo at cs.hut.fi>
@@ -176,6 +176,7 @@ int sshpkt_disconnect(struct ssh *, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
int sshpkt_protocol_error(struct ssh *, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
+int sshpkt_record_unimplemented(struct ssh *ssh, int type, uint32_t seq);
int sshpkt_add_padding(struct ssh *, u_char);
void sshpkt_fatal(struct ssh *ssh, int r, const char *fmt, ...)
__attribute__((format(printf, 3, 4)))
diff --git a/ssh.h b/ssh.h
index cd95dd831..4ff9e1645 100644
--- a/ssh.h
+++ b/ssh.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ssh.h,v 1.91 2024/09/25 23:01:39 jsg Exp $ */
+/* $OpenBSD: ssh.h,v 1.92 2026/11/25 06:57:05 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo at cs.hut.fi>
@@ -91,3 +91,7 @@
/* Limits for banner exchange */
#define SSH_MAX_BANNER_LEN 8192
#define SSH_MAX_PRE_BANNER_LINES 1024
+
+/* Other preauth limits */
+#define SSH_MAX_PREAUTH_UNIMPL_MESSAGES 32
+
--
To stop receiving notification emails like this one, please contact
djm at mindrot.org.
More information about the openssh-commits
mailing list