Use-after-free read of the CURLOPT_RESOLVE list after curl_easy_reset()
curl_easy_reset() does not clear the internal pointer to the CURLOPT_RESOLVE list, so after an application frees its list the next transfer reads freed memory while parsing resolve entries. This causes a heap-use-after-free read that crashes the process in a native build.
Originally disclosed on HackerOne
- Disclosed after 29 hours
Summary:
Setting CURLOPT_RESOLVE stores the application's curl_slist pointer in an internal handle field that curl_easy_reset() does not clear, so after the application frees its list, the next curl_easy_perform() on the reset handle reads the freed memory while parsing the resolve entries. Freeing the list at that point follows the documentation: CURLOPT_RESOLVE(3) states the list is not copied and must be kept around only until after the transfer has completed, and curl_easy_reset(3) states all options previously set on the handle are re-initialized to their default values, the state the handle had when created.
Affected version
curl 8.23.0 built from the upstream curl-8_23_0 source on Linux x86_64: clang -O1 + ASan reports the heap-use-after-free below, and a gcc -O2 native build crashes with SIGSEGV (exit 139) on the same sequence.
Steps To Reproduce:
Build curl 8.23.0 with ASan, compile the PoC against that build and run it; no network access is needed because the freed list is parsed during Curl_pretransfer, before any connection is attempted.
cmake -B b -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_C_FLAGS="-fsanitize=address -g -O1" && cmake --build b -j
gcc -fsanitize=address poc.c -o poc -I<curl-src>/include -Lb/lib -lcurl
./poc
poc.c:
/* curl 8.23.0 - curl_easy_reset() does not clear the internal
* state.resolve alias of the CURLOPT_RESOLVE list. */
#include <curl/curl.h>
int main(void)
{
CURL *h = curl_easy_init();
struct curl_slist *resolve =
curl_slist_append(NULL, "host-a.invalid:59998:127.0.0.1");
curl_slist_append(resolve, "host-b.invalid:59998:127.0.0.1");
curl_slist_append(resolve, "host-c.invalid:59998:127.0.0.1");
curl_easy_setopt(h, CURLOPT_URL, "http://host-a.invalid:59998/");
curl_easy_setopt(h, CURLOPT_RESOLVE, resolve);
curl_easy_reset(h); /* doc: handle back to as-created state */
curl_slist_free_all(resolve); /* app frees its own list */
curl_easy_setopt(h, CURLOPT_URL, "http://host-a.invalid:59998/");
curl_easy_perform(h); /* UAF read during Curl_pretransfer */
curl_easy_cleanup(h);
return 0;
}
Essential ASan output:
ERROR: AddressSanitizer: heap-use-after-free on address 0x502000000010
READ of size 8 at 0x502000000010 thread T0
#0 Curl_loadhostpairs lib/vdns/dnscache.c:865:31
#1 Curl_pretransfer lib/transfer.c:536:14
... frames 2-7: multi/easy internals ...
#8 curl_easy_perform lib/easy.c:855:14
freed by thread T0 here:
#1 curl_slist_free_all lib/slist.c:136:5
native gcc -O2 run: SIGSEGV, exit code 139
Impact
Summary:
This is a use-after-free read inside libcurl, reached through documented API usage, that reliably crashes the process in a native -O2 build, affecting any application that resets easy handles and frees its CURLOPT_RESOLVE lists.
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
Impact
Any application that resets an easy handle and frees its CURLOPT_RESOLVE list can crash the process, as shown by a SIGSEGV in a native build.
What the attacker needed
Application resets an easy handle; application frees its resolve list; no network access needed
How it was found
- Build curl 8.23.0 with AddressSanitizer enabled.
- Compile the proof-of-concept program against that build.
- Run the program, which sets a resolve list, resets the handle, frees the list and performs a request.
- Observe the heap-use-after-free report under ASan and the crash in a native build.
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 program can tell curl to send a hostname to a fixed address using a list of entries it owns. The documentation says resetting the handle returns it to its fresh state, so the program frees its list afterwards. But curl keeps a hidden pointer to that freed list and reads it on the next request, which is a use-after-free and can crash the program.
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.