BaseMediaResource::ModifyLoadFlags Use-After-Free using MP4 video.
A media resource used to download an MP4 video could be freed while still referenced after the iframe was removed and the document rewritten. An attacker could trigger a use-after-free and crash the browser, with the freed memory potentially reused by a new document.
- Fixed in 11 days
- Paid in 23 days
- Disclosed after 11 days
Created attachment 8824656
test.html
User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0 SeaMonkey/2.46
Build ID: 20161229190117
Steps to reproduce:
Download the attached mp4 video file and create an iframe tag with the src pointing to it,
then removing the iframe nodes and doing a document.write in the main window right after can cause the media resource
chanel used to download the mp4 to be freed and reused in a short time inside this new document.
It doesn't crash if using timers or events so I had to wait in an alert or sync XMLHttpRequestt for the object deletion,
apparently as stated here https://dxr.mozilla.org/mozilla-central/source/dom/media/MediaResource.h#438, it can only be
accessed from the main thread.
I'm reproducing it waiting 10 seconds before closing the alert, it's an arbitrary time. The basic idea is that it only continues
execution after a call to MediaResource::Destroy().
Using the testcase it only crashes using mp4 files.
Tested with a Nightly build 32bit version:
Name Firefox
Version 53.0a1
Build ID 20161201030205
Actual results:
(910.da0): Access violation - code c0000005 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=e5e5e5e5 ebx=00000001 ecx=8374b9ee edx=00000015 esi=1786c02c edi=176dac40
eip=69fe630a esp=003bf0dc ebp=003bf0f8 iopl=0 nv up ei pl zr na pe nc
cs=0023 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010246
xul!mozilla::BaseMediaResource::ModifyLoadFlags+0x5e:
69fe630a 8b08 mov ecx,dword ptr [eax] ds:002b:e5e5e5e5=????????
69fe630c ff5130 call dword ptr [ecx+30h]
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 media resource was destroyed while a pending load-flags update still held a pointer to it, so the later call read freed memory.
Impact
The browser could crash through a use-after-free, and the freed memory could be reused by a new document, though the report only demonstrates a crash.
What the attacker needed
Victim loads a crafted page; an MP4 video file is served; timing wait for resource destruction
How it was found
- Download the attached MP4 video file.
- Create an iframe whose src points to the MP4 file.
- Remove the iframe nodes and then call document.write in the main window.
- Wait inside an alert or a synchronous XMLHttpRequest until the media resource is destroyed.
- Observe the crash in BaseMediaResource::ModifyLoadFlags.
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 web page loads a video, the browser keeps an object in memory that manages the download. If that object is deleted but some code still tries to use it, the program reads memory that no longer belongs to it, which is called a use-after-free. Here the browser crashed when it tried to use the deleted video object.
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.