Commit c8c3916329 for openssl.org
commit c8c3916329edc7861f6b3e49432ea1aeafd50a61
Author: Alexandr Nedvedicky <sashan@openssl.org>
Date: Thu Nov 19 09:53:14 2026 +0100
Fix SSL_set0_{r,w}bio() for DTLS and QUIC objects leaking BIO on failure
SSL_set0_rbio()/SSL_set0_wbio() must always consume the supplied BIO
object, regardless success/failure of underlying set operation.
Resolves: https://github.com/openssl/openssl/issues/33645
Fixes: 2f0ad0d852ea "DTLS 1.3 Limit DTLSv1_listen to DTLS1.2 and add SSL Listener for DTLS"
Fixes: 22d53c88838d "QUIC Front-End I/O API"
Co-authored-by: Andrew Dinh <andrewd@openssl.org>
Reviewed-by: Andrew Dinh <andrewd@openssl.org>
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Bob Beck <beck@openssl.org>
Merge-date: Thu Nov 26 09:41:47 2026
Merged-from: https://github.com/openssl/openssl/pull/33840
diff --git a/ssl/d1_lib.c b/ssl/d1_lib.c
index 7d60aff0b2..f6408478f6 100644
--- a/ssl/d1_lib.c
+++ b/ssl/d1_lib.c
@@ -2865,8 +2865,10 @@ void ossl_dtls_listener_set0_net_rbio(SSL *s, BIO *bio)
DTLS_LISTENER *dl;
BIO *old_rbio;
- if (!IS_DTLS_LISTENER(s))
+ if (!IS_DTLS_LISTENER(s)) {
+ BIO_free_all(bio);
return;
+ }
dl = (DTLS_LISTENER *)s;
@@ -2892,12 +2894,6 @@ void ossl_dtls_listener_set0_net_rbio(SSL *s, BIO *bio)
old_rbio = dl->net_rbio;
- /* No change - nothing to do */
- if (old_rbio == bio) {
- ossl_crypto_mutex_unlock(dl->mutex);
- return;
- }
-
dl->net_rbio = bio;
ossl_crypto_mutex_unlock(dl->mutex);
@@ -2942,8 +2938,10 @@ void ossl_dtls_listener_set0_net_wbio(SSL *s, BIO *bio)
DTLS_LISTENER *dl;
BIO *old_wbio;
- if (!IS_DTLS_LISTENER(s))
+ if (!IS_DTLS_LISTENER(s)) {
+ BIO_free_all(bio);
return;
+ }
dl = (DTLS_LISTENER *)s;
@@ -2955,6 +2953,7 @@ void ossl_dtls_listener_set0_net_wbio(SSL *s, BIO *bio)
/* No change - nothing to do */
if (old_wbio == bio) {
+ BIO_free_all(bio);
return;
}
diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c
index 5134b4f766..29c656265c 100644
--- a/ssl/quic/quic_impl.c
+++ b/ssl/quic/quic_impl.c
@@ -1213,11 +1213,17 @@ void ossl_quic_conn_set0_net_rbio(SSL *s, BIO *net_rbio)
QCTX ctx;
if (!expect_quic_csl(s, &ctx))
- return;
+ goto free;
- /* Returns 0 if no change. */
+ /* Returns 0 if no change or on failure. */
if (!quic_set0_net_rbio(ctx.obj, net_rbio))
- return;
+ goto free;
+
+ net_rbio = NULL;
+
+free:
+ /* we are supposed to consume net_rbio */
+ BIO_free_all(net_rbio);
}
void ossl_quic_conn_set0_net_wbio(SSL *s, BIO *net_wbio)
@@ -1225,11 +1231,17 @@ void ossl_quic_conn_set0_net_wbio(SSL *s, BIO *net_wbio)
QCTX ctx;
if (!expect_quic_csl(s, &ctx))
- return;
+ goto free;
- /* Returns 0 if no change. */
+ /* Returns 0 if no change or on failure. */
if (!quic_set0_net_wbio(ctx.obj, net_wbio))
- return;
+ goto free;
+
+ net_wbio = NULL;
+
+free:
+ /* we are supposed to consume net_wbio */
+ BIO_free_all(net_wbio);
}
BIO *ossl_quic_conn_get_net_rbio(const SSL *s)