Use-After-Free in OpenSSL Keylog Callback via SSL_get_ex_data() in libcurl
A use-after-free vulnerability exists in libcurl when the OpenSSL keylog callback is set, because the callback may be invoked after the SSL object has been freed, leading to access to a dangling pointer. This can cause a segmentation fault (denial of service) and potentially code execution under specific conditions.
Originally disclosed on HackerOne
- Disclosed after 11 hours
Summary:
A Use-After-Free (UAF) vulnerability exists in libcurl when the OpenSSL SSL_CTX_set_keylog_callback is set. The callback may be invoked after the associated SSL object has been freed via SSL_free(), leading to access to a dangling pointer and potential crash or information leak via SSL_get_ex_data().
This can be triggered manually or accidentally through custom keylog callbacks when ex_data is accessed inside the callback and the SSL object is no longer valid.
Security impact: Under specific conditions (when keylog callback is configured), it results in a segmentation fault (DoS). If further heap grooming or ex_data abuse is possible, this may lead to code execution.
Affected version
Tested on:
curl 8.8.0 (OpenSSL 3.3.0) Release-Date: 2024-06-26 Protocols: dict file ftp ftps gopher gophers http https imap imaps mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp Features: alt-svc AsynchDNS HSTS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL threadsafe TLS-SRP UnixSockets Platform: Termux (Android 11, aarch64) OpenSSL: 3.3.0 built from source
Steps To Reproduce:
- Build the following minimal C program (tested with gcc -o segv segv.c -lssl -lcrypto):
#include <openssl/ssl.h> #include <openssl/err.h> #include <stdio.h> #include <stdlib.h>
void my_keylog_cb(const SSL *ssl, const char *line) { printf("Keylog callback: %s\n", line); // UAF: SSL already freed void *ptr = SSL_get_ex_data((SSL *)ssl, 0); // cast to remove const printf("Data: %p\n", ptr); }
int main() { SSL_library_init(); SSL_load_error_strings();
SSL_CTX *ctx = SSL_CTX_new(TLS_client_method());
SSL_CTX_set_keylog_callback(ctx, my_keylog_cb);
SSL *ssl = SSL_new(ctx);
int idx = SSL_get_ex_new_index(0, "mydata", NULL, NULL, NULL);
char *data = strdup("hello");
SSL_set_ex_data(ssl, idx, data);
SSL_free(ssl); // Free SSL
// Trigger callback after free
my_keylog_cb(ssl, "CLIENT_RANDOM deadbeef...");
SSL_CTX_free(ctx);
free(data);
return 0;
}
- Run the binary:
$ ./segv Keylog callback: CLIENT_RANDOM deadbeef... Data: 0x0 Segmentation fault
Was an AI involved?
No, the bug was discovered through manual auditing and testing. However, AI (ChatGPT) was used only to assist in writing documentation and estimating CVSS/weakness classification (e.g., CWE-416).
Impact
Under specific conditions (when keylog callback is configured), it results in a segmentation fault (DoS). If further heap grooming or ex_data abuse is possible, this may lead to code execution.
Attachments

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 the keylog callback is invoked after the SSL object has been freed, without checking that the object is still valid.
Impact
Under specific conditions (when keylog callback is configured), it results in a segmentation fault (DoS). If further heap grooming or ex_data abuse is possible, this may lead to code execution.
What the attacker needed
Keylog callback configured; SSL object freed before callback
How it was found
- Build a minimal C program that sets a keylog callback and frees the SSL object.
- Run the binary, which triggers the callback after the SSL object is freed.
- Observe the segmentation fault.
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 use-after-free happens when a program frees memory but then keeps using it. Here, a callback that logs encryption keys can run after the secure connection object is gone, so it reads leftover data and crashes. The text says this can be triggered manually or accidentally.
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.