Skip to content
Memory corruption Disclosed report Intermediate

Use after free in hyperfifo example

The hyperfifo example frees the libevent event base before calling curl_multi_cleanup, so the add-socket callback later touches freed memory. Projects that copied the example could crash, but the reporter says an attacker could achieve little beyond a crash.

deepbluev7 Follow

Originally disclosed on HackerOne

Informational View original
  • Disclosed after 30 hours

Summary:

THIS ONLY IS AN ISSUE IN EXAMPLE CODE, NOT CURL ITSELF!

In the hyperfifo example the event base is freed before the curl_multi_cleanup is called. This leads to a use after free in the addsocket callback, when libevent tries to lock a mutex in the base event during the curl shutdown.

Link to the problematic code: https://github.com/curl/curl/blob/d6807890696019308bc885871575f3c2dac875d4/docs/examples/hiperfifo.c#L453

Affected version

8.18.0, but the bug has been there for a while, likely since the beginning of that example. Interestingly the multi-event example seems to not be affected.

Steps To Reproduce:

Running the example under ASAN should be sufficient. I have however not verified that, however the same code did cause crashes in my project: https://nheko.im/nheko-reborn/coeurl/-/commit/7e0afef3e774497efa29bf581630747cddd95e55 https://github.com/Nheko-Reborn/nheko/issues/1941

Impact

Summary:

ONLY AFFECTS AN EXAMPLE! NOT A BUG IN CURL!

The impact should basically be none, I am only submitting this here, because I haven't found documentation on how issues in examples should be submitted and other projects might have copied the example as a base (like I did), which can lead to crashes in some circumstances. As such I am just being overly careful in reporting this, please close this as invalid or whatever, if you think that is the best approach. I just wanted to let you judge the impact of this instead of me just reporting something possibly sensitive on the bug tracker.

I don't think an attacker could achieve much more that a crash in projects, that copied the example code.

For example we were affected by this, but haven't filed any security issue about it either: https://github.com/Nheko-Reborn/nheko/issues/1941

The original report as published on HackerOne, by deepbluev7. 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 example tears down the libevent event base before curl_multi_cleanup, so the add-socket callback runs against freed memory.

Impact

The reporter states the impact should basically be none and that an attacker could achieve little more than a crash in projects that copied the example.

What the attacker needed

Project copied the example code; example reaches shutdown

How it was found

  1. Build and run the hyperfifo example, ideally with AddressSanitizer enabled.
  2. Let the example reach shutdown so the event base is freed.
  3. Observe the add-socket callback touching the freed event base during curl cleanup.

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 use-after-free happens when a program releases a block of memory and then keeps using it, so it may read or write whatever now sits there. Here the example code shuts down its event loop before telling the curl library to clean up, and the cleanup still tries to use the event loop. The result is usually a crash, not a way for someone to take over a machine.

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 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.