heap-use-after-free /netwerk/sctp/datachannel/DataChannel.cpp:3021 in mozilla::DataChannelConnection::CloseAll
A use-after-free exists in Firefox's SCTP data channel shutdown code, where closing a pending channel can run user callback code that frees the connection object while it is still being used. An attacker could potentially trigger a crash or memory corruption by causing channels to be closed in this way.
- Fixed in 11 days
- Paid in 22 days
- Disclosed after 11 days
Created attachment 9412708
240715.zip
#Reproduce
OS:Win10 X64
130.0a1 (2024-07-14) (64-bit)
step:
1. python -m http.server 1337
2. python -m ffpuppet firefox.exe -p prefs.js -d -u http://localhost:1337/poc.html
#Analysis
Code at [1] may trigger user callback code, causing the THIS(DataChannelConnection) object to be freed, leading to UAF
'''
https://searchfox.org/mozilla-central/source/netwerk/sctp/datachannel/DataChannel.cpp#3025
void DataChannelConnection::CloseAll() {
DC_DEBUG(("Closing all channels (connection %p)", (void*)this));
// Make sure no more channels will be opened
MutexAutoLock lock(mLock);
SetState(DataChannelConnectionState::Closed);
// Close current channels
// If there are runnables, they hold a strong ref and keep the channel
// and/or connection alive (even if in a CLOSED state)
for (auto& channel : mChannels.GetAll()) {
MutexAutoUnlock lock(mLock);
channel->Close();
}
// Clean up any pending opens for channels
for (const auto& channel : mPending) {
DC_DEBUG(("closing pending channel %p, stream %u", channel.get(),
channel->mStream));
MutexAutoUnlock lock(mLock);
channel->Close(); // also releases the ref on each iteration <<[1]
}
mPending.clear();
// It's more efficient to let the Resets queue in shutdown and then
// SendOutgoingStreamReset() here.
SendOutgoingStreamReset();
}
'''
#Note
testharness.js & testharnessreport.js & RTCPeerConnection-helper.js are come from wpt test framework
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 CloseAll loop calls channel->Close() while holding only an unlocked mutex, and that call can invoke user callbacks that drop the last reference to the DataChannelConnection, so the loop continues using a freed object.
Impact
Could cause a crash or memory corruption in the browser when channels are closed during shutdown; the text does not demonstrate code execution.
What the attacker needed
Victim loads a crafted page; Firefox build with SCTP data channels
How it was found
- Serve the proof-of-concept page from a local HTTP server.
- Launch Firefox with the supplied prefs and the proof-of-concept URL using ffpuppet.
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 frees a piece of memory but keeps using it afterwards, that is called a use-after-free. Here, closing a data channel can run code that frees the connection object, and then the same function keeps touching that freed object, which can crash the browser or corrupt memory.
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.