[0] Application
From github.com/varnish/hitch:
« A scalable TLS proxy by Varnish Software. »
hitch is written in C on top of libev. It terminates TLS in front of
cleartext backends such as Varnish Cache, and can describe each connection
to the backend with a PROXY protocol header (v1 text line, or v2 binary with
write-proxy-v2 = on).
With proxy-client-cert = on (off by default, src/configuration.c:202),
hitch appends a PROXYv2 TLV of type 0xE0 carrying the client’s X509
certificate, re-encoded as PEM, so that the backend can make its own
authorization decisions on it. Such deployments also configure
client-verify (optional or required) with a client-verify-ca bundle,
since hitch only requests a client certificate when verification is on. The
vulnerable path is therefore the one mTLS deployments use.
The code was introduced by commit 13dba68 (“Add proxy-client-cert setting”, 2020-10-02), first released in 1.7.0. It is unchanged through 1.8.0 and on master as of August 2026.
This flaw was verified on a locally built hitch 1.8.0 (release tarball) on Linux, glibc 2.41 and OpenSSL 3.5.7, under both an AddressSanitizer build and a production-like build.
[I] The vulnerability
A) Overview
When proxy-client-cert = on, a client presenting a certificate whose PEM
encoding is larger than the remaining space of the 32 KiB ring-buffer slot
in which the PROXYv2 header is built makes OpenSSL grow its buffer, which
ends in a free() of a pointer inside that slot. The pointer was never
returned by malloc, glibc rejects it and the worker process dies, with
every connection it was carrying.
B) Required data
- A hitch deployment with
write-proxy-v2 = on,proxy-client-cert = on, andclient-verifyset tooptionalorrequiredwith aclient-verify-ca. Withclient-verifyunset, hitch never requests a client certificate and the path is never reached. In both modes the certificate must be valid for the configured CA: the verify callback (client_vfy_cb,src/hitch.c:738) returns OpenSSL’s verdict unchanged, so an invalid certificate ends the handshake before the header is built. - A client certificate, signed by that CA, whose PEM encoding exceeds the remaining slot space, about 32 KiB. The size is not part of chain validity, but it is fixed by the CA at signing time: the trigger needs a CA that issues a certificate carrying a large extension (the proof certificate carries a single custom extension of a few dozen kilobytes). Private PKIs that copy extensions from the CSR into the certificate do exactly that.
The attacker is therefore an enrolled mTLS client with an unusual certificate. No secret beyond its own key is needed, and a legitimately enrolled client with such a certificate triggers the crash without any malice.
C) Explanation
write_proxy_v2 (src/hitch.c:2079) builds the PROXYv2 header directly
inside a ring-buffer slot: base = ringbuffer_write_ptr(...) at
src/hitch.c:2095, with maxlen the full slot size, the compiled default
DEF_RING_DATA_LEN of 32 KiB (src/ringbuffer.h:37), each slot a plain
malloc(rb->data_len) (src/ringbuffer.c:52). After the fixed header, the
address block and the ALPN and AUTHORITY TLVs, the running length len is a
few dozen bytes when the certificate TLV is appended:
/* src/hitch.c:2162-2163 */
if (CONFIG->PROXY_CLIENT_CERT)
len += proxy_tlv_cert(ps, base + len, maxlen - len);
proxy_tlv_cert (src/hitch.c:2039-2076) then does something unusual.
Instead of encoding the certificate to a private buffer and copying it in,
it builds an OpenSSL struct buf_mem_st by hand, pointing inside the ring
slot, and hands it to a memory BIO as if it were the BIO’s own heap buffer:
/* src/hitch.c:2044-2058 */
struct buf_mem_st bm[1];
memset(bm, 0, sizeof(*bm));
/* set aside the first three bytes for PROXY tlv type and size */
bm->data = dst + 3; /* 2052: interior pointer, dst = base + len */
bm->max = dstlen - 3; /* 2053: remaining slot space */
bio = BIO_new(BIO_s_mem());
AN(bio);
BIO_set_mem_buf(bio, bm, BIO_NOCLOSE); /* 2056 */
if (PEM_write_bio_X509_AUX(bio, crt) == 0) { ... } /* 2058 */
Two defects follow from these lines.
Defect 1, the grow abort (reachable). PEM_write_bio_X509_AUX writes
the PEM through the BIO. If the PEM needs more than bm->max bytes, the
memory BIO grows what it believes to be its own buffer: BIO_write,
mem_write, BUF_MEM_grow_clean, which ends in CRYPTO_clear_realloc: a
fresh malloc, a memcpy, then a free() of the old pointer. The old
pointer is dst + 3, an address inside the 32 KiB slot. glibc detects the
free of a pointer it never returned and aborts the process (free(): invalid pointer, or under ASan attempting free on address which was not malloc()-ed). Nothing on the path checks the PEM size against bm->max
first. The OpenSSL contract is that a BUF_MEM handed to a BIO belongs to
the BIO, which a stack buf_mem_st pointing into a ring slot does not
satisfy.
Defect 2, the dstlen < 3 underflow (latent). bm->max = dstlen - 3
(src/hitch.c:2053) is computed without checking dstlen >= 3. dstlen is
an ssize_t computed as maxlen - len (src/hitch.c:2163). If it ever
reaches the call with a value of 0, 1 or 2, dstlen - 3 wraps to a huge
size_t and the PEM is written in place with no bound at all: a heap
overflow of the slot by the certificate bytes. On stock 1.8.0 this is not
reachable: the slot is fixed at 32 KiB (the ring-data-len and ring-slots
keys exist in the lexer and in config_param_validate, but no grammar rule
and no command-line option reaches them), and the fixed header and TLVs
cannot consume 32 KiB. We did not execute this case, it follows from the
code. On the released code it only fires if the slot size ever becomes
configurable or smaller. On non-glibc
allocators, the realloc and free of an interior pointer in defect 1 is
undefined behavior with no particular bound.
D) Exploitation
The attack is one TLS handshake.
- The client connects to the TLS frontend and completes a handshake with the enrolled, oversized certificate (a ~55 KB PEM in our proof, an ordinary 2048-bit certificate carrying a single large custom extension).
- Chain verification succeeds, the certificate is valid for the CA. hitch
opens the backend connection and builds the PROXYv2 header, including
the
0xE0certificate TLV. PEM_write_bio_X509_AUXneeds more than the remaining slot space, the memory BIO grows, OpenSSL callsfree()on the interior pointer, and the worker aborts.
We ran the proof end to end against locally built hitch 1.8.0 instances
(loopback, test CA, proxy-client-cert = on, client-verify = optional).
The negative control first, a normal-size certificate from the same test
CA: handshake completes, no crash. Then the attack certificate: on the ASAN
build the worker died inside proxy_tlv_cert (src/hitch.c:2058, called
from write_proxy_v2 at src/hitch.c:2163), the sanitizer reporting the
bad free in CRYPTO_clear_realloc, called from BUF_MEM_grow_clean, called
from PEM_write_bio_X509_AUX, with the address identified as interior to
the 32768-byte slot allocation:
==1052728==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed
#0 in free
#1 in CRYPTO_clear_realloc (libcrypto.so.3)
#2 in BUF_MEM_grow_clean (libcrypto.so.3)
...
#7 in PEM_write_bio (libcrypto.so.3)
#11 in proxy_tlv_cert src/hitch.c:2058
#12 in write_proxy_v2 src/hitch.c:2163
SUMMARY: AddressSanitizer: bad-free in free
20261009T183635.512635 [1052727] {core} Child 1052728 exited with status 1.
The same handshake replayed against the respawned worker produced the same
report and a second Child ... exited with status 1 line, with the frontend
still accepting connections, which is what makes the attack repeatable. On
the production-like build, the same certificate killed the worker with a
segmentation fault inside the allocator:
20261009T183636.975223 [1052766] {core} Child 1052768 was terminated by signal 11.
How glibc dies depends on the heap layout at the moment of the free:
either its sanity checks reject the interior pointer and the worker aborts
(free(): invalid pointer, signal 6), or the bytes before the pointer are
read as a chunk header and the worker faults (signal 11). The SNI length
shifts the pointer and the worker’s prior activity shifts the heap, so the
same build gave both: signal 11 on a fresh worker with valid.example.com
and on a respawned worker with a 4-byte SNI, signal 6 on respawned workers
for the other lengths swept from 1 to 48, including seventeen a. Either
way the worker is gone and the master respawns it.
A companion harness drove the extracted proxy_tlv_cert (lines 2039-2076,
taken from the source without modification) through two cases: a fitting
PEM is written in place (exit 0), and an oversized PEM aborts in the grow
path with the freed address reported interior to the slot.
E) Consequences
Every oversized client certificate kills the worker and every connection it
carried. hitch runs a single worker by default (workers = 1,
src/configuration.c:212), so on a default deployment one handshake drops
every connection of the instance. The master respawns the worker at once
and keeps accepting, so this is an active, repeatable DoS, not a persistent
one: one handshake per second keeps long-lived TLS traffic from surviving,
and the backend sees its connections drop mid-stream.
We looked at whether the free of an interior pointer could be pushed further. The bytes preceding the pointer when the free fires are the PROXYv2 header and TLVs written so far: fixed header bytes and SNI and ALPN payload, which TLS constrains to be NUL-free. A fake-chunk attack needs those bytes to encode a plausible allocator header, and the NUL-free constraint pins at least five nonzero low bytes of the would-be size word. On glibc 2.41 this rules out the tcache range, fails the size sanity checks before consolidation, and fails the alignment congruences of the mmapped-chunk route (checked exhaustively over the 65k candidate values). The process dies before any allocator state is modified, so no heap disclosure follows either. The impact we could establish is a worker abort, hence the medium rating together with the non-default option and the certificate the CA has to issue.
[II] Mitigation
1. Encode the certificate into a private memory BIO, one that owns its
buffer and may grow, then check the size and copy into the slot
(src/hitch.c:2039-2076, suggested replacement):
static int
proxy_tlv_cert(struct proxystate *ps, char *dst, ssize_t dstlen)
{
X509 *crt;
BIO *bio;
BUF_MEM *bm;
crt = SSL_get_peer_certificate(ps->ssl);
if (crt == NULL)
return (0);
if (dstlen < 3) { /* kills defect 2 outright */
X509_free(crt);
return (0);
}
bio = BIO_new(BIO_s_mem());
AN(bio);
if (PEM_write_bio_X509_AUX(bio, crt) == 0) {
BIO_free(bio);
X509_free(crt);
log_ssl_error(ps,
"proxy-client-cert (PEM_write_bio_X509_AUX) failed");
return (0);
}
BIO_get_mem_ptr(bio, &bm);
/* also fixes the u16 TLV-length truncation for large certs */
if (bm->length > dstlen - 3 || bm->length > 0xffff) {
ERRPROXY(ps, "proxy-client-cert: certificate too large "
"for the PROXY header, TLV dropped\n");
BIO_free(bio);
X509_free(crt);
return (0); /* a per-connection condition, not a worker abort */
}
memcpy(dst + 3, bm->data, bm->length);
dst[0] = 0xe0;
dst[1] = (bm->length >> 8) & 0xff;
dst[2] = bm->length & 0xff;
BIO_free(bio);
X509_free(crt);
return (bm->length + 3);
}
Returning 0 skips the TLV, logs it, and turns the worker abort into a
per-connection condition. The return value must stay non-negative: the
caller adds it to len (src/hitch.c:2163), so an error code such as -1
would shorten the header and corrupt it. Note that the SSL TLV written next
still carries the PP2_CLIENT_CERT_SESS flag, so a backend that relies on
the 0xE0 TLV must treat its absence as “no certificate”. Closing the
connection instead avoids that ambiguity and is the behavior we would
recommend, but it needs a call to shutdown_proxy inside the function or a
change of the caller, not an error code.
2. Check dstlen before use, as in the code above, so that the
dstlen - 3 underflow of defect 2 cannot happen whatever the slot size.
3. Build the whole PROXYv2 header in a private bounded buffer and copy
it into the slot once. write_proxy_v2 builds it in the raw ring slot
(src/hitch.c:2095-2100, where the existing comment XXX: should it be rounded down to PP2_HEADER_MAX? already questions the sizing), and the
copy removes this class of in-place construction.
4. Regression test. Drive the extracted function under
AddressSanitizer with a fitting PEM (must pass) and an oversized PEM (must
be refused, not crash), and add dstlen = 2 (must be refused) once the
check is in. Ours fails on 1.8.0 and passes with the fix, we are happy to
share it.
Until a fix is released, operators running proxy-client-cert = on can
limit certificate size at the CA, and should read a repeated Child ... was terminated by signal 6 or signal 11 in the hitch log as this bug rather
than as a hardware problem.
[III] Timeline
2026/10/09: Advisory sent to Varnish Software
[IV] Author
John JEAN is a French security researcher, CTO at Wargan (https://www.wargan.com).
Follow me on X @johnjean
[V] PGP
My current PGP key is 0xDC3CB82BF0967AF0, you can get it on the Work with me page.