Double free in tool_ssls_load()
The curl tool's SSL session loading code frees two buffers without clearing the pointers, so a malformed session file can cause the same memory to be freed twice. An attacker who can supply a crafted session file could crash the tool or potentially cause other dangerous behaviour.
- Disclosed after 12 hours
Summary:
There is a double-free bug(s) in tool_ssls_load(), which can happen at line 83-84 or 129-130 (tool_ssls.c):
curl_free(shmac);
curl_free(sdata);
The root cause is that line 83-84 did not reset shmac and sdata to NULL.
If the seesion is malformed, the double-free will be triggerd.
No AI was used to find the issue or generate the report.
Affected version
It was introduced in commit https://github.com/curl/curl/commit/515a21f350b89f0676e5df7f904c62c8f67be377 on Jan 9, 2025.
So, it can affect v8.12.0~v8.17.0. It only affects curl tool.
Steps To Reproduce:
- Build curl-8_17_0 from source. (my configure is: "./configure --enable-debug --with-openssl --enable-static --disable-shared --enable-ssls-export").
--enable-ssls-exportis key to enable the vunerable code. - Create a malformed session file (Please refer to the attached one). The logic is to make the code continue before reset
shmacandsdatavia curlx_base64_decode(). My choice is directly leverage the content check at https://github.com/curl/curl/blob/master/src/tool_ssls.c#L81-L91. - Run the
curltool:./src/curl --ssl-sessions .curl_ssl_sessions https://example.com. That's it.
Note:
To be honest, I am very happy but also a bit "disappointed" when my tool found it, because the feature SSLS-EXPORT is marked as EXPERIMENTAL again.
I understand that the project should provide appropriate reminders to users due to the possible unstable functionalities of new features. But as a contributor,I sincerely hope that maintainers can evaluate based on the facts of code and actual scope, rather than policy labels. By doing so, I believe that the contributors will be more motivated to extensively test new features to help curl grow better.
Anyway, I responsibly reported it and its PoC here, as well as submit the the corresponding patch via PR (https://github.com/curl/curl/pull/19588) with no sensitive word mentioned.
Supporting Material/References:
The malformed PoC session file (.curl_ssl_sessions).
- [attachment / reference]
.curl_ssl_sessions
Impact
Summary:
Attackers can trigger double-free vulnerability via specially crafted SSL session files, causing DoS or other potential dangerous behaviors.
Attack Prerequisites:
- Requires SSLS-EXPORT feature enabled
- Attacker can influence SSL session file content, or can influence session data generation process
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the error path frees the shmac and sdata buffers but leaves the pointers set, so a later cleanup frees them a second time.
Impact
An attacker able to influence the session file content could trigger a double free, causing a denial of service or other potentially dangerous behaviour, though only when the experimental SSLS export feature is enabled.
What the attacker needed
SSLS-EXPORT feature enabled; attacker can influence session file content
The fix
The pointers should be reset to NULL after freeing so a later cleanup does not free them again; a patch was submitted via pull request.
How it was found
- Build curl from source with the SSLS export feature enabled.
- Create a malformed session file that makes the code continue before the pointers are reset.
- Run the curl tool pointing it at that session file and a URL.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program finishes with a piece of memory it hands it back to the system, called freeing. If it frees the same block twice, the memory manager can get confused and the program may crash or misbehave. Here a crafted session file makes the code take an early exit path that frees the buffers, and later they get freed again.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.