Ensure we free all the BIOs in a chain for QUIC like we do in TLS
authorMatt Caswell <matt@openssl.org>
Wed, 20 Sep 2023 15:25:44 +0000 (16:25 +0100)
committerMatt Caswell <matt@openssl.org>
Fri, 22 Sep 2023 12:56:43 +0000 (13:56 +0100)
An application may pass in a whole BIO chain via SSL_set_bio(). When we
free the BIO we should be using BIO_free_all() not BIO_free() like we do
with TLS.

Reviewed-by: Tim Hudson <tjh@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22157)

ssl/quic/quic_impl.c
ssl/quic/quic_tserver.c
test/quic_multistream_test.c

index beec26c019c1de475e8827bb37ac034adabac96d..cb927fa52d131263af5ec8d9dedb7a4985b9321f 100644 (file)
@@ -545,8 +545,8 @@ void ossl_quic_free(SSL *s)
 
     ossl_quic_channel_free(ctx.qc->ch);
 
-    BIO_free(ctx.qc->net_rbio);
-    BIO_free(ctx.qc->net_wbio);
+    BIO_free_all(ctx.qc->net_rbio);
+    BIO_free_all(ctx.qc->net_wbio);
 
     /* Note: SSL_free calls OPENSSL_free(qc) for us */
 
@@ -876,7 +876,7 @@ void ossl_quic_conn_set0_net_rbio(SSL *s, BIO *net_rbio)
     if (!ossl_quic_channel_set_net_rbio(ctx.qc->ch, net_rbio))
         return;
 
-    BIO_free(ctx.qc->net_rbio);
+    BIO_free_all(ctx.qc->net_rbio);
     ctx.qc->net_rbio = net_rbio;
 
     if (net_rbio != NULL)
@@ -903,7 +903,7 @@ void ossl_quic_conn_set0_net_wbio(SSL *s, BIO *net_wbio)
     if (!ossl_quic_channel_set_net_wbio(ctx.qc->ch, net_wbio))
         return;
 
-    BIO_free(ctx.qc->net_wbio);
+    BIO_free_all(ctx.qc->net_wbio);
     ctx.qc->net_wbio = net_wbio;
 
     if (net_wbio != NULL)
index 92c17d10f3c64846a61390e195b1716c097ddf43..3630577e707b918affe75a4c9a3a2edbd998808c 100644 (file)
@@ -159,8 +159,8 @@ void ossl_quic_tserver_free(QUIC_TSERVER *srv)
         return;
 
     ossl_quic_channel_free(srv->ch);
-    BIO_free(srv->args.net_rbio);
-    BIO_free(srv->args.net_wbio);
+    BIO_free_all(srv->args.net_rbio);
+    BIO_free_all(srv->args.net_wbio);
     OPENSSL_free(srv->ssl);
     SSL_free(srv->tls);
     SSL_CTX_free(srv->ctx);
index b401e78e329ba008e817a4f6aa88a4c9d2d3b7e1..2ad4ef292e2d8ab60bc4693ef74289e03713d794 100644 (file)
@@ -746,10 +746,8 @@ static int helper_init(struct helper *h, int free_order, int blocking,
         BIO_set_data(h->s_qtf_wbio, h->qtf);
     }
 
-    if (!need_injector)
-        h->s_net_bio_own = NULL;
-
-    h->s_qtf_wbio_own   = NULL;
+    h->s_net_bio_own = NULL;
+    h->s_qtf_wbio_own = NULL;
 
     h->c_fd = BIO_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP, 0);
     if (!TEST_int_ge(h->c_fd, 0))