nginx: Fix CVE-2026-40701

This patch applies the upstream fix as referenced in [2], using the
commit shown in [1].

[1] https://github.com/nginx/nginx/commit/d2b8d47741820c9fb134c6731ecb40b21f3085b1
[2] https://nginx.org/en/security_advisories.html

Signed-off-by: Hetvi Thakar <hthakar@cisco.com>
Signed-off-by: Anuj Mittal <anuj.mittal@oss.qualcomm.com>
This commit is contained in:
Hetvi Thakar authored and Anuj Mittal committed 2026-10-28 12:31:39 +05:30
1 parent 578ad71dfe
commit d023b652ac
3 files changed
+82

No files matched your search

@@ -0,0 +1,74 @@
From d2b8d47741820c9fb134c6731ecb40b21f3085b1 Mon Sep 17 00:00:00 2001
From: Roman Arutyunyan <arut@nginx.com>
Date: Tue, 21 Apr 2026 14:51:41 +0400
Subject: [PATCH] OCSP: resolve cleanup on connection close
Previously, when a client SSL connection was terminated (typically due to a
timeout) while resolving an OCSP responder, the OCSP context was freed, but
the resolve context was not. This resulted in use-after-free on resolve
completion.
Reported by Leo Lin.
CVE: CVE-2026-40701
Upstream-Status: Backport [https://github.com/nginx/nginx/commit/d2b8d47741820c9fb134c6731ecb40b21f3085b1]
(cherry picked from commit d2b8d47741820c9fb134c6731ecb40b21f3085b1)
Signed-off-by: Hetvi Thakar <hthakar@cisco.com>
---
src/event/ngx_event_openssl_stapling.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/event/ngx_event_openssl_stapling.c b/src/event/ngx_event_openssl_stapling.c
index a0a8031c7..231bdeceb 100644
--- a/src/event/ngx_event_openssl_stapling.c
+++ b/src/event/ngx_event_openssl_stapling.c
@@ -113,6 +113,7 @@ struct ngx_ssl_ocsp_ctx_s {
ngx_resolver_t *resolver;
ngx_msec_t resolver_timeout;
+ ngx_resolver_ctx_t *resolve;
ngx_msec_t timeout;
@@ -1341,6 +1342,10 @@ ngx_ssl_ocsp_done(ngx_ssl_ocsp_ctx_t *ctx)
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ctx->log, 0,
"ssl ocsp done");
+ if (ctx->resolve) {
+ ngx_resolve_name_done(ctx->resolve);
+ }
+
if (ctx->peer.connection) {
ngx_close_connection(ctx->peer.connection);
}
@@ -1433,7 +1438,10 @@ ngx_ssl_ocsp_request(ngx_ssl_ocsp_ctx_t *ctx)
resolve->data = ctx;
resolve->timeout = ctx->resolver_timeout;
+ ctx->resolve = resolve;
+
if (ngx_resolve_name(resolve) != NGX_OK) {
+ ctx->resolve = NULL;
ngx_ssl_ocsp_error(ctx);
return;
}
@@ -1522,6 +1530,7 @@ ngx_ssl_ocsp_resolve_handler(ngx_resolver_ctx_t *resolve)
}
ngx_resolve_name_done(resolve);
+ ctx->resolve = NULL;
ngx_ssl_ocsp_connect(ctx);
return;
@@ -1529,6 +1538,8 @@ ngx_ssl_ocsp_resolve_handler(ngx_resolver_ctx_t *resolve)
failed:
ngx_resolve_name_done(resolve);
+ ctx->resolve = NULL;
+
ngx_ssl_ocsp_error(ctx);
}
--
2.35.6
@@ -1,5 +1,9 @@
require nginx.inc
SRC_URI:append = " \
file://CVE-2026-40701.patch \
"
LIC_FILES_CHKSUM = "file://LICENSE;md5=3dc49537b08b14c8b66ad247bb4c4593"
SRC_URI[sha256sum] = "2c96a946bfb0882a21744ed429770a2123ae1828c7c48665092993ddee91a918"
@@ -1,5 +1,9 @@
require nginx.inc
SRC_URI:append = " \
file://CVE-2026-40701.patch \
"
# 1.28.x branch is the current stable branch, the recommended default
# 1.29.x is the current mainline branches containing all new features
DEFAULT_PREFERENCE = "-1"