[PATCH] OpenSSL: Clear cached peer X509 pointers on TLS shutdown

Andrzej Ostruszka andrzejo at chromium.org
Thu Dec 3 06:13:14 PST 2026


tls_verify_cb() caches borrowed, un-refcounted X509 pointers from the
verification context into struct tls_connection (peer_cert, peer_issuer,
and peer_issuer_issuer).

tls_connection_shutdown() resets the SSL object via SSL_clear() for EAP
fast re-authentication without clearing these pointers. If the peer
subsequently rejects session resumption, the TLS library frees the prior
SSL_SESSION and its certificate chain, leaving the cached pointers
dangling. When the new handshake uses a shallower certificate chain and
includes a stapled OCSP response, peer_issuer_issuer is not overwritten
and OCSP verification can dereference the freed X509 object via
X509_dup().

Clear conn->peer_cert, conn->peer_issuer, and conn->peer_issuer_issuer
in tls_connection_shutdown() before resetting the SSL state.

Fixes: 080585c01a1e ("Add support for OCSP stapling to validate server certificate")
Fixes: 6bf61fb28882 ("OpenSSL: Use certificates from TLS authentication in OCSP stapling")
Signed-off-by: Andrzej Ostruszka <andrzejo at chromium.org>
---
 src/crypto/tls_openssl.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/crypto/tls_openssl.c b/src/crypto/tls_openssl.c
index f6caed368..f610f234b 100644
--- a/src/crypto/tls_openssl.c
+++ b/src/crypto/tls_openssl.c
@@ -2114,6 +2114,14 @@ int tls_connection_shutdown(void *ssl_ctx, struct tls_connection *conn)
 	if (conn == NULL)
 		return -1;
 
+	/* Clear borrowed peer certificate pointers before resetting the SSL
+	 * session so stale pointers cannot survive into a subsequent handshake
+	 * (e.g., during EAP fast re-authentication if session resumption is
+	 * rejected). */
+	conn->peer_cert = NULL;
+	conn->peer_issuer = NULL;
+	conn->peer_issuer_issuer = NULL;
+
 	/* Shutdown previous TLS connection without notifying the peer
 	 * because the connection was already terminated in practice
 	 * and "close notify" shutdown alert would confuse AS. */
-- 
2.56.1.911.g883d8bcb20-goog




More information about the Hostap mailing list