]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC APL: Fix refcounting for listeners
authorHugo Landau <hlandau@openssl.org>
Mon, 5 Feb 2024 17:32:51 +0000 (17:32 +0000)
committerViktor Dukhovni <openssl-users@dukhovni.org>
Wed, 11 Sep 2024 08:00:08 +0000 (18:00 +1000)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23334)

ssl/quic/quic_impl.c

index f6a8ed3f67862d3244278445527ad4290e63c7a0..65cf97947405e09d5c75fbf8f393eb32b81be550 100644 (file)
@@ -546,17 +546,18 @@ static void qc_cleanup(QUIC_CONNECTION *qc, int have_lock)
         quic_unref_port_bios(qc->port);
         ossl_quic_port_free(qc->port);
         qc->port = NULL;
-    }
 
-    ossl_quic_engine_free(qc->engine);
-    qc->engine = NULL;
+        ossl_quic_engine_free(qc->engine);
+        qc->engine = NULL;
+    }
 
     if (have_lock)
         /* tsan doesn't like freeing locked mutexes */
         ossl_crypto_mutex_unlock(qc->mutex);
 
 #if defined(OPENSSL_THREADS)
-    ossl_crypto_mutex_free(&qc->mutex);
+    if (qc->listener == NULL)
+        ossl_crypto_mutex_free(&qc->mutex);
 #endif
 }
 
@@ -662,6 +663,10 @@ void ossl_quic_free(SSL *s)
      * us
      */
     qc_cleanup(ctx.qc, /*have_lock=*/1);
+    /* Note: SSL_free calls OPENSSL_free(qc) for us */
+
+    if (ctx.qc->listener != NULL)
+        SSL_free(&ctx.qc->listener->obj.ssl);
 }
 
 /* SSL method init */
@@ -4185,8 +4190,14 @@ static QUIC_CONNECTION *create_qc_from_incoming_conn(QUIC_LISTENER *ql, QUIC_CHA
 {
     QUIC_CONNECTION *qc = NULL;
 
+    if (!SSL_up_ref(&ql->obj.ssl)) {
+        QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_INTERNAL_ERROR, NULL);
+        goto err;
+    }
+
     if ((qc = OPENSSL_zalloc(sizeof(*qc))) == NULL) {
         QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_CRYPTO_LIB, NULL);
+        SSL_free(&ql->obj.ssl);
         goto err;
     }
 
@@ -4194,6 +4205,7 @@ static QUIC_CONNECTION *create_qc_from_incoming_conn(QUIC_LISTENER *ql, QUIC_CHA
                             SSL_TYPE_QUIC_CONNECTION,
                             &ql->obj.ssl, NULL, NULL)) {
         QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_INTERNAL_ERROR, NULL);
+        SSL_free(&ql->obj.ssl);
         goto err;
     }