]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: quic: do not use the FD of another thread group's listener
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 3 Dec 2026 10:03:37 +0000 (11:03 +0100)
committerOlivier Houchard <cognet@ci0.org>
Thu, 3 Dec 2026 10:04:53 +0000 (11:04 +0100)
With per-thread-group FD tables, quic_dgram_parse() looks for a listener
of the same bind line in the current thread group, since commit
62d6ed440 ("MEDIUM: quic: Do not use another thread group's listener
FD"). But the CID tree is shared by all bind lines, so a datagram for a
connection may be received on a bind line which has no listener in the
group of the connection's thread, and the listener of the other group
was then kept. If no connection ended up being used, its FD, which
means nothing in the current group, was used to send a Version
Negotiation, Retry or Stateless Reset packet, and a new connection
could be attached to that listener.

Drop the packet in these cases only, ie when the version is not
supported or when no connection is found. Packets for an existing
connection do not need the listener and are still processed. This can
be tested with "tune.fd.tables per-thread-group" and two QUIC bind lines
on different thread groups, by sending to the second one the datagrams
of a connection established on the first one.

This was reported by deanliang06 <dextersquad4@gmail.com>, who proposed
a first fix dropping all such datagrams:

  https://www.mail-archive.com/haproxy@formilux.org/msg47862.html

This should be backported to 3.5.

src/quic_rx.c

index 42ab47b74990e9319a228b8cc6277f6f0090c589..ba4734e87d38aa2587931a5b624ce761c4dd814c 100644 (file)
@@ -1850,6 +1850,13 @@ static inline int quic_token_validate(struct quic_rx_packet *pkt,
        goto leave;
 }
 
+/* Returns non-zero if <l>'s FD cannot be used from the current thread group. */
+static inline int quic_lstnr_is_foreign(const struct listener *l)
+{
+       return (global.tune.options & GTUNE_NO_TG_FD_SHARING) &&
+              l->rx.bind_tgroup != tgid;
+}
+
 /* Listener only function.
  *
  * Find the associated connection to the packet <pkt> or create a new one if
@@ -1888,6 +1895,12 @@ static struct quic_conn *quic_rx_pkt_retrieve_conn(struct quic_rx_packet *pkt,
        if (!qc && *new_tid != -1 && tid != *new_tid)
                goto out;
 
+       if (!qc && quic_lstnr_is_foreign(l)) {
+               TRACE_PROTO("no connection and listener from another thread group, packet dropped",
+                           QUIC_EV_CONN_LPKT, NULL, NULL, NULL, pkt->version);
+               goto err;
+       }
+
        if (pkt->type == QUIC_PACKET_TYPE_INITIAL) {
                BUG_ON(!pkt->version); /* This must not happen. */
 
@@ -2127,6 +2140,11 @@ static int quic_rx_pkt_parse(struct quic_conn *qc, struct quic_rx_packet *pkt,
                 * sent only by servers.
                 */
                if (l && !pkt->version) {
+                       if (quic_lstnr_is_foreign(l)) {
+                               TRACE_PROTO("Packet dropped", QUIC_EV_CONN_LPKT);
+                               goto drop;
+                       }
+
                         /* unsupported version, send Negotiation packet */
                        if (send_version_negotiation(l, (struct sockaddr_storage *)&dgram->daddr,
                                                     (struct sockaddr_storage *)&dgram->saddr, pkt)) {