summaryrefslogtreecommitdiffstats
path: root/ssl
diff options
context:
space:
mode:
authorHugo Landau <hlandau@openssl.org>2023-05-17 13:15:01 +0100
committerHugo Landau <hlandau@openssl.org>2023-05-24 10:34:54 +0100
commit629b408c12c56b2c9e3279de8658718e8dd658a2 (patch)
tree13916b230422a8d1b27fcf9467ce8bbdcb45646f /ssl
parent1a0de4c1eea1f32a3e1113add26625d49b3854d8 (diff)
QUIC: Fix bugs where threading is disabled
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/20856)
Diffstat (limited to 'ssl')
-rw-r--r--ssl/quic/quic_impl.c19
-rw-r--r--ssl/quic/quic_reactor.c8
-rw-r--r--ssl/quic/quic_tserver.c6
3 files changed, 33 insertions, 0 deletions
diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c
index 1f76232c49..ac0e9f0380 100644
--- a/ssl/quic/quic_impl.c
+++ b/ssl/quic/quic_impl.c
@@ -258,14 +258,18 @@ static int ossl_unused expect_quic_conn_only(const SSL *s, QCTX *ctx)
*/
static void quic_lock(QUIC_CONNECTION *qc)
{
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_lock(qc->mutex);
+#endif
}
/* Precondition: Channel mutex is held (unchecked) */
QUIC_NEEDS_LOCK
static void quic_unlock(QUIC_CONNECTION *qc)
{
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_unlock(qc->mutex);
+#endif
}
@@ -304,11 +308,15 @@ SSL *ossl_quic_new(SSL_CTX *ctx)
if (qc->tls == NULL || (sc = SSL_CONNECTION_FROM_SSL(qc->tls)) == NULL)
goto err;
+#if defined(OPENSSL_THREADS)
if ((qc->mutex = ossl_crypto_mutex_new()) == NULL)
goto err;
+#endif
+#if !defined(OPENSSL_NO_QUIC_THREAD_ASSIST)
qc->is_thread_assisted
= (ssl_base->method == OSSL_QUIC_client_thread_method());
+#endif
qc->as_server = 0; /* TODO(QUIC): server support */
qc->as_server_state = qc->as_server;
@@ -338,6 +346,9 @@ SSL *ossl_quic_new(SSL_CTX *ctx)
err:
if (qc != NULL) {
+#if defined(OPENSSL_THREADS)
+ ossl_crypto_mutex_free(qc->mutex);
+#endif
ossl_quic_channel_free(qc->ch);
SSL_free(qc->tls);
}
@@ -418,10 +429,12 @@ void ossl_quic_free(SSL *s)
/* Ensure we have no remaining XSOs. */
assert(ctx.qc->num_xso == 0);
+#if !defined(OPENSSL_NO_QUIC_THREAD_ASSIST)
if (ctx.qc->is_thread_assisted && ctx.qc->started) {
ossl_quic_thread_assist_wait_stopped(&ctx.qc->thread_assist);
ossl_quic_thread_assist_cleanup(&ctx.qc->thread_assist);
}
+#endif
ossl_quic_channel_free(ctx.qc->ch);
@@ -431,7 +444,9 @@ void ossl_quic_free(SSL *s)
/* Note: SSL_free calls OPENSSL_free(qc) for us */
SSL_free(ctx.qc->tls);
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_free(&ctx.qc->mutex); /* freed while still locked */
+#endif
}
/* SSL method init */
@@ -491,8 +506,10 @@ void ossl_quic_conn_force_assist_thread_wake(SSL *s)
if (!expect_quic(s, &ctx))
return;
+#if !defined(OPENSSL_NO_QUIC_THREAD_ASSIST)
if (ctx.qc->is_thread_assisted && ctx.qc->started)
ossl_quic_thread_assist_notify_deadline_changed(&ctx.qc->thread_assist);
+#endif
}
QUIC_NEEDS_LOCK
@@ -1121,9 +1138,11 @@ static int ensure_channel_started(QUIC_CONNECTION *qc)
|| !ossl_quic_channel_start(qc->ch))
goto err;
+#if !defined(OPENSSL_NO_QUIC_THREAD_ASSIST)
if (qc->is_thread_assisted)
if (!ossl_quic_thread_assist_init_start(&qc->thread_assist, qc->ch))
goto err;
+#endif
}
qc->started = 1;
diff --git a/ssl/quic/quic_reactor.c b/ssl/quic/quic_reactor.c
index 853d62f947..4d65a408bb 100644
--- a/ssl/quic/quic_reactor.c
+++ b/ssl/quic/quic_reactor.c
@@ -175,8 +175,10 @@ static int poll_two_fds(int rfd, int rfd_want_read,
/* Do not block forever; should not happen. */
return 0;
+# if defined(OPENSSL_THREADS)
if (mutex != NULL)
ossl_crypto_mutex_unlock(mutex);
+# endif
do {
/*
@@ -200,8 +202,10 @@ static int poll_two_fds(int rfd, int rfd_want_read,
pres = select(maxfd + 1, &rfd_set, &wfd_set, &efd_set, ptv);
} while (pres == -1 && get_last_socket_error_is_eintr());
+# if defined(OPENSSL_THREADS)
if (mutex != NULL)
ossl_crypto_mutex_lock(mutex);
+# endif
return pres < 0 ? 0 : 1;
#else
@@ -232,8 +236,10 @@ static int poll_two_fds(int rfd, int rfd_want_read,
/* Do not block forever; should not happen. */
return 0;
+# if defined(OPENSSL_THREADS)
if (mutex != NULL)
ossl_crypto_mutex_unlock(mutex);
+# endif
do {
if (ossl_time_is_infinite(deadline)) {
@@ -247,8 +253,10 @@ static int poll_two_fds(int rfd, int rfd_want_read,
pres = poll(pfds, npfd, timeout_ms);
} while (pres == -1 && get_last_socket_error_is_eintr());
+# if defined(OPENSSL_THREADS)
if (mutex != NULL)
ossl_crypto_mutex_lock(mutex);
+# endif
return pres < 0 ? 0 : 1;
#endif
diff --git a/ssl/quic/quic_tserver.c b/ssl/quic/quic_tserver.c
index 6788851f29..6fc341f3c4 100644
--- a/ssl/quic/quic_tserver.c
+++ b/ssl/quic/quic_tserver.c
@@ -67,8 +67,10 @@ QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args,
srv->args = *args;
+#if defined(OPENSSL_THREADS)
if ((srv->mutex = ossl_crypto_mutex_new()) == NULL)
goto err;
+#endif
srv->ctx = SSL_CTX_new_ex(srv->args.libctx, srv->args.propq, TLS_method());
if (srv->ctx == NULL)
@@ -106,7 +108,9 @@ QUIC_TSERVER *ossl_quic_tserver_new(const QUIC_TSERVER_ARGS *args,
err:
if (srv != NULL) {
ossl_quic_channel_free(srv->ch);
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_free(&srv->mutex);
+#endif
}
OPENSSL_free(srv);
@@ -123,7 +127,9 @@ void ossl_quic_tserver_free(QUIC_TSERVER *srv)
BIO_free(srv->args.net_wbio);
SSL_free(srv->tls);
SSL_CTX_free(srv->ctx);
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_free(&srv->mutex);
+#endif
OPENSSL_free(srv);
}