CVE-2026-80229: OpenSSL provider use-after-free
A use-after-free occurs in libcurl when an easy handle with CURLOPT_SSLENGINE set is cleaned up while its TLS connection remains pooled in a multi handle, because the OpenSSL library context is freed but still referenced by the pooled connection's SSL_CTX. A subsequent easy handle reusing that pooled connection dereferences the freed memory, causing a crash or potentially undefined behaviour.
Originally disclosed on HackerOne
- Triaged in 2 hours
- Fixed in 8 days
- Disclosed after 8 days
Summary
When CURLOPT_SSLENGINE is set (e.g. "default" on OpenSSL 3.x), ossl_set_provider() (line 1791) allocates a per-handle OSSL_LIB_CTX and stores it in data->state.libctx. During TLS connection setup, SSL_CTX_new_ex() (line 3750) receives this library context and embeds a pointer to it inside the newly created SSL_CTX. The SSL_CTX is owned by the connection filter attached to the pooled connection — its lifetime is independent of the easy handle.
When curl_easy_cleanup() is called on the originating handle, ossl_close_all() → ossl_provider_cleanup() (line 2001) calls OSSL_LIB_CTX_free(data->state.libctx) (line 1752), destroying the library context. The pooled connection's SSL_CTX now holds a dangling pointer. When a second easy handle reuses this pooled connection via the multi handle's connection cache, any SSL operation — session resumption, re-handshake, cipher lookup — dereferences the freed OSSL_LIB_CTX, producing a heap-use-after-free.
The bug is a lifetime mismatch: data->state.libctx is scoped to the easy handle, but SSL_CTX_new_ex() borrows it without taking ownership, and the resulting SSL_CTX outlives the easy handle via connection pooling.
Preconditions
- libcurl built with OpenSSL 3.x (
OPENSSL_HAS_PROVIDERSdefined) CURLOPT_SSLENGINEset on at least one easy handle (triggersossl_set_provider)- Easy handle cleaned up while its TLS connection remains pooled in a multi handle
- A subsequent easy handle reuses that pooled connection
Root cause trace
curl_easy_setopt(CURLOPT_SSLENGINE, "default")→Curl_ssl_set_engine→ossl_set_engine→ossl_set_provider(line 1768).ossl_set_providercallsOSSL_LIB_CTX_new()(line 1791), stores result indata->state.libctx.- On TLS connect,
ossl_connect_common→ossl_connect_step1reachesSSL_CTX_new_ex(data->state.libctx, data->state.propq, req_method)(line 3750). TheSSL_CTXstores thelibctxpointer internally. - Transfer completes.
curl_multi_remove_handledetaches the easy handle; the TLS connection moves to the multi handle's connection pool. curl_easy_cleanup(data)→ossl_close_all(data)→ossl_provider_cleanup(data)→OSSL_LIB_CTX_free(data->state.libctx)(line 1752). Thelibctxis freed.- A new easy handle B with matching connection parameters is added to the same multi handle.
Curl_ssl_conn_config_matchfinds the pooled connection (engine/provider is not compared inmatch_ssl_primary_config). - B reuses the pooled connection. Any SSL operation on the
SSL_CTXdereferences the freedlibctx→ heap-use-after-free.
Remediation
The OSSL_LIB_CTX must outlive every SSL_CTX that references it. Options:
- Reference-count the library context and share ownership between the easy handle and the connection filter's
SSL_CTX. Release only when both are done. - Transfer ownership to the SSL_CTX wrapper (
struct ossl_ctx): movelibctxout ofdata->stateintooctxwhenSSL_CTX_new_exis called.ossl_close(connection teardown) frees it instead ofossl_close_all(handle teardown). - Duplicate the library context per connection, so each
SSL_CTXowns its own copy. More expensive but simplest lifetime model.
Impact
Under ASan, the dereference triggers an immediate crash. Without ASan, behavior is undefined: the freed heap region may be reallocated to attacker-controlled data, potentially allowing corruption of OpenSSL internal state. In a multi-tenant application using CURLOPT_SSLENGINE with a shared multi handle, this creates a use-after-free on every pooled TLS connection whose originating easy handle is cleaned up before the connection is evicted.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The OSSL_LIB_CTX is scoped to the easy handle but is borrowed by the SSL_CTX without ownership transfer, so the SSL_CTX outlives the easy handle via connection pooling and holds a dangling pointer.
Impact
Under ASan the dereference triggers an immediate crash; without ASan, behaviour is undefined and the freed heap region may be reallocated to attacker-controlled data, potentially allowing corruption of OpenSSL internal state, with a use-after-free occurring on every pooled TLS connection whose originating easy handle is cleaned up before eviction.
What the attacker needed
Libcurl built with OpenSSL 3.x; CURLOPT_SSLENGINE set on an easy handle; easy handle cleaned up while connection pooled; subsequent easy handle reuses pooled connection
The fix
The OSSL_LIB_CTX must outlive every SSL_CTX that references it, for example by reference-counting it, transferring ownership to the SSL_CTX wrapper, or duplicating it per connection.
How it was found
- Set CURLOPT_SSLENGINE to "default" on an easy handle, which triggers ossl_set_provider and allocates a per-handle OSSL_LIB_CTX.
- Perform a TLS connection; SSL_CTX_new_ex receives the library context and stores a pointer to it inside the SSL_CTX.
- After the transfer completes, remove the easy handle from the multi handle so the TLS connection moves to the connection pool.
- Call curl_easy_cleanup on the originating handle, which frees the OSSL_LIB_CTX via ossl_provider_cleanup.
- Add a new easy handle with matching connection parameters to the same multi handle; it reuses the pooled connection.
- Any SSL operation on the reused connection dereferences the freed OSSL_LIB_CTX, causing a heap-use-after-free.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program uses libcurl to make secure connections, it can reuse existing connections to save time. This report shows that if one part of the program finishes and cleans up while a connection is still kept for reuse, the memory holding important security settings is freed too early. Later, when another part tries to use that reused connection, it reads freed memory, which can crash the program or cause unpredictable behaviour.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.