OOB Write in CopyPlane within ImageContainer.cpp
An unchecked signed 32-bit width in the CopyPlane function of ImageContainer.cpp can cause an out-of-bounds write when a specially crafted layout sets the width larger than the calculated height. The reporter believes triggering the vulnerable function is very difficult but not impossible, and impact is low.
Originally disclosed on Mozilla
- Fixed in 41 days
- Paid in 2 months
- Disclosed after 41 days
Received a vuln report via email from a friend. I've not confirmed (on paternity leave) but someone should check this. Bug sounds hard to exploit, but reporter want to check with us before blogging about it just in case.
--VIA EMAIL BELOW ------
In the process of creating a full writeup / exploit for the Pwn2Own 2017 bug (https://www.mozilla.org/en-US/security/advisories/mfsa2017-08/) I believe have come across another bug. I am unsure whether the Chaitin team who discovered the Integer Overflow overlooked the vulnerable code, chose to ignore it, reported it alongside their Integer Overflow, or someone else found it subsequently and reported it but I haven't yet found any indication of this being the case.
What's the bug?
The vulnerable function is `CopyPlane` within ImageContainer.cpp (https://searchfox.org/mozilla-central/source/gfx/layers/ImageContainer.cpp#539). The issue here is that the signed 32-bit integer `width` used in the 'Slow Path' of the copy (or when aSkip is anything other than 0) is unchecked. This means that in the case of Firefox 52 a specially crafted Layout can achieve a very simple out of bounds write purely by setting the width value of a layout object to more than the calculated height. (Inside the poc.zip folder I have provided the oobwrite.html file for a simple demonstration of what i mean).
What's the impact?
After a bit of research and scouring through the current Firefox source, I have come to the conclusion that it is _very_ difficult to actually trigger this vulnerable function however it is not impossible. The function `CopyPlane` is referenced only within the `RecyclingPlanarYCbCrImage::CopyData`. The `CopyData` function is then referenced 9 times outside of ImageContainer however, 1 is mitigated by the fact that you removed the overloaded constructor for ImageBitmap objects in Firefox 52. I haven't had a chance to go through and attempt to trigger the bug via the remaining 8 references but i have the suspicion it could be very difficult to trigger from any other code path. For this reason i understand the impact is low but i think it is definitely worth looking at!
I have actually included this out of bounds write within my writeup but - because I realised the bug may not have been reported / discovered prior to now i thought it would be best to let you know and make sure it got fixed or marked as wont-fix before i go and publish the details publicly.
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 signed 32-bit integer width used in the slow path of CopyPlane is not validated, allowing a value larger than the calculated height to cause an out-of-bounds write.
Impact
The reporter states that triggering the vulnerable function is very difficult but not impossible, and therefore the impact is low.
What the attacker needed
Crafted layout with width > height; reach CopyPlane via CopyData
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.
An out-of-bounds write happens when a program writes data past the end of a memory buffer, which can corrupt other data or crash the program. Here, a number representing width is not checked, so a very large width can make the program write outside the intended memory area. The reporter says this is hard to reach in practice, so the risk is considered low.
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.