new file mode 100644
@@ -0,0 +1,121 @@
+From 63d74d545295faa3d147ef704d740da4805f13f4 Mon Sep 17 00:00:00 2001
+From: Aleksei Bavshin <a.bavshin@nginx.com>
+Date: Mon, 21 Sep 2026 09:57:19 -0700
+Subject: [PATCH] Stream ssl_preread: forbid trailing data in extensions
+
+As required explicitly in RFC 9846 Section 4.3 and implicitly in all the
+previous versions of TLS extensions specification.
+
+Reported by Vivek Parikh, BreachX Zero Day Labs using Typhon AI Mil v2.
+
+CVE: CVE-2026-123640
+Upstream-Status: Backport [https://github.com/nginx/nginx/commit/63d74d545295faa3d147ef704d740da4805f13f4]
+
+Signed-off-by: Hetvi Thakar <hthakar@cisco.com>
+---
+ src/stream/ngx_stream_ssl_preread_module.c | 40 +++++++++++++++++++---
+ 1 file changed, 35 insertions(+), 5 deletions(-)
+
+diff --git a/src/stream/ngx_stream_ssl_preread_module.c b/src/stream/ngx_stream_ssl_preread_module.c
+index 3fc83ff..8f2d333 100644
+--- a/src/stream/ngx_stream_ssl_preread_module.c
++++ b/src/stream/ngx_stream_ssl_preread_module.c
+@@ -224,6 +224,7 @@ ngx_stream_ssl_preread_parse_record(ngx_stream_ssl_preread_ctx_t *ctx,
+ sw_cs, /* cipher_suites */
+ sw_cm_len, /* compression_methods length */
+ sw_cm, /* compression_methods */
++ sw_ext_len, /* extensions length */
+ sw_ext, /* extension */
+ sw_ext_header, /* extension_type, extension_data length */
+ sw_sni_len, /* SNI length */
+@@ -330,11 +331,20 @@ ngx_stream_ssl_preread_parse_record(ngx_stream_ssl_preread_ctx_t *ctx,
+ return NGX_OK;
+ }
+
+- state = sw_ext;
++ state = sw_ext_len;
+ dst = p;
+ size = 2;
+ break;
+
++ case sw_ext_len:
++ if (left != (size_t) (p[0] << 8) + p[1]) {
++ ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ctx->log, 0,
++ "ssl preread: extensions length error");
++ return NGX_DECLINED;
++ }
++
++ /* fall through */
++
+ case sw_ext:
+ if (left == 0) {
+ return NGX_OK;
+@@ -346,6 +356,8 @@ ngx_stream_ssl_preread_parse_record(ngx_stream_ssl_preread_ctx_t *ctx,
+ break;
+
+ case sw_ext_header:
++ ext = (p[2] << 8) + p[3];
++
+ if (p[0] == 0 && p[1] == 0 && ctx->host.data == NULL) {
+ /* SNI extension */
+ state = sw_sni_len;
+@@ -372,11 +384,17 @@ ngx_stream_ssl_preread_parse_record(ngx_stream_ssl_preread_ctx_t *ctx,
+
+ state = sw_ext;
+ dst = NULL;
+- size = (p[2] << 8) + p[3];
++ size = ext;
+ break;
+
+ case sw_sni_len:
+- ext = (p[0] << 8) + p[1];
++ if (ext < 5 || ext != 2 + (size_t) (p[0] << 8) + p[1]) {
++ ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ctx->log, 0,
++ "ssl preread: SNI format error");
++ return NGX_DECLINED;
++ }
++ ext -= 2;
++
+ state = sw_sni_host_head;
+ dst = p;
+ size = 3;
+@@ -416,7 +434,12 @@ ngx_stream_ssl_preread_parse_record(ngx_stream_ssl_preread_ctx_t *ctx,
+ break;
+
+ case sw_alpn_len:
+- ext = (p[0] << 8) + p[1];
++ if (ext < 4 || ext != 2 + (size_t) (p[0] << 8) + p[1]) {
++ ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ctx->log, 0,
++ "ssl preread: ALPN format error");
++ return NGX_DECLINED;
++ }
++ ext -= 2;
+
+ ctx->alpn.data = ngx_pnalloc(ctx->pool, ext);
+ if (ctx->alpn.data == NULL) {
+@@ -469,6 +492,14 @@ ngx_stream_ssl_preread_parse_record(ngx_stream_ssl_preread_ctx_t *ctx,
+ break;
+
+ case sw_supver_len:
++ size = p[0];
++
++ if (ext < 3 || ext != 1 + size) {
++ ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ctx->log, 0,
++ "ssl preread: supported_versions format error");
++ return NGX_DECLINED;
++ }
++
+ ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ctx->log, 0,
+ "ssl preread: supported_versions");
+
+@@ -478,7 +509,6 @@ ngx_stream_ssl_preread_parse_record(ngx_stream_ssl_preread_ctx_t *ctx,
+
+ state = sw_ext;
+ dst = NULL;
+- size = p[0];
+ break;
+ }
+
+--
+2.35.6
+
new file mode 100644
@@ -0,0 +1,61 @@
+From 1e668b7e856198f89a2eec0b94b54b826eb5c4f7 Mon Sep 17 00:00:00 2001
+From: Aleksei Bavshin <a.bavshin@nginx.com>
+Date: Tue, 29 Sep 2026 09:19:30 -0700
+Subject: [PATCH] Stream ssl_preread: forbid duplicate SNI and ALPN
+
+As stated in the TLS Extensions specification (RFC 3546) and all
+subsequent TLS specification updates,
+
+: There MUST NOT be more than one extension of the same type.
+
+Such a ClientHello is now treated as malformed, as with other parsing
+errors.
+
+CVE: CVE-2026-123640
+Upstream-Status: Backport [https://github.com/nginx/nginx/commit/1e668b7e856198f89a2eec0b94b54b826eb5c4f7]
+
+Signed-off-by: Hetvi Thakar <hthakar@cisco.com>
+---
+ src/stream/ngx_stream_ssl_preread_module.c | 18 ++++++++++++++++--
+ 1 file changed, 16 insertions(+), 2 deletions(-)
+
+diff --git a/src/stream/ngx_stream_ssl_preread_module.c b/src/stream/ngx_stream_ssl_preread_module.c
+index 8f2d333..7aa8669 100644
+--- a/src/stream/ngx_stream_ssl_preread_module.c
++++ b/src/stream/ngx_stream_ssl_preread_module.c
+@@ -358,16 +358,30 @@ ngx_stream_ssl_preread_parse_record(ngx_stream_ssl_preread_ctx_t *ctx,
+ case sw_ext_header:
+ ext = (p[2] << 8) + p[3];
+
+- if (p[0] == 0 && p[1] == 0 && ctx->host.data == NULL) {
++ if (p[0] == 0 && p[1] == 0) {
+ /* SNI extension */
++
++ if (ctx->host.data != NULL) {
++ ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ctx->log, 0,
++ "ssl preread: duplicate SNI");
++ return NGX_DECLINED;
++ }
++
+ state = sw_sni_len;
+ dst = p;
+ size = 2;
+ break;
+ }
+
+- if (p[0] == 0 && p[1] == 16 && ctx->alpn.data == NULL) {
++ if (p[0] == 0 && p[1] == 16) {
+ /* ALPN extension */
++
++ if (ctx->alpn.data != NULL) {
++ ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ctx->log, 0,
++ "ssl preread: duplicate ALPN");
++ return NGX_DECLINED;
++ }
++
+ state = sw_alpn_len;
+ dst = p;
+ size = 2;
+--
+2.35.6
+
@@ -20,6 +20,8 @@ SRC_URI:append = " \
file://CVE-2026-15176.patch \
file://CVE-2026-97205.patch \
file://CVE-2026-123633.patch \
+ file://CVE-2026-123640_p1.patch \
+ file://CVE-2026-123640_p2.patch \
"
LIC_FILES_CHKSUM = "file://LICENSE;md5=3dc49537b08b14c8b66ad247bb4c4593"
@@ -20,6 +20,8 @@ SRC_URI:append = " \
file://CVE-2026-15176.patch \
file://CVE-2026-97205.patch \
file://CVE-2026-123633.patch \
+ file://CVE-2026-123640_p1.patch \
+ file://CVE-2026-123640_p2.patch \
"
# 1.28.x branch is the current stable branch, the recommended default