]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: quic-be: do not register the connection before the quic_conn is initialized
authorFrederic Lecaille <flecaille@haproxy.com>
Mon, 16 Nov 2026 15:32:13 +0000 (16:32 +0100)
committerFrederic Lecaille <flecaille@haproxy.com>
Tue, 17 Nov 2026 08:35:15 +0000 (09:35 +0100)
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.

include/haproxy/quic_ssl.h
src/quic_conn.c
src/quic_ssl.c
src/ssl_sock.c
src/xprt_quic.c

index f22b7c03eea4ea8092dd39e7e1763f283f79c764..d42e949e6ee71a9488f6e7e8679422b80bc80968 100644 (file)
@@ -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);
 
index 8b5d75ee9b8e27687095507de6a9d2b0153066f4..71f44a2ebfc318301dc107e156ca1d9d6bd15832 100644 (file)
@@ -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;
index 7539234c3a5a76b7f384a473748414bf8c80c937..d22efef4370d1536dda1f813e255e725520e17fc 100644 (file)
@@ -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;
index 7c8b954b68f70f69b8ef4c10b1d08bef71aea79a..1c77c5822d296bd204fb1c8347abe258d49d9e1f 100644 (file)
@@ -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)
index 6a43c707f22feeb0372016bcaa70a10dcf70ca30..632eb5286dec114b17e766f011516cca36a74912 100644 (file)
@@ -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;