From: Frederic Lecaille Date: Wed, 18 Nov 2026 16:39:29 +0000 (+0100) Subject: REGTESTS: quic: backend must drop packets with an unsupported version X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/%7B@url%7D?a=commitdiff_plain;h=e55a181e96a9446390bc4c6bf5a5641b326081cc;p=haproxy.git REGTESTS: quic: backend must drop packets with an unsupported version On backend connections, quic_rx_pkt_parse() accepts long header packets carrying an unsupported version, since the version checks only apply to listeners. Such packets keep QUIC_PACKET_TYPE_UNKNOWN, which maps to no encryption level, and reach BUG_ON(!qel || !pktns) in qc_enc_level_alloc() from qc_try_rm_hp(). A server which does not support the negotiated version answers with a Version Negotiation packet (RFC 9000 6.1), so no malicious peer is needed. The test starts a socket that replies to the Initial with a long header packet using an unsupported version, and checks that the request fails with a 503 instead of killing the process. It needs no helper beyond python3, so it carries no #REGTEST_EXTRA directive. Covers f12c7c7d9. --- diff --git a/reg-tests/quic/unknown_version_backend.py b/reg-tests/quic/unknown_version_backend.py new file mode 100644 index 000000000..8b5970f91 --- /dev/null +++ b/reg-tests/quic/unknown_version_backend.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later + +"""Fake QUIC backend answering haproxy's Initial with a long header packet +using an unsupported version. A single datagram is enough to reach +quic_rx_pkt_parse() on the backend side of the connection: it must be +dropped instead of being parsed with a QUIC_PACKET_TYPE_UNKNOWN type, which +resolves to a NULL encryption level. +""" +import argparse +import socket +import sys + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--port", type=int, required=True) + ap.add_argument("--timeout", type=float, default=10.0) + args = ap.parse_args() + + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + s.settimeout(args.timeout) + s.bind(("127.0.0.1", args.port)) + print("READY", flush=True) + + try: + data, peer = s.recvfrom(65535) + except socket.timeout: + print("no Initial packet received", flush=True) + return 1 + + if not data[0] & 0x80: + print("not a long header packet", flush=True) + return 1 + + dcid_len = data[5] + scid_off = 6 + dcid_len + scid_len = data[scid_off] + hap_scid = data[scid_off + 1:scid_off + 1 + scid_len] + + payload = b"\x00" * 40 + pkt = (bytes([0xC0]) + (0x1A2A3A4A).to_bytes(4, "big") + + bytes([len(hap_scid)]) + hap_scid + b"\x00" + + bytes([0x40 | (len(payload) >> 8), len(payload) & 0xFF]) + payload) + s.sendto(pkt, peer) + s.close() + print("sent %d bytes long header packet with unsupported version" % len(pkt), flush=True) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/reg-tests/quic/unknown_version_backend.vtc b/reg-tests/quic/unknown_version_backend.vtc new file mode 100644 index 000000000..b43497ed7 --- /dev/null +++ b/reg-tests/quic/unknown_version_backend.vtc @@ -0,0 +1,49 @@ +varnishtest "QUIC backend must drop packets with an unsupported version" +# SPDX-License-Identifier: GPL-2.0-or-later + +#REGTEST_TYPE=bug + +feature ignore_unknown_macro +feature cmd "python3 --version" + +# QUIC backend connections are not supported with USE_QUIC_OPENSSL_COMPAT. +feature cmd "$HAPROXY_PROGRAM -cc 'feature(QUIC) && !feature(QUIC_OPENSSL_COMPAT) && !feature(OPENSSL_WOLFSSL)'" + +# Reserve the UDP port used by the fake QUIC backend. +server s_backend {} -start +server s_backend -break + +process p1 "python3 ${testdir}/unknown_version_backend.py --port ${s_backend_port}" -start +process p1 -expect-text 0 0 "READY" + +haproxy h1 -conf { + global + expose-experimental-directives + + defaults + mode http + timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" + timeout client "${HAPROXY_TEST_TIMEOUT-5s}" + timeout server "${HAPROXY_TEST_TIMEOUT-5s}" + + frontend fe + bind "fd@${fe}" + default_backend be + + backend be + # Fail on the first attempt: do not depend on ICMP port unreachable + # to make connection retries fail fast once the fake backend exited. + retries 0 + server qsrv quic4@127.0.0.1:${s_backend_port} ssl verify none alpn h3 +} -start + +# The fake backend answers the Initial with a long header packet using an +# unsupported version: the request must fail, but haproxy used to abort on +# BUG_ON(!qel || !pktns) in qc_enc_level_alloc() while parsing it. +client c1 -connect ${h1_fe_sock} { + txreq + rxresp + expect resp.status == 503 +} -run + +process p1 -wait