From: Frederic Lecaille Date: Mon, 16 Nov 2026 15:32:13 +0000 (+0100) Subject: BUG/MINOR: quic-be: do not register the connection before the quic_conn is initialized X-Git-Tag: v3.5-dev13~52 X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/%7B@url%7D?a=commitdiff_plain;h=17a43429681de5b0d1543c16c262029168efe53d;p=haproxy.git BUG/MINOR: quic-be: do not register the connection before the quic_conn is initialized qc_new_conn() stores the connection passed as argument in qc->conn before the first failure points, while quic_conn_release(), called from its own error path, BUG_ONs on a non-null ->conn. As the upper connection is still allocated while qc_new_conn() runs, any failure after this point aborts the whole process instead of returning an error. Only backend connections are affected, as the frontend caller passes a NULL connection. qc->conn cannot simply be removed from qc_new_conn(): it is dereferenced by ssl_sock_srv_try_reuse_sess(), called from qc_alloc_ssl_sock_ctx() on the backend side, to look up a reusable TLS session. The latter leaves ctx->conn to NULL, unlike its non-QUIC counterpart ssl_sock_init(), which forces ssl_sock_srv_try_reuse_sess() to fall back to qc->conn. Pass the connection to qc_alloc_ssl_sock_ctx() so that ctx->conn is always valid, and use it unconditionally in ssl_sock_srv_try_reuse_sess(). Then let the caller register the connection, next to conn->handle.qc, once qc_new_conn() has succeeded. Commit ca5511f02 fixed this by setting ->conn only once the quic_conn was fully initialized. Commit a83ed86b7, which reinstated the conn argument, moved the assignment back into the initialization block and reintroduced the bug. Must be backported to 3.4. --- diff --git a/include/haproxy/quic_ssl.h b/include/haproxy/quic_ssl.h index f22b7c03e..d42e949e6 100644 --- a/include/haproxy/quic_ssl.h +++ b/include/haproxy/quic_ssl.h @@ -35,7 +35,8 @@ int ssl_quic_initial_ctx(struct bind_conf *bind_conf); SSL_CTX *ssl_quic_srv_new_ssl_ctx(void); -int qc_alloc_ssl_sock_ctx(struct quic_conn *qc, void *target); +int qc_alloc_ssl_sock_ctx(struct quic_conn *qc, void *target, + struct connection *conn); int qc_ssl_provide_all_quic_data(struct quic_conn *qc, struct ssl_sock_ctx *ctx); int qc_ssl_do_hanshake(struct quic_conn *qc, struct ssl_sock_ctx *ctx); diff --git a/src/quic_conn.c b/src/quic_conn.c index 8b5d75ee9..71f44a2eb 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -1177,7 +1177,11 @@ struct quic_conn *qc_new_conn(void *target, qc->idle_timer_task = NULL; qc->xprt_ctx = NULL; - qc->conn = conn; + /* Set by the caller once the quic_conn is fully initialized: + * quic_conn_release(), called from the error paths below, BUG_ONs on a + * non-null ->conn while the upper connection is still allocated. + */ + qc->conn = NULL; qc->qcc = NULL; qc->strm_reject = NULL; qc->path = NULL; @@ -1376,7 +1380,7 @@ struct quic_conn *qc_new_conn(void *target, qc->wait_event.events = 0; qc->subs = NULL; - if (qc_alloc_ssl_sock_ctx(qc, target) || + if (qc_alloc_ssl_sock_ctx(qc, target, conn) || !quic_conn_init_timer(qc) || !quic_conn_init_idle_timer_task(qc, prx)) goto err; diff --git a/src/quic_ssl.c b/src/quic_ssl.c index 7539234c3..d22efef43 100644 --- a/src/quic_ssl.c +++ b/src/quic_ssl.c @@ -1318,7 +1318,8 @@ static int qc_set_quic_early_data_enabled(struct quic_conn *qc, SSL *ssl) * * Returns 0 on success else non-zero. */ -int qc_alloc_ssl_sock_ctx(struct quic_conn *qc, void *target) +int qc_alloc_ssl_sock_ctx(struct quic_conn *qc, void *target, + struct connection *conn) { struct ssl_sock_ctx *ctx = NULL; struct bind_conf *bc; @@ -1333,7 +1334,15 @@ int qc_alloc_ssl_sock_ctx(struct quic_conn *qc, void *target) goto err; } - ctx->conn = NULL; + /* ssl_sock_srv_try_reuse_sess(), called from this function on the + * backend side, dereferences ->conn to look up a reusable TLS session. + * + * It is NULL for frontend connections, which never reuse a session. + * Note that this field is not read anywhere else for QUIC: this + * function neither enables KTLS nor installs ssl_sock_io_cb(), so the + * generic ssl_sock handlers, which rely on it, are never used here. + */ + ctx->conn = conn; ctx->bio = NULL; ctx->xprt = NULL; ctx->xprt_ctx = NULL; diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 7c8b954b6..1c77c5822 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -6260,12 +6260,7 @@ int increment_sslconn() */ void ssl_sock_srv_try_reuse_sess(struct ssl_sock_ctx *ctx, struct server *srv) { -#ifdef USE_QUIC - struct quic_conn *qc = ctx->qc; - struct connection *conn = qc ? qc->conn : ctx->conn; -#else struct connection *conn = ctx->conn; -#endif /* Do nothing for check connections */ if (conn->flags & CO_FL_SSL_NO_CACHED_INFO) diff --git a/src/xprt_quic.c b/src/xprt_quic.c index 6a43c707f..632eb5286 100644 --- a/src/xprt_quic.c +++ b/src/xprt_quic.c @@ -176,6 +176,7 @@ static int qc_conn_init(struct connection *conn, void **xprt_ctx) conn->flags |= CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN | CO_FL_FDLESS; conn->handle.qc = qc; + qc->conn = conn; } ret = 0;