CVE-2019-5481: krb5: double-free in read_data() after realloc() fail
A double-free vulnerability exists in lib/security.c when Curl_saferealloc() fails, and an attacker could remotely trigger it by sending a large length value.
- Triaged in 20 hours
- Fixed in 8 days
- Paid in 42 hours
- Disclosed after 14 months
Summary:
In 'lib/security.c', there is a double-free of the reference 'buf->data' on the teardown path if 'Curl_saferealloc()' fails.
Also, since we read 'len' from the 'fd', the sender might be able to remotely trigger a realloc() failure, and then the double-free, by sending the value 0x7fffffff.
Introduced by 0649433da realloc: use Curl_saferealloc to avoid common mistakes
Steps To Reproduce:
Actual double-free was not reproduced. The realloc failure with particular 'len' value can be reproduced on my 32bits linux machine with following code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
void *ptr = malloc(10);
if (!ptr)
return -1;
int len = 0x7fffffff;
void *ptr2 = realloc(ptr, len);
if (!ptr2) {
printf("Triggered realloc failure\n");
return 0;
}
return -1;
}
Comment:
Also checked other occurences of 'Curl_saferealloc()' calls which all seem fine otherwise.
Impact
Double-free after a 'realloc()' failure, which could be triggered remotely, depending on the use context of the 'read_data()' function.
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 code frees 'buf->data' on the error path after Curl_saferealloc() fails, but that pointer was already freed or not updated, leading to a double-free.
Impact
A double-free could be triggered remotely, depending on the use context of the read_data() function.
What the attacker needed
Ability to send data to read_data()
How it was found
- Send a length value of 0x7fffffff to trigger a realloc failure.
- The realloc failure is on the teardown path that would lead to the double-free.
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 or be exploited. Here, if a memory allocation fails, the code mistakenly frees a buffer that is already freed. An attacker might cause that failure by sending a very large size value.
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.