GnuTLS CURLINFO_TLS_SESSION / CURLINFO_TLS_SSL_PTR type confusion
When libcurl is built with GnuTLS, the TLS session info returned for CURLINFO_TLS_SESSION and CURLINFO_TLS_SSL_PTR wrongly reports the backend as OpenSSL while the pointer is actually a GnuTLS session. An application that trusts the backend field and passes the pointer to OpenSSL functions would treat one structure as another, which at minimum is likely to crash.
- Disclosed after 4 days
Summary:
curl_easy_getinfo for CURLINFO_TLS_SESSION and CURLINFO_TLS_SSL_PTR incorrectly return CURLSSLBACKEND_OPENSSL in struct curl_tlssessioninfo backend field for GnuTLS.
struct curl_tlssessioninfo {
curl_sslbackend backend;
void *internals;
};
The bug is at https://github.com/curl/curl/blob/2db8ae480fdcae7f005bf847fbbf837821c8184c/lib/vquic/vquic-tls.c#L211
#elif defined(USE_GNUTLS)
(void)give_ssl_ctx; /* gnutls always returns its session */
info->backend = CURLSSLBACKEND_OPENSSL;
info->internals = ctx->gtls.session;
return TRUE;
If the caller interprets the backend and makes dynamic decision on the value it will parse gnutls_session_t as SSL_CTX / SSL, leading to type confusion.
Example of an affected code can be found from: https://github.com/curl/curl/blob/7c23e88d17e0939b4e01c8d05f430e167e148f4b/docs/libcurl/opts/CURLINFO_TLS_SSL_PTR.md?plain=1#L144
What actually happens when the incorrect pointer is passed to OpenSSL functions is unknown and depends on the specific application code and what functions it will call. At minimum a crash is likely, but other impacts can't easily be ruled out, especially considering wide platform and version support in libcurl.
Mitigating factors: For this issue to become an issue, the application must be linked against both GnuTLS abd OpenSSL . This seems quite unlikely - but isn't entirely impossible. Either way, as such the impact of this vulnerability is limited. I cannot easily point out any affected applications.
Affected version
8.15.0
Steps To Reproduce:
- Have app built against both GnuTLS and OpenSSL.
- Have the app use
curl_easy_getinfowith eitherCURLINFO_TLS_SESSIONorCURLINFO_TLS_SSL_PTR. - Have code calling OpenSSL functions when
CURLSSLBACKEND_OPENSSL == info->backend,
Supporting Material/References:
-
This bug appears to have been added by commit https://github.com/curl/curl/commit/2db8ae480fdcae7f005bf847fbbf837821c8184c
-
This report is AI free for your pleasure. Stop the slop!
Impact
Summary:
Crash, potential unknown other impacts depending on the application code.
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
Likely a copy-paste error in the GnuTLS branch of the QUIC TLS helper, which sets the backend field to CURLSSLBACKEND_OPENSSL instead of the GnuTLS backend while storing a GnuTLS session pointer.
Impact
At minimum a crash is likely, and other impacts cannot easily be ruled out, but the issue only arises when an application is linked against both GnuTLS and OpenSSL, which the report calls quite unlikely.
What the attacker needed
App linked against both GnuTLS and OpenSSL; app reads TLS session info via curl_easy_getinfo; app calls OpenSSL functions on the pointer
How it was found
- Build an application linked against both GnuTLS and OpenSSL.
- Have the application call curl_easy_getinfo with CURLINFO_TLS_SESSION or CURLINFO_TLS_SSL_PTR.
- Have the code call OpenSSL functions when the returned backend equals CURLSSLBACKEND_OPENSSL.
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.
A library called libcurl can use different TLS libraries (the software that handles encrypted connections) underneath, such as GnuTLS or OpenSSL. It hands the application a small struct saying which one is in use plus a pointer to the session. Here the label says OpenSSL but the pointer is really a GnuTLS session, so an app that believes the label and calls OpenSSL functions on it is working with the wrong kind of object, which can crash it.
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.