Skip to content

1.18.1

Choose a tag to compare

@freitasjca freitasjca released this 18 Sep 09:55
· 29 commits to main since this release

Fixed

FIX-ALPN-RACE-1 — heap corruption when a TTlsClientContext is shared across threads.

1.18.0's TNghttp2Client.Connect called TTlsClientContext.EnableHttp2Alpn on
every connect, so that offering h2 did not depend on the order in which a
caller assigns and configures TlsContext. That goal was right; the placement
was not.

EnableHttp2Alpn is SSL_CTX_set_alpn_protos — it writes the context, and
a TTlsClientContext is designed to be shared. OpenSSL frees the stored
protocol list and allocates a replacement, unlocked, so two threads connecting
on one shared context free the same block twice. Measured at 4 aborts in 30
runs
of the provider mTLS suite, reported by glibc as double free or corruption (fasttop) or malloc_consolidate(): invalid chunk size.

The abort surfaces wherever the allocator next notices the damage — typically a
sequential test well after the concurrent one that caused it — so the crash
location is not the fault location.

Fix: bind SSL_set_alpn_protos (per-connection, OpenSSL 1.0.2+) and apply
the list to the SSL in TTlsClientConnection.Create. Connect no longer
touches the context. Everything 1.18.0 wanted is preserved — applied on every
connect, independent of assignment order, always exactly h2 — and it now
mutates nothing shared.

After: 0 aborts in 30 runs, provider suite 37 passed / 0 failed / 1 skipped.

Upgrading

No API change. TTlsClientContext.EnableHttp2Alpn remains public and
idempotent; it is simply no longer required. If you call it yourself, call it
once, before any thread connects — a shared context must not be
reconfigured while other threads are connecting on it.

Anyone on 1.18.0 using a shared TTlsClientContext from more than one thread
should upgrade.