Skip to content
Memory corruption Disclosed report Advanced CVE-2026-80229

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.

giant_anteater Follow

Originally disclosed on HackerOne

Informational View original
  • 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_PROVIDERS defined)
  • CURLOPT_SSLENGINE set on at least one easy handle (triggers ossl_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

  1. curl_easy_setopt(CURLOPT_SSLENGINE, "default") → Curl_ssl_set_engine → ossl_set_engine → ossl_set_provider (line 1768).
  2. ossl_set_provider calls OSSL_LIB_CTX_new() (line 1791), stores result in data->state.libctx.
  3. On TLS connect, ossl_connect_common → ossl_connect_step1 reaches SSL_CTX_new_ex(data->state.libctx, data->state.propq, req_method) (line 3750). The SSL_CTX stores the libctx pointer internally.
  4. Transfer completes. curl_multi_remove_handle detaches the easy handle; the TLS connection moves to the multi handle's connection pool.
  5. curl_easy_cleanup(data) → ossl_close_all(data) → ossl_provider_cleanup(data) → OSSL_LIB_CTX_free(data->state.libctx) (line 1752). The libctx is freed.
  6. A new easy handle B with matching connection parameters is added to the same multi handle. Curl_ssl_conn_config_match finds the pooled connection (engine/provider is not compared in match_ssl_primary_config).
  7. B reuses the pooled connection. Any SSL operation on the SSL_CTX dereferences the freed libctx → heap-use-after-free.

Remediation

The OSSL_LIB_CTX must outlive every SSL_CTX that references it. Options:

  1. 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.
  2. Transfer ownership to the SSL_CTX wrapper (struct ossl_ctx): move libctx out of data->state into octx when SSL_CTX_new_ex is called. ossl_close (connection teardown) frees it instead of ossl_close_all (handle teardown).
  3. Duplicate the library context per connection, so each SSL_CTX owns 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.

The original report as published on HackerOne, by giant_anteater. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

  1. Set CURLOPT_SSLENGINE to "default" on an easy handle, which triggers ossl_set_provider and allocates a per-handle OSSL_LIB_CTX.
  2. Perform a TLS connection; SSL_CTX_new_ex receives the library context and stores a pointer to it inside the SSL_CTX.
  3. After the transfer completes, remove the easy handle from the multi handle so the TLS connection moves to the connection pool.
  4. Call curl_easy_cleanup on the originating handle, which frees the OSSL_LIB_CTX via ossl_provider_cleanup.
  5. Add a new easy handle with matching connection parameters to the same multi handle; it reuses the pooled connection.
  6. 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.

More by giant_anteater

View all

93 more disclosed reports, best first.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.