]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: quic-be: install the peer CID only from an accepted Initial
authordeanliang06 <dextersquad4@gmail.com>
Mon, 30 Nov 2026 14:31:40 +0000 (09:31 -0500)
committerFrederic Lecaille <flecaille@haproxy.com>
Mon, 30 Nov 2026 14:52:14 +0000 (15:52 +0100)
On backend QUIC connections, parsing an Initial header sets the peer
CID before the packet is validated. If that packet is discarded, a
later valid Initial cannot replace the CID. If the CIDs differ, the
backend handshake can fail.

Install the peer CID only after the Initial has been decrypted and its
frames have been parsed. Preserve the existing Retry handling.

This should be backported up to 3.3, where the bug was introduced by
2d076178c ("MINOR: quic-be: Store asap the DCID").

include/haproxy/quic_conn-t.h
src/quic_rx.c

index 3b84b2db1e954e6e4527773482d23397bfcd1543..8570b42b178c564fc26172c225cc1eb1cc45c3ea 100644 (file)
@@ -464,7 +464,7 @@ struct quic_conn_closed {
 #define QUIC_FL_CONN_HPKTNS_DCD                  (1U << 16) /* Handshake packet number space discarded  */
 #define QUIC_FL_CONN_PEER_VALIDATED_ADDR         (1U << 17) /* Peer address is considered as validated for this connection. */
 #define QUIC_FL_CONN_NO_TOKEN_RCVD               (1U << 18) /* Client dit not send any token */
-#define QUIC_FL_CONN_SCID_RECEIVED               (1U << 19) /* (client only: first Initial received. */
+#define QUIC_FL_CONN_SCID_RECEIVED               (1U << 19) /* (client only: first Initial accepted. */
 #define QUIC_FL_CONN_XPRT_CLOSED                 (1U << 20) /* close callback of xprt layer already called */
 /* gap here */
 #define QUIC_FL_CONN_TO_KILL                     (1U << 24) /* Unusable connection, to be killed */
index 83c3fec0f629364b13d85ab149cc23d10b7cc113..1bdb98fb78c715a2b428897415ce22290957c6a8 100644 (file)
@@ -1468,6 +1468,14 @@ int qc_treat_rx_pkts(struct quic_conn *qc)
                                else {
                                        struct quic_arng ar = { .first = pkt->pn, .last = pkt->pn };
 
+                                       if (pkt->type == QUIC_PACKET_TYPE_INITIAL && qc_is_back(qc) &&
+                                           !(qc->flags & QUIC_FL_CONN_SCID_RECEIVED)) {
+                                               /* Adopt the peer CID only after accepting its Initial. */
+                                               memcpy(qc->dcid.data, pkt->scid.data, pkt->scid.len);
+                                               qc->dcid.len = pkt->scid.len;
+                                               qc->flags |= QUIC_FL_CONN_SCID_RECEIVED;
+                                       }
+
                                        /* RFC 9000 8.1. Address Validation during Connection Establishment
                                         *
                                         * Connection establishment implicitly provides address validation for
@@ -2271,12 +2279,6 @@ static int quic_rx_pkt_parse(struct quic_conn *qc, struct quic_rx_packet *pkt,
                                 * ack-eliciting Initial packets to at least the smallest allowed maximum
                                 * datagram size of 1200 bytes.
                                 */
-                               if (!(qc->flags & QUIC_FL_CONN_SCID_RECEIVED)) {
-                                       qc->flags |= QUIC_FL_CONN_SCID_RECEIVED;
-                                       memcpy(qc->dcid.data, pkt->scid.data, pkt->scid.len);
-                                       qc->dcid.len = pkt->scid.len;
-                               }
-
                                if (qc_is_back(qc)) {
                                        if (qc->flags & QUIC_FL_CONN_CLOSING) {
                                                TRACE_PROTO("Packet dropped",