word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word word
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1
mmMwWLliI0fiflO&1Please use the print function of Shimo document, click the menu bar [Print]
BUG_Author: Heng Zhang
Affected Version: Live555 Streaming Media 2018.9.2 (liveMedia)
Vendor: Live555 GitHub Repository
Software: Live555 Streaming Media / testOnDemandRTSPServer
Vulnerability Files:
liveMedia/MatroskaFile.cpp(MatroskaDemux allocation/usage)liveMedia/MatroskaFileServerMediaSubsession.cpp(creates per-track sources from the demux)liveMedia/include/Media.hh(access toMedium::envir()on a freed object)liveMedia/Media.cpp(MediaLookupTable::remove deletesMediuminstances)liveMedia/RTSPServer.cpp,liveMedia/OnDemandServerMediaSubsession.cpp,liveMedia/GenericMediaServer.cppDuring RTSP
SETUPfor a Matroska (.mkv) stream,MatroskaFileServerMediaSubsession::createNewStreamSource()requests a demuxed track fromMatroskaDemux. InsideMatroskaDemux::newDemuxedTrackByTrackNumber(), the code constructs aMatroskaDemuxedTrackusingenvir()from the demux (Medium::envir()).A crafted
test.mkvcan trigger a lifetime mismatch where theMatroskaDemuxobject has been removed fromMediaLookupTableand deleted (viaMediaLookupTable::remove()), yet a stale pointer to the demux is still used to create a new track. The call toMedium::envir()therefore dereferences a freedMatroskaDemuxinstance, causing a heap-use-after-free and crash.RTSPServer::RTSPClientConnection::handleRequestBytes()→RTSPServer::RTSPClientSession::handleCmd_SETUP()→OnDemandServerMediaSubsession::getStreamParameters()→MatroskaFileServerMediaSubsession::createNewStreamSource()→MatroskaDemux::newDemuxedTrackByTrackNumber()→Medium::envir()(UAF on freedMatroskaDemux)MatroskaDemuxobject is managed as aMediumand can be deleted byMediaLookupTable::remove()while other code still holds raw pointers to it.MatroskaDemuxpointer to construct a demuxed track, leading to a dereference of freed memory inMedium::envir().SETUPfor Matroska streams.The following steps detail the setup process for building the Live555 Streaming Media library and the required demo program.
Clone the Live555 source repository:
git clone https://github.com/rgaufman/live555.gitNavigate into the directory and check out the commit corresponding to version 2018.09.02:
git checkout ceeb4f4Build the Live555 Streaming Media libraries and the associated demo programs. The compilation must be performed with AddressSanitizer (ASAN) enabled (e.g., by including the necessary ASAN flags in the compiler and linker options, such as
-fsanitize=address).Ensure that the demo program testOnDemandRTSPServer is successfully compiled and produced as an output binary.test.mkvin the working directory used by thematroskaFileTeststream.Start the server:
From an RTSP client, issue a typical control sequence against the Matroska stream (the crash occurs during
SETUP):With the crafted
test.mkvin place, the process terminates with the AddressSanitizer heap-use-after-free report above.liveMedia/include/Media.hh:59(UsageEnvironment& Medium::envir() const)liveMedia/MatroskaFile.cpp:724–730(MatroskaDemux::newDemuxedTrackByTrackNumber)liveMedia/MatroskaFile.cpp:230–235(MatroskaFile::newDemux)liveMedia/Media.cpp:135–149(MediaLookupTable::removedeletesMedium)RTSPServer::RTSPClientSession::handleCmd_SETUP→OnDemandServerMediaSubsession::getStreamParameters→MatroskaFileServerMediaSubsession::createNewStreamSource→MatroskaDemux::newDemuxedTrackByTrackNumber(UAF)Type: Use-After-Free (dangling pointer dereference)
Impact: Denial of Service; potential memory corruption
Trigger: Crafted Matroska file (
test.mkv) causing premature demux deletion while a stale pointer remains in use