Use-after-free of the internal multi->admin easy handle via the documented CURLMOPT_NOTIFYFUNCTION callback
libcurl's multi handle keeps an internal easy handle that is passed to the CURLMOPT_NOTIFYFUNCTION callback, and the callback is allowed to remove and clean up easy handles. Because neither removal nor cleanup rejects this internal handle, a callback can free it, after which curl_multi_cleanup() reads the freed memory and closes the handle again, causing a use-after-free.
- Disclosed after 3 days
Summary:
curl_multi_init() creates an internal easy handle (multi->admin) and marks it state.internal = TRUE (lib/multi.c:248). The CURLMOPT_NOTIFYFUNCTION callback is handed that internal handle on CURLMNOTIFY_INFO_READ (lib/multi_ntfy.c:109), and the option documentation invites callbacks to remove and clean up easy handles. Neither curl_multi_remove_handle() (lib/multi.c:903, only GOOD_EASY_HANDLE()) nor curl_easy_cleanup() (lib/easy.c:855, no state.internal check) rejects it, so the callback can free multi->admin while the multi handle still references it. The program then reads the freed handle inside curl_multi_cleanup() and closes multi->admin a second time (ASan: heap-use-after-free in Curl_async_thrdd_multi_destroy, lib/vdns/asyn-thrdd.c:506). I reproduced this on the official curl 8.22.0 release tarball and on current git master cdbe4eb; I can provide a patch or more details if useful.
Affected version
curl/libcurl 8.22.0, official release tarball (Release-Date: 2026-09-02, tag curl-8_22_0); also reproduced on current git master cdbe4eb. Platform: x86_64 Linux; static libcurl built from source with clang 14 and -fsanitize=address (RelWithDebInfo). curl -V output of the build used: curl 8.22.0 (Linux) libcurl/8.22.0 Release-Date: 2026-09-02 Protocols: dict file ftp gopher http imap ipfs ipns mqtt pop3 rtsp smtp telnet tftp ws Features: alt-svc AsynchDNS IPv6 Largefile threadsafe UnixSockets
Steps To Reproduce:
- Unpack the attached poc.zip (poc.c, reproduce.sh, build.md). reproduce.sh builds a static libcurl with AddressSanitizer from a curl source tree (master by default, or point SRC at the 8.22.0 source) and compiles the harness.
- Run ./poc - on CURLMNOTIFY_INFO_READ the callback calls curl_multi_remove_handle() and curl_easy_cleanup() on the handle it was given; the program then calls curl_multi_cleanup().
- Observe the ASan heap-use-after-free: the free stack shows curl_easy_cleanup() called from the callback, and the read happens in curl_multi_cleanup() -> Curl_async_thrdd_multi_destroy(). Control: ./poc control (the callback leaves the delivered handle alone) exits cleanly with no sanitizer report.
Impact
Summary:
An application that follows the CURLMOPT_NOTIFYFUNCTION documentation frees libcurl's internal easy handle. Subsequent multi API calls operate on freed heap memory (use-after-free read) and close the handle a second time, which crashes the process or corrupts state (denial of service). Only a completed transfer with notifications enabled is needed - no malicious server is required.
Context
curl's multi interface lets an application drive many transfers at once from a single event loop. curl_multi_init() creates a CURLM handle, and inside that structure libcurl keeps an internal easy handle, multi->admin, which it marks with [redacted] = TRUE (lib/multi.c:248). That handle is not one the application created; it belongs to the multi handle and is used for libcurl's own bookkeeping.
The feature at the centre of this report is CURLMOPT_NOTIFYFUNCTION, a documented multi option that installs a callback for transfer notifications. When a notification of type CURLMNOTIFY_INFO_READ fires, libcurl hands the callback an easy handle (lib/multi_ntfy.c:109). The documentation for the option invites callbacks to remove and clean up easy handles. The report shows that the handle delivered can be the internal multi->admin one.
Setup
The work was done against curl/libcurl 8.22.0, taken from the official release tarball (Release-Date: 2026-09-02, tag curl-8_22_0), and reproduced again on current git master at commit cdbe4eb.
The platform was x86_64 Linux. libcurl was built statically from source with clang 14 and -fsanitize=address, using the RelWithDebInfo configuration. The build used for the test reported itself as:
curl 8.22.0 (Linux) libcurl/8.22.0
Release-Date: 2026-09-02
Protocols: dict file ftp gopher http imap ipfs ipns mqtt pop3 rtsp smtp telnet tftp ws
Features: alt-svc AsynchDNS IPv6 Largefile threadsafe UnixSockets
The proof of concept was shipped as poc.zip, containing poc.c, reproduce.sh and build.md. reproduce.sh builds a static libcurl with AddressSanitizer from a curl source tree (master by default, or the 8.22.0 source if SRC is pointed at it) and then compiles the harness. No server-side component is needed: the trigger is a completed transfer with notifications enabled.
Finding it
The researcher traced what happens to the handle delivered to the notification callback. The callback receives the internal multi->admin handle on CURLMNOTIFY_INFO_READ, and the option's documentation tells callback authors they may remove and clean up easy handles. Two functions were checked for a guard against internal handles:
curl_multi_remove_handle()(lib/multi.c:903) only checksGOOD_EASY_HANDLE().curl_easy_cleanup()(lib/easy.c:855) has no[redacted]check at all.
Neither rejects multi->admin. So a callback that follows the documentation can free the internal handle while the multi handle still holds a reference to it. The multi handle is then left pointing at freed heap memory, and later multi API calls read it.
Exploitation
Step 1: build the instrumented library and harness
Unpack poc.zip and run the reproduction script. It builds a static libcurl with AddressSanitizer from a curl source tree (master by default, or point SRC at the 8.22.0 source) and compiles the harness:
./reproduce.sh
Step 2: run the proof of concept
On CURLMNOTIFY_INFO_READ the callback calls curl_multi_remove_handle() and curl_easy_cleanup() on the handle it was given. The program then calls curl_multi_cleanup().
Step 3: observe the sanitizer report
AddressSanitizer reports a heap-use-after-free. The free stack shows curl_easy_cleanup() called from the callback; the read happens in curl_multi_cleanup() through Curl_async_thrdd_multi_destroy (lib/vdns/asyn-thrdd.c:506). In other words, the program reads the freed handle inside curl_multi_cleanup() and closes multi->admin a second time.
Control run
./poc control
In the control the callback leaves the delivered handle alone. It exits cleanly with no sanitizer report, which isolates the free-and-reuse in the callback as the trigger.
Root cause
The internal easy handle multi->admin is created by curl_multi_init() and flagged with [redacted] = TRUE, but that flag is not enforced at the two places where an application can dispose of an easy handle. curl_multi_remove_handle() only applies GOOD_EASY_HANDLE(), and curl_easy_cleanup() performs no [redacted] check. The notification callback is given the internal handle and the option documentation explicitly invites callbacks to remove and clean up handles, so the documented usage path leads directly to freeing an object the multi handle still owns.
After the free, the multi handle keeps its reference. curl_multi_cleanup() then reads the freed handle and closes multi->admin a second time, producing the use-after-free read and the double close. The existing defences did not stop it because the internal-handle marker is not consulted on either disposal path.
Impact
An application that follows the CURLMOPT_NOTIFYFUNCTION documentation frees libcurl's internal easy handle. Subsequent multi API calls then operate on freed heap memory (a use-after-free read) and close the handle a second time, which crashes the process or corrupts state, a denial of service.
No attacker is involved: only a completed transfer with notifications enabled is needed, and no malicious server is required.
Fix
The report does not describe a patch or a change that was made. The researcher offered to provide a patch or further details. A fix would need to reject internal handles on the disposal paths, so that a callback cannot free the handle the multi handle still owns.
Variants to test
- Other notification types delivered to the callback: check whether any type other than
CURLMNOTIFY_INFO_READalso hands overmulti->admin, and whether the same remove-and-cleanup sequence frees it. - Other documented callbacks that receive an easy handle: try the same remove-then-cleanup sequence from each and watch for a sanitizer report in
curl_multi_cleanup()or a double close. - Direct calls outside a callback: call
curl_multi_remove_handle()andcurl_easy_cleanup()on the internal handle from application code aftercurl_multi_init(), and see whether the internal-handle flag is enforced anywhere. - Cleanup ordering: free the internal handle and then exercise other multi API calls before
curl_multi_cleanup(), looking for reads of freed memory beyond the one inCurl_async_thrdd_multi_destroy. - Build configurations: repeat under AddressSanitizer on both the 8.22.0 tarball and current master, since the report reproduced on both, to confirm the behaviour is not specific to one build.
What happened, in plain words
curl is a very widely used piece of software for moving data over the internet. You have probably used it without knowing: it is the program behind the curl command, and it also exists as a library called libcurl that other programs embed so they can talk to web servers, mail servers and so on. This report is about a bug in libcurl, found by a security researcher.
The bug is a memory management mistake. When a program asks libcurl to manage several network transfers at the same time, libcurl creates a small internal object to keep its own notes. A documented feature lets the application register a function that libcurl calls to report progress. That function is handed the internal object, and the documentation tells developers they may clean up objects they receive. If they do, libcurl frees its own internal object while still believing it is there. Later, when the program shuts everything down, libcurl reads memory that has already been freed. That kind of mistake is called a use-after-free, and it can crash the program.
The important detail is that no attacker is involved. The application only has to follow the documentation.
Background: the words you need
Before the details, a few ideas explained from scratch.
- A library and an API. A library is a collection of ready-made code that other programs use instead of writing everything themselves. The list of functions a library offers, and the rules for calling them, is its API (application programming interface). Think of a restaurant menu: the menu is the API, the kitchen is the library, and you are the application. You order from the menu and the kitchen does the work.
- A handle. In programming, a handle is a value that represents some bigger thing the library keeps internally, a bit like a coat-check ticket. You do not hold the coat itself, only the ticket, and you give the ticket back when you want the coat. In curl, a handle is a pointer to a structure that libcurl manages for you.
- The easy interface and the multi interface. curl offers two ways to work. The easy interface handles one transfer at a time: you set it up, it runs, it finishes. The multi interface lets one program run many transfers at once from a single loop, which is what a busy application needs.
curl_multi_init()creates the multi handle, the object that coordinates all of them. - A callback. A callback is a function you write and hand to a library, so the library can call it back at the right moment. It is like leaving your phone number with a delivery company: they call you when the parcel arrives. Here, the callback is called when something notable happens during a transfer.
- Heap memory, freeing, and use-after-free. Programs get scratch memory from a region called the heap. When they are done with a block, they free it, returning it for reuse. If the program keeps using a block after freeing it, that is a use-after-free. It is like handing back a hotel room key, then walking back into the room: the room may now belong to someone else, or the door may be locked, and either way the result is unpredictable. In software it can mean a crash or corrupted data.
- AddressSanitizer. A debugging tool that watches memory use while a program runs and shouts loudly when it spots a mistake such as a use-after-free, printing exactly where the memory was freed and where it was wrongly used.
- Denial of service. A failure that stops a program or service from working, without the attacker gaining anything. A crash is the simplest example.
Context: how the pieces fit together
curl's multi interface lets an application drive many transfers at once from a single event loop. curl_multi_init() creates a CURLM handle, and inside that structure libcurl keeps an internal easy handle, multi->admin, which it marks with [redacted] = TRUE (lib/multi.c:248). That handle is not one the application created; it belongs to the multi handle and is used for libcurl's own bookkeeping.
In plain terms: when you open a multi handle, libcurl quietly creates a second, private handle for itself and sticks a label on it saying "this one is mine, internal". The application never asked for it and normally never sees it.
The feature at the centre of this report is CURLMOPT_NOTIFYFUNCTION, a documented multi option that installs a callback for transfer notifications. When a notification of type CURLMNOTIFY_INFO_READ fires, libcurl hands the callback an easy handle (lib/multi_ntfy.c:109). The documentation for the option invites callbacks to remove and clean up easy handles. The question the researcher asked is what happens when the handle being delivered is the internal multi->admin one.
So the notification feature is a way to say "tell me when something happens during a transfer". One of those moments is CURLMNOTIFY_INFO_READ. At that moment libcurl passes a handle to your callback. The documentation says callbacks may remove and clean up handles. The researcher's question was simple and sharp: what if the handle you are given is libcurl's own private one?
Setup: what was tested and how
The work was done against curl/libcurl 8.22.0, taken from the official release tarball (Release-Date: 2026-09-02, tag curl-8_22_0), and reproduced again on current git master at commit cdbe4eb.
A release tarball is the packaged source code of a specific published version. Git master is the latest, still-changing copy of the source code. Testing both shows the bug is not a quirk of one old package.
The platform was x86_64 Linux. libcurl was built statically from source with clang 14 and -fsanitize=address, using the RelWithDebInfo configuration. The build used for the test reported itself as:
curl 8.22.0 (Linux) libcurl/8.22.0
Release-Date: 2026-09-02
Protocols: dict file ftp gopher http imap ipfs ipns mqtt pop3 rtsp smtp telnet tftp ws
Features: alt-svc AsynchDNS IPv6 Largefile threadsafe UnixSockets
Line by line, this is the version banner curl prints when asked about itself:
- The first line gives the curl version, the operating system family, and the libcurl version, which here match at 8.22.0.
- The second line gives the release date.
- The
Protocols:line lists the network protocols this build can speak, from dict and file through http, imap, mqtt, smtp and tftp to ws. - The
Features:line lists optional capabilities compiled in, such as AsynchDNS (asynchronous name lookup) and threadsafe.
Building from source means compiling the code yourself rather than installing a ready-made package. Building statically means the library's code is baked into the test program rather than loaded separately at run time. -fsanitize=address switches on AddressSanitizer, the memory watchdog described above. clang 14 is the compiler used. RelWithDebInfo is a build setting that keeps debugging information while still optimising, so the sanitizer report can point at exact source lines.
The proof of concept was shipped as poc.zip, containing poc.c, reproduce.sh and build.md. reproduce.sh builds a static libcurl with AddressSanitizer from a curl source tree (master by default, or the 8.22.0 source if SRC is pointed at it) and then compiles the harness. No server-side component is needed: the trigger is a completed transfer with notifications enabled.
A proof of concept is a small program that demonstrates a bug reliably. A harness is the wrapper that drives the library and checks the result. poc.c is the test program's source, reproduce.sh is a script that rebuilds everything from scratch, and build.md holds build notes. Because the trigger is a normal completed transfer, you do not need a hostile server: the bug happens on the application's own side.
Finding it: why the handle could be freed
The researcher traced what happens to the handle delivered to the notification callback. The callback receives the internal multi->admin handle on CURLMNOTIFY_INFO_READ, and the option's documentation tells callback authors they may remove and clean up easy handles. Two functions were checked for a guard against internal handles:
curl_multi_remove_handle()(lib/multi.c:903) only checksGOOD_EASY_HANDLE().curl_easy_cleanup()(lib/easy.c:855) has no[redacted]check at all.
Neither rejects multi->admin. So a callback that follows the documentation can free the internal handle while the multi handle still holds a reference to it. The multi handle is then left pointing at freed heap memory, and later multi API calls read it. That mismatch between what the documentation permits and what the internal handle's ownership model allows is what made the behaviour look wrong.
Unpacking that: curl_multi_remove_handle() is the function that detaches an easy handle from a multi handle, and curl_easy_cleanup() is the function that frees an easy handle for good. Both are ordinary, documented calls. The first only checks GOOD_EASY_HANDLE(), a sanity test that the value looks like a handle at all. The second does not look at the [redacted] label at all. So the label saying "libcurl owns this one" is written but never read on either path. The application is allowed to free something the library still relies on, and the library is left holding a reference, meaning a stored pointer, to memory that no longer belongs to it.
Exploitation: reproducing it step by step
Step 1: build the instrumented library and harness
Unpack poc.zip and run the reproduction script. It builds a static libcurl with AddressSanitizer from a curl source tree (master by default, or point SRC at the 8.22.0 source) and compiles the harness:
./reproduce.sh
This one line runs the script. The ./ means "the file in the current folder". The script does the heavy lifting: it compiles libcurl with the memory watchdog switched on, then compiles the test program against it. Doing this first means every later run is instrumented, so any memory mistake is reported instead of silently ignored.
Step 2: run the proof of concept
This runs the test program. On CURLMNOTIFY_INFO_READ the callback calls curl_multi_remove_handle() and curl_easy_cleanup() on the handle it was given. The program then calls curl_multi_cleanup().
In order: the program starts a transfer with notifications enabled; libcurl fires the notification and passes the handle; the callback, doing exactly what the documentation allows, detaches that handle and frees it; the program then shuts the multi handle down with curl_multi_cleanup(). That last call is where the freed memory gets touched again.
Step 3: observe the sanitizer report
AddressSanitizer reports a heap-use-after-free. The free stack shows curl_easy_cleanup() called from the callback; the read happens in curl_multi_cleanup() through Curl_async_thrdd_multi_destroy (lib/vdns/asyn-thrdd.c:506). In other words, the program reads the freed handle inside curl_multi_cleanup() and closes multi->admin a second time.
A stack is the chain of function calls that led to a point in the program, like a list of who called whom. The free stack tells you where the memory was released: in curl_easy_cleanup(), called from the callback. The read happens later, during shutdown, inside a function called Curl_async_thrdd_multi_destroy. And because the handle is closed once in the callback and again during shutdown, it is a double close as well as a use-after-free.
Control run
./poc control
In the control the callback leaves the delivered handle alone. It exits cleanly with no sanitizer report, which isolates the free-and-reuse in the callback as the trigger.
A control run is the same experiment with the suspected cause removed. Here the only change is that the callback does not touch the handle. If the crash disappears, the callback's free-and-reuse is what causes it, not something else in the setup.
Root cause
The internal easy handle multi->admin is created by curl_multi_init() and flagged with [redacted] = TRUE, but that flag is not enforced at the two places where an application can dispose of an easy handle. curl_multi_remove_handle() only applies GOOD_EASY_HANDLE(), and curl_easy_cleanup() performs no [redacted] check. The notification callback is given the internal handle and the option documentation explicitly invites callbacks to remove and clean up handles, so the documented usage path leads directly to freeing an object the multi handle still owns.
After the free, the multi handle keeps its reference. curl_multi_cleanup() then reads the freed handle and closes multi->admin a second time, producing the use-after-free read and the double close. The existing defences did not stop it because the internal-handle marker is not consulted on either disposal path.
Put simply: the library writes a "do not touch, this is mine" label, then never checks it at the two doors through which an application can throw a handle away. The documentation points users at one of those doors while holding the labelled object. The result is predictable.
Impact
An application that follows the CURLMOPT_NOTIFYFUNCTION documentation frees libcurl's internal easy handle. Subsequent multi API calls then operate on freed heap memory (a use-after-free read) and close the handle a second time, which crashes the process or corrupts state, a denial of service.
No attacker is involved: only a completed transfer with notifications enabled is needed, and no malicious server is required. The report rates the issue medium severity.
In everyday terms: a well-behaved program that uses the feature as documented can crash itself. Nobody has to attack it. A crash is still a crash, and corrupted state can be worse than a clean stop.
Fix
The report does not describe a patch or a change that was made. The researcher offered to provide a patch or further details. A fix would need to reject internal handles on the disposal paths, so that a callback cannot free the handle the multi handle still owns.
A patch is a small change to source code that fixes a problem. The idea here is to make the label mean something: before freeing or detaching a handle, check whether it is marked internal, and if it is, refuse. That closes both doors at once.
Variants to test
- Other notification types delivered to the callback: check whether any type other than
CURLMNOTIFY_INFO_READalso hands overmulti->admin, and whether the same remove-and-cleanup sequence frees it. - Other documented callbacks that receive an easy handle: try the same remove-then-cleanup sequence from each and watch for a sanitizer report in
curl_multi_cleanup()or a double close. - Direct calls outside a callback: call
curl_multi_remove_handle()andcurl_easy_cleanup()on the internal handle from application code aftercurl_multi_init(), and see whether the internal-handle flag is enforced anywhere. - Cleanup ordering: free the internal handle and then exercise other multi API calls before
curl_multi_cleanup(), looking for reads of freed memory beyond the one inCurl_async_thrdd_multi_destroy. - Build configurations: repeat under AddressSanitizer on both the 8.22.0 tarball and current master, since the report reproduced on both, to confirm the behaviour is not specific to one build.
Each variant asks the same underlying question from a different angle: is the internal label checked anywhere, and can the private handle be freed through any other documented route?
Glossary
- API: the set of functions and rules a library offers to the programs that use it.
- AddressSanitizer: a tool that watches a running program's memory use and reports mistakes such as use-after-free.
- Callback: a function you give to a library so the library can call it back at a chosen moment.
- Control run: a repeat of an experiment with the suspected cause removed, to confirm it is really the cause.
- curl / libcurl: a command-line tool and a library for transferring data over network protocols.
- CURLM handle: the object created by
curl_multi_init()that coordinates several transfers at once. - CURLMOPT_NOTIFYFUNCTION: a documented curl option that installs a callback for transfer notifications.
- CURLMNOTIFY_INFO_READ: a notification type fired when information has been read during a transfer.
- Denial of service: a failure that stops a program or service working, without the attacker gaining anything.
- Double close: closing or freeing the same object twice, which is a memory error.
- Easy handle: the object representing a single transfer in curl.
- Free: to return a block of memory to the system so it can be reused.
- Git master: the latest, still-changing version of a project's source code.
- Handle: a value that stands for a larger object a library keeps internally, like a coat-check ticket.
- Harness: a small program built to drive a library and check its behaviour.
- Heap: the region of memory a program uses for objects it creates while running.
- Internal handle: a handle libcurl creates for its own bookkeeping, marked
[redacted] = TRUE, rather than one the application asked for. - libcurl: the library form of curl, embedded in other programs.
- Medium severity: a rating on a scale of how serious a security issue is; here, between low and high.
- Multi interface: curl's way of running many transfers at once from one loop.
- Patch: a small change to source code that fixes a problem.
- Proof of concept: a small program that demonstrates a bug reliably.
- Reference: a stored pointer to an object; if the object is freed, the reference points at invalid memory.
- Release tarball: the packaged source code of a specific published version.
- RelWithDebInfo: a build setting that keeps debugging information while still optimising.
- Stack: the chain of function calls that led to a point in a program.
- Static build: a build where the library's code is baked into the program rather than loaded separately.
- Use-after-free: using a block of memory after it has been freed, which can crash a program or corrupt data.
- x86_64 Linux: a common computer architecture running the Linux operating system.