Commit 3b7808c21b for openssl.org
commit 3b7808c21b7f05307b9f6ebd617c3ba42d87652b
Author: Andrew Dinh <andrewd@openssl.org>
Date: Sun Nov 15 17:00:41 2026 +0700
ssl/quic/quic_impl.c: fix deadlock rejecting pending connection
If a new pending connection callback (set
by SSL_CTX_set_new_pending_conn_cb()) returns 0,
port_new_handshake_layer() frees the new pending connection while
the engine lock is still held. ossl_quic_free() then calls qctx_lock()
on that same lock, so the listener deadlocks.
Only run qc_cleanup() without taking a lock and exit early
when ossl_quic_free() is called on a pending connection that has
no channel: a connection like that has no shared resources to clean up.
Resolves: https://github.com/openssl/project/issues/2129
Link: https://github.com/openssl/openssl/pull/33664#discussion_r4560006747
Assisted-by: Claude:claude-opus-5-5
Reviewed-by: Bob Beck <beck@openssl.org>
Reviewed-by: Saša NedvÄ›dický <sashan@openssl.org>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Merge-date: Fri Nov 20 18:34:32 2026
Merged-from: https://github.com/openssl/openssl/pull/33744
diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c
index 92f85f0106..5134b4f766 100644
--- a/ssl/quic/quic_impl.c
+++ b/ssl/quic/quic_impl.c
@@ -783,6 +783,16 @@ void ossl_quic_free(SSL *s)
return;
}
+ /*
+ * A pending connection whose channel has been detached is being discarded
+ * by the port. It has no shared resources to clean up, and the port lock
+ * may already be held by the caller.
+ */
+ if (!ctx.is_stream && ctx.qc->pending && ctx.qc->ch == NULL) {
+ qc_cleanup(ctx.qc, /*have_lock=*/0);
+ return;
+ }
+
qctx_lock(&ctx);
if (ctx.is_stream) {