From: Frederic Lecaille Date: Wed, 18 Nov 2026 16:47:39 +0000 (+0100) Subject: REGTESTS: quic: undecryptable 0-RTT packets must not exhaust the Rx buffer X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/HAProxyCommunityEdition_60px.png?a=commitdiff_plain;ds=inline;p=haproxy.git REGTESTS: quic: undecryptable 0-RTT packets must not exhaust the Rx buffer On a listener with "allow-0rtt", a 0-RTT packet whose header protection cannot be removed is queued in the 0-RTT encryption level pqpkts list, with a reference on the connection Rx buffer. That buffer is reclaimed in order and stops at the first referenced packet, so a queued 0-RTT packet pins all the data behind it. When no 0-RTT RX secret exists, because the early data were rejected by the TLS stack or because the TLS library does not support 0-RTT, those packets can never be decrypted and are never released: past about 64 kB, every packet of the connection is dropped until the idle timeout. The test completes a handshake, keeps the connection healthy with an HTTP/3 request, then injects 120 long header 0-RTT packets whose payload is encrypted with keys haproxy does not know, which reproduces the state reached when 0-RTT keys are absent. Dropped packets are counted as dropped_pkt_bufoverrun, shown as dropbuff= by "show quic full", so the vtc asserts through the CLI that this field does not appear: the Rx buffer was not exhausted and the connection was not stalled. It needs the Python client in reg-tests/quic/qclient, so it carries '#REGTEST_EXTRA=qclient' and only runs when requested. Covers 2335f9196. --- diff --git a/reg-tests/quic/0rtt_undecryptable.py b/reg-tests/quic/0rtt_undecryptable.py new file mode 100755 index 000000000..741de70bc --- /dev/null +++ b/reg-tests/quic/0rtt_undecryptable.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-or-later + +"""Feed haproxy 0-RTT packets it can never decrypt. + +A 0-RTT packet whose header protection cannot be removed, because no 0-RTT +RX secret exists (early data rejected by the TLS stack, or a TLS library +without 0-RTT support), is queued in eel->rx.pqpkts with a reference on +qc->rx.buf. The Rx buffer is reclaimed in order, stopping at the first +referenced packet: past ~64 kB, every packet is dropped until the idle +timeout, accounted as quic_dropped_pkt_bufoverrun and shown as dropbuff= in +"show quic". + +The packets below are built synthetically as long-header packets of the +0-RTT type, with a payload encrypted with keys haproxy does not know, which +is exactly the state reached when 0-RTT keys are absent. +""" +import argparse +import hashlib +import os +import sys + +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), + "qclient")) + +from qclient import QClient +from qcrypto import Keys, protect_long + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--addr", required=True) + ap.add_argument("--port", type=int, required=True) + ap.add_argument("--count", type=int, default=120) + args = ap.parse_args() + + c = QClient((args.addr, args.port), timeout=1.0) + print("READY", flush=True) + + if not c.handshake(wait=2.0): + print("RESULT handshake failed events=%r closed=%r" + % (c.events, c.closed), flush=True) + return + + # Keep the connection healthy, so that what is measured below is not the + # consequence of a failed handshake. + c.h3_setup() + _, fin = c.request(0) + if not fin: + print("RESULT request failed", flush=True) + return + + # 0-RTT long header packets encrypted with unknown keys: haproxy cannot + # remove their header protection and queues them. + fake = Keys(hashlib.sha256(b"fake-0rtt").digest()) + payload = b"\x01" * 1100 + for i in range(args.count): + c.sock.sendto(protect_long(fake, 1, c.server_cid, c.scid, i, payload), + c.addr) + + print("SENT %d" % args.count, flush=True) + + +if __name__ == "__main__": + main() diff --git a/reg-tests/quic/0rtt_undecryptable.vtc b/reg-tests/quic/0rtt_undecryptable.vtc new file mode 100644 index 000000000..8f176e345 --- /dev/null +++ b/reg-tests/quic/0rtt_undecryptable.vtc @@ -0,0 +1,54 @@ +varnishtest "QUIC: undecryptable 0-RTT packets must not exhaust the Rx buffer" + +#REGTEST_TYPE=bug +#REGTEST_EXTRA=qclient + +feature ignore_unknown_macro +feature cmd "python3 --version" +feature cmd "python3 -c 'import cryptography'" + +# QUIC is not supported with USE_QUIC_OPENSSL_COMPAT nor with wolfSSL. +feature cmd "$HAPROXY_PROGRAM -cc 'feature(QUIC) && !feature(QUIC_OPENSSL_COMPAT) && !feature(OPENSSL_WOLFSSL)'" + +# A 0-RTT packet whose header protection cannot be removed is queued in +# eel->rx.pqpkts with a reference on qc->rx.buf, and the Rx buffer is +# reclaimed in order, stopping at the first referenced packet. When no 0-RTT +# RX secret exists, for instance because the early data were rejected by the +# TLS stack or because the TLS library does not support 0-RTT, these packets +# can never be decrypted and must not be kept: otherwise, past ~64 kB, every +# subsequent packet of the connection is dropped until the idle timeout. + +haproxy h1 -conf { + global + .if feature(THREAD) + thread-groups 1 + nbthread 1 + .endif + + defaults + mode http + timeout connect "${HAPROXY_TEST_TIMEOUT-5s}" + timeout client "${HAPROXY_TEST_TIMEOUT-5s}" + timeout server "${HAPROXY_TEST_TIMEOUT-5s}" + + frontend fe + bind "quic+fd@${fe}" ssl crt ${testdir}/certs/common.pem alpn h3 allow-0rtt + http-request return status 200 content-type text/plain string "ok" +} -start + +process p1 "python3 ${testdir}/0rtt_undecryptable.py --addr ${h1_fe_addr} --port ${h1_fe_port}" -start +process p1 -expect-text 0 0 "READY" +process p1 -expect-text 0 0 "SENT" + +# Let haproxy account the packets it had to drop. +delay 1 + +# Only the "full" format dumps dropbuff=, and only when the counter is not +# null (see dump_quic_full()), so an absence of the field means the Rx +# buffer was not exhausted. +haproxy h1 -cli { + send "show quic full" + expect !~ "dropbuff=" +} + +process p1 -wait