From: Frederic Lecaille Date: Mon, 16 Nov 2026 16:37:50 +0000 (+0100) Subject: BUG/MINOR: quic: initialize the members read by quic_conn_release() first X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/gitweb.js?a=commitdiff_plain;h=2b75c35734215bc8493fea3d1d61542503f2d167;p=haproxy.git BUG/MINOR: quic: initialize the members read by quic_conn_release() first qc_new_conn() allocates the CID tree before initializing ->flags, ->state and ->prx_counters, while quic_conn_release(), called from its error path, reads all three of them. On allocation failure, the release thus reads uninitialized memory, and quic_conn_prx_cntrs_update() dereferences an invalid ->prx_counters instead of returning early. This affects both frontend and backend connections. The backend ->prx_counters assignment has the same problem, as it is placed after the RAND_bytes() call, which is another failure point. This was introduced by commit b8cb8e1a6 ("BUG/MINOR: quic: fix counters used on BE side"), which moved the assignment into the per-side branches, after the first failure point. Move the CID tree allocation after these initializations, and move the backend ->prx_counters assignment before RAND_bytes(). Must be backported up to 3.3. --- diff --git a/src/quic_conn.c b/src/quic_conn.c index 71f44a2eb..eb0ee3bac 100644 --- a/src/quic_conn.c +++ b/src/quic_conn.c @@ -1206,12 +1206,6 @@ struct quic_conn *qc_new_conn(void *target, qc->ipktns = qc->hpktns = qc->apktns = NULL; LIST_INIT(&qc->pktns_list); - qc->cids = pool_alloc(pool_head_quic_cids); - if (!qc->cids) { - TRACE_ERROR("Could not allocate a new CID tree", QUIC_EV_CONN_INIT, qc); - goto err; - } - *qc->cids = EB_ROOT; qc->next_cid_seq_num = 0; qc->max_sent_cid_seq_num = 0; qc->scid = conn_id->cid; @@ -1248,6 +1242,8 @@ struct quic_conn *qc_new_conn(void *target, if (HA_ATOMIC_LOAD(&srv->flags) & SRV_F_UDP_GSO_NOTSUPP) qc->flags |= QUIC_FL_CONN_UDP_GSO_EIO; + qc->prx_counters = EXTRA_COUNTERS_GET(prx->extra_counters_be, &quic_stats_module); + qc->state = QUIC_HS_ST_CLIENT_INITIAL; /* Randomly generate the first DCID used for the first INITIAL @@ -1258,8 +1254,6 @@ struct quic_conn *qc_new_conn(void *target, goto err; qc->dcid.len = sizeof(qc->dcid.data); qc->odcid = qc->dcid; - - qc->prx_counters = EXTRA_COUNTERS_GET(prx->extra_counters_be, &quic_stats_module); } qc->err = quic_err_transport(QC_ERR_NO_ERROR); @@ -1278,6 +1272,18 @@ struct quic_conn *qc_new_conn(void *target, } } + /* Allocated only now: quic_conn_release() is called from the error + * paths below and reads ->flags, ->state and ->prx_counters, which + * are initialized above. + */ + qc->cids = pool_alloc(pool_head_quic_cids); + if (!qc->cids) { + TRACE_ERROR("Could not allocate a new CID tree", QUIC_EV_CONN_INIT, qc); + goto err; + } + + *qc->cids = EB_ROOT; + /* Now proceeds to allocation of qc members. */ qc->rx.buf.area = pool_alloc(pool_head_quic_conn_rxbuf); if (!qc->rx.buf.area) {