From: Hugo Landau Date: Sun, 10 Mar 2024 00:29:07 +0000 (+0000) Subject: QUIC APL: Avoid having a mutex variable where not needed X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f27ac813cb130591b3163c8af0446b9f7029de34;p=thirdparty%2Fopenssl.git QUIC APL: Avoid having a mutex variable where not needed Reviewed-by: Matt Caswell Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/23334) --- diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index 39307621d2b..10c1ee859e7 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -551,11 +551,11 @@ static void qc_cleanup(QUIC_CONNECTION *qc, int have_lock) qc->engine = NULL; } +#if defined(OPENSSL_THREADS) if (have_lock) /* tsan doesn't like freeing locked mutexes */ ossl_crypto_mutex_unlock(qc->mutex); -#if defined(OPENSSL_THREADS) if (qc->listener == NULL) ossl_crypto_mutex_free(&qc->mutex); #endif @@ -569,7 +569,9 @@ static void quic_free_listener(QCTX *ctx) ossl_quic_port_drop_incoming(ctx->ql->port); ossl_quic_port_free(ctx->ql->port); ossl_quic_engine_free(ctx->ql->engine); +#if defined(OPENSSL_THREADS) ossl_crypto_mutex_free(&ctx->ql->mutex); +#endif } QUIC_TAKES_LOCK @@ -1644,7 +1646,9 @@ static int create_channel(QUIC_CONNECTION *qc, SSL_CTX *ctx) engine_args.libctx = ctx->libctx; engine_args.propq = ctx->propq; +#if defined(OPENSSL_THREADS) engine_args.mutex = qc->mutex; +#endif engine_args.now_cb = get_time_cb; engine_args.now_cb_arg = qc; qc->engine = ossl_quic_engine_new(&engine_args); @@ -4068,7 +4072,9 @@ SSL *ossl_quic_new_listener(SSL_CTX *ctx, uint64_t flags) engine_args.libctx = ctx->libctx; engine_args.propq = ctx->propq; +#if defined(OPENSSL_THREADS) engine_args.mutex = ql->mutex; +#endif if ((ql->engine = ossl_quic_engine_new(&engine_args)) == NULL) { QUIC_RAISE_NON_NORMAL_ERROR(NULL, ERR_R_INTERNAL_ERROR, NULL); goto err; @@ -4097,6 +4103,9 @@ err: if (ql != NULL) ossl_quic_engine_free(ql->engine); +#if defined(OPENSSL_THREADS) + ossl_crypto_mutex_free(&ql->mutex); +#endif OPENSSL_free(ql); return NULL; } @@ -4214,7 +4223,9 @@ static QUIC_CONNECTION *create_qc_from_incoming_conn(QUIC_LISTENER *ql, QUIC_CHA qc->engine = ql->engine; qc->port = ql->port; qc->ch = ch; +#if defined(OPENSSL_THREADS) qc->mutex = ql->mutex; +#endif qc->tls = ossl_quic_channel_get0_tls(ch); qc->last_net_bio_epoch = UINT64_MAX; qc->started = 1; diff --git a/ssl/quic/quic_local.h b/ssl/quic/quic_local.h index 059251506e4..85c73fe6c71 100644 --- a/ssl/quic/quic_local.h +++ b/ssl/quic/quic_local.h @@ -162,7 +162,9 @@ struct quic_conn_st { * The mutex used to synchronise access to the QUIC_CHANNEL. We own this but * provide it to the channel. */ +#if defined(OPENSSL_THREADS) CRYPTO_MUTEX *mutex; +#endif /* * If we have a default stream attached, this is the internal XSO @@ -269,11 +271,13 @@ struct quic_listener_st { /* The QUIC port representing the QUIC listener and socket. */ QUIC_PORT *port; +#if defined(OPENSSL_THREADS) /* * The mutex used to synchronise access to the QUIC_ENGINE. We own this but * provide it to the engine. */ CRYPTO_MUTEX *mutex; +#endif /* Have we started listening yet? */ unsigned int listening : 1;