Double-free vulnerability in libcurl with rustls via NoServerCertVerifier condition leads to application crash
A double-free bug exists in libcurl when built with rustls, triggered when the certificate verifier is not initialised because the peer verification and CA store conditions are not met. An attacker could potentially cause an application crash, though the reporter notes it is hard to reproduce controllably and mainly a risk in out-of-memory scenarios.
- Disclosed after 15 hours
Summary:
There is a double-free in libcurl with rustls. The root cause is reported and it is fixed in https://github.com/curl/curl/pull/19425, while I did not try to evaluate the actual triggering at that time.
No AI was used to find the issue or generate the report.
Affected version
It was introduced via commit https://github.com/curl/curl/commit/088f0e6a5b8d934073a0e089ebecd14ca75120c4 on Mar 25, 2025. It affected the official version from v8.13.0 to v8.17.0.
Steps To Reproduce:
- Installation: (1) Install rustls-ffi via https://github.com/rustls/rustls-ffi/releases/download/v0.15.0/librustls_0.15.0_amd64.deb.zip. (2) Build curl-8_17_0 from source. (my configure is: "./configure --enable-debug --enable-static --disable-shared --with-rustls")
- Compile the basic PoC program via "gcc -o test_rustls_fail test.c -I./include ./lib/.libs/libcurl.a -lnghttp2 -lpsl -lrustls -lpthread -lz -fsanitize=address -g" (The source of PoC program is attached). The basic target is to trigger NoServerCertVerifier of rustls_client_config_builder_build() at https://github.com/rustls/rustls-ffi/blob/0b5f053fe5200e262ed70c100cc5486ce76d9d8a/librustls/src/client.rs#L505.
In cr_init_backend, https://github.com/curl/curl/blob/master/lib/vtls/rustls.c#L1046-L1067 is for setting the verifier. Once !conn_config->verifypeer, ssl_config->native_ca_store and (ca_info_blob || ssl_cafile) are not satisfied, then the verifier will not be inited.
3. Run the PoC program. The output/sanitizer info will show the double-free problem.
Note:
I did not fully try other unsuccessful possibilities of rustls_client_config_builder_build(). The PoC is just a real triggering case to show the existence of double-free.
Based on my personal analysis, it is mainly affect the libcurl and it is hard to reproduce it in a controllable manner for curl tool.
However, there is still a risk of curl crashing in the oom scenario.
For example, the API rustls_client_config_builder_dangerous_set_certificate_verifier returns OK yet the verifier may not be successfully set due to oom at https://github.com/rustls/rustls-ffi/blob/0b5f053fe5200e262ed70c100cc5486ce76d9d8a/librustls/src/client.rs#L218.
Maybe we can also further prevent it earlier just like below:
else if(ca_info_blob || ssl_cafile) {
result = init_config_builder_verifier(data,
config_builder,
conn_config,
ca_info_blob,
ssl_cafile);
if(result != CURLE_OK) {
rustls_client_config_builder_free(config_builder);
return result;
}
}
+ else {
+ rustls_client_config_builder_free(config_builder);
+ return CURLE_SSL_CONNECT_ERROR;
+ }
Supporting Material/References:
The source of PoC program.
- Please see the attached file
test.c.
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 in the rustls backend frees the config builder without returning an error when the certificate verifier cannot be initialised, leading to a double-free.
Impact
The double-free could crash the application, though the reporter says it is hard to reproduce controllably and mainly a risk in out-of-memory scenarios.
What the attacker needed
Curl built with rustls; specific verifier setup conditions; out-of-memory may be needed
The fix
The root cause was reported and fixed in a pull request, and the reporter also suggests freeing the config builder and returning an error when the verifier cannot be set up.
How it was found
- Install the rustls-ffi library package.
- Build curl from source with rustls support enabled.
- Compile the provided test program with address sanitizer.
- Run the test program and observe the double-free report.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A double-free happens when a program frees the same memory twice, which can corrupt memory and crash the program. Here, libcurl built with a TLS library called rustls can hit this when it fails to set up certificate checking in a particular configuration. The reporter shows a small test program that triggers the crash under a memory checker.
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.