Skip to content
Memory corruption Disclosed report Advanced

Heap overflow via HTTP/2 PUSH_PROMISE

libcurl's HTTP/2 handling of PUSH_PROMISE headers doubles an array's allocation size without checking for integer overflow, so on 32-bit platforms a very large number of headers can cause too little memory to be allocated and pointers to be written past the buffer. An attacker running a malicious HTTP/2 server could trigger a heap overflow, though the report notes this is very hard to reach and the practical impact is low.

nyymi Follow

Originally disclosed on HackerOne

  • Disclosed after 3 days

Summary:

libcurl HTTP/2 support processes incoming PUSH_PROMISE headers by storing them in an array. The code initially allocates storage for 10 headers and then keeps doubling the array size as needed:

      stream->push_headers_alloc *= 2;
      headp = Curl_saferealloc(stream->push_headers,
                               stream->push_headers_alloc * sizeof(char *));

(https://github.com/curl/curl/blob/07a9b89fedaec60bdbc254f23f66149b31d2f8da/lib/http2.c#L1053)

On 32-bit platforms after receiving 10 << 26 headers the the allocation size will overflow, resulting in too little memory being allocated ((10 << 27) * sizeof(char *) will be truncated to lower 32-bit resulting in 1 GB storage being allocated) for the array. Subsequently the pointers will be written to unallocated memory by stream->push_headers[stream->push_headers_used++] = h;

Steps To Reproduce:

  1. Have HTTP2 server that sends more than 1 << 26 PUSH_PROMISE headers
  2. curl https://targetsite

The fix is to limit the amount of promise headers that are accepted and return error if too many are received.

Impact

Heap overflow.

This issue is likely very hard to trigger as it requires a system where realloc for (1 << 26) * sizeof(char *) bytes is successful. This is rather rare. In addition to be exploitable in other than denial of service capacity the attacker would need to find out some way way to obtain code execution by the array overflow. This would likely work by having some object get allocated to the newly released heap memory and then get overwritten by this array pointer write. An example would be an object that has pointer to command to execute.

As such the practical impact of this vulnerability is low.

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

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 array growth calculation multiplies the allocation count by the pointer size without checking for integer overflow, so on 32-bit systems the requested size wraps to a much smaller value than the writes require.

Impact

A heap overflow occurs, but the report states it is likely very hard to trigger and the practical impact is low, with code execution requiring further heap grooming.

What the attacker needed

32-bit platform; attacker-controlled HTTP/2 server; victim runs curl against it; very large realloc succeeds

The fix

The fix is to limit the number of promise headers accepted and return an error when too many are received.

How it was found

  1. Set up an HTTP/2 server that sends more than 1 << 26 PUSH_PROMISE headers.
  2. Run curl against that server.

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 needs to store a growing list, it asks the system for more memory each time the list gets bigger. Here the program multiplied the size by two repeatedly without checking whether the number had become too large to represent, so the memory request wrapped around to a small value while the program kept writing entries into it. That means data gets written past the end of the reserved space, which is called a heap overflow.

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.

More by nyymi

View all

51 more disclosed reports, best first.

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.