YCbCr ColorDepth Mismatch Heap-Buffer-Overflow in SWGL Compositor
Categories
(Core :: Graphics, defect)
Tracking
()
People
(Reporter: truber, Assigned: lsalzman)
References
(Regression)
Details
(4 keywords, Whiteboard: [adv-main149-][adv-ESR140.9-])
Attachments
(4 files, 3 external files)
Vulnerability Analysis: YCbCr ColorDepth Mismatch Heap-Buffer-Overflow in SWGL Compositor
Bug Information
- Component: PTexture IPC Protocol / SWGL Software Compositor
- Crash Function:
textureLinearUnpackedR16ingfx/wr/swgl/src/texture.h:680 - Vulnerability Type: CWE-122 Heap-Based Buffer Overflow (Out-of-Bounds Read)
- Exploitable: Yes — attacker-controlled OOB read in parent process from compromised content process
Summary
A compromised content process can send a malicious SurfaceDescriptorBuffer containing a YCbCrDescriptor with colorDepth=COLOR_16 but strides sized for 8-bit data. The parent process's buffer size validation (ComputeYCbCrBufferSize) does not account for colorDepth, so it accepts the descriptor as valid. When the SWGL software compositor processes the texture using R16 format (2 bytes per pixel), it interprets the byte stride as a uint16_t element stride by dividing by 2, causing the sampler to read beyond the allocated shmem boundary.
Root Cause
The function ImageDataSerializer::ComputeYCbCrBufferSize() in gfx/layers/ImageDataSerializer.cpp computes the required buffer size based solely on stride * height for each plane, without considering the colorDepth field. For COLOR_8, this is correct since each sample is 1 byte. For COLOR_16, each sample is 2 bytes, so the stride must be at least width * 2 bytes per row. However, the validation only checks that stride >= width (implicitly, via AllowedSurfaceSize), not stride >= width * bytesPerPixel(colorDepth).
When SWGL processes a YUV420 texture with COLOR_16:
RenderTextureHostSWGL::UpdatePlanes()selectsLOCAL_GL_R16internal formatwr_swgl_set_texture_buffer()is called with the original byte stride- SWGL's
init_sampler()divides the byte stride bybpp=2to get element stride - The element stride is now
stride/2, but the texture width remains unchanged - For pixels where
x > stride/2, the access wraps into the next row and eventually past the buffer end
Detailed Exploitation
Attack Setup
- Content process creates a 96×64 BGRA canvas (shmem = 24576 bytes)
- Intercepts
ShmemTextureData::Serialize()to replace the RGB descriptor with:- YCbCr descriptor: ySize=128×128, yStride=128, cbCrSize=64×64, cbCrStride=64
- colorDepth=COLOR_16, chromaSubsampling=HALF_WIDTH_AND_HEIGHT
- Total claimed 8-bit size: 128×128 + 2×64×64 = 24576 bytes (matches shmem)
OOB Calculation
For the Cr plane (starts at offset 20480, 4096 bytes long):
- SWGL sampler: width=64, height=64, byte_stride=64, bpp=2
- Element stride = 64/2 = 32 (uint16_t elements)
- Pixel (63, 63):
uint16_t[63 + 63*32]=uint16_t[2079]→ byte offset 4158 - Cr plane has only 4096 bytes → 62 bytes past end of Cr plane
- Absolute: 20480 + 4158 = 24638 > 24576 shmem → 62 bytes past shmem boundary
Impact
- Information Disclosure: Reading 62+ bytes of heap data beyond the allocated shmem, which could contain sensitive data from other allocations
- Potential Code Execution: If combined with heap grooming, the attacker could leak heap metadata or adjacent object pointers to defeat ASLR, enabling further exploitation
- Sandbox Escape Vector: This is triggered from a compromised content process against the parent (browser) process via PTexture IPC
Affected Code Path
- Content → Parent:
PTexturecreation with maliciousSurfaceDescriptorBuffer - Parent validation:
CreateBackendIndependentTextureHost()→ComputeYCbCrBufferSize()→ PASSES (doesn't check colorDepth) - Parent compositing:
RenderBufferTextureHost::MapPlane()→RenderTextureHostSWGL::UpdatePlanes()→wr_swgl_set_texture_buffer()with R16 format - SWGL render thread:
textureLinearUnpackedR16()→ OOB READ
Proposed Fix
ComputeYCbCrBufferSize should validate that strides are sufficient for the given colorDepth. Specifically:
int32_t bpp = gfx::BytesPerPixel(SurfaceFormatForColorDepth(aColorDepth));
if (aYStride < aYSize.width * bpp || aCbCrStride < aCbCrSize.width * bpp) {
return 0;
}
Alternatively, RenderBufferTextureHost::MapPlane() could validate stride vs width × bytesPerPixel before passing data to SWGL.
Distinction from Known Bug
The previously known vulnerability (display rect > ySize mismatch) crashes in linearRowTapsR8 at composite.h:785 in the 8-bit texture sampling path. This new vulnerability crashes in textureLinearUnpackedR16 at texture.h:680 in the 16-bit texture sampling path. The root causes are completely independent:
- Known bug: display rect dimensions exceed actual plane dimensions → fix: validate display ≤ ySize
- This bug: stride insufficient for colorDepth → fix: validate stride ≥ width × bytesPerPixel(colorDepth)
| Reporter | ||
Comment 1•9 months ago
|
||
I tested that this repros with the patches for bug 2015268 and bug 2014857 applied.
| Reporter | ||
Comment 2•9 months ago
|
||
| Reporter | ||
Comment 3•9 months ago
|
||
| Reporter | ||
Comment 4•9 months ago
|
||
| Reporter | ||
Comment 5•9 months ago
|
||
Full log from local repro.
| Reporter | ||
Updated•9 months ago
|
Comment 6•9 months ago
|
||
Tentatively classifying as S2; I don't know enough about this code to fully validate that this is a problem. :gw, could you please take a look?
Updated•9 months ago
|
Updated•9 months ago
|
| Assignee | ||
Comment 7•9 months ago
|
||
Updated•9 months ago
|
| Assignee | ||
Updated•9 months ago
|
| Assignee | ||
Updated•9 months ago
|
| Assignee | ||
Comment 8•9 months ago
|
||
Comment on attachment 9548074 [details]
(secure)
Beta/Release Uplift Approval Request
- User impact if declined/Reason for urgency: Possible buffer overflow in parent/GPU process.
- Is this code covered by automated tests?: Unknown
- Has the fix been verified in Nightly?: Yes
- Needs manual test from QE?: No
- If yes, steps to reproduce:
- List of other uplifts needed: None
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky): Adds some extra stride validation checks.
- String changes made/needed:
- Is Android affected?: Yes
ESR Uplift Approval Request
- If this is not a sec:{high,crit} bug, please state case for ESR consideration:
- User impact if declined:
- Fix Landed on Version: 150
- Risk to taking this patch: Low
- Why is the change risky/not risky? (and alternatives if risky):
| Assignee | ||
Updated•9 months ago
|
| Assignee | ||
Updated•9 months ago
|
| Assignee | ||
Updated•9 months ago
|
Comment 10•9 months ago
|
||
Updated•9 months ago
|
Comment 11•9 months ago
|
||
Lee, the uplift request says "List of other uplifts needed: None" but this bug depends on 3 other security bugs that don't have uplift requests. I am guessing that they should all land in a stack when the uplift requests are added?
Comment 12•9 months ago
|
||
And once it gets review bug 2018113 will want to land on top of this bug and the other dependant bugs listed here.
| Assignee | ||
Comment 13•9 months ago
|
||
(In reply to Pascal Chevrel:pascalc from comment #11)
Lee, the uplift request says "List of other uplifts needed: None" but this bug depends on 3 other security bugs that don't have uplift requests. I am guessing that they should all land in a stack when the uplift requests are added?
Yes, the other deps unfortunately are required to land this.
Comment 14•8 months ago
|
||
In those other bugs the assignee said they are not going to seek uplift. So I guess we should uplift this bug plus bug 2018113 and fix the conflicts. Doing that plus uplifting bug 2014857 should cover all of the problems in this group of bugs.
| Assignee | ||
Comment 15•8 months ago
|
||
Updated•8 months ago
|
| Assignee | ||
Comment 16•8 months ago
|
||
| Assignee | ||
Comment 17•8 months ago
|
||
I made patches for 140 and 149 that should uplift without any dependency on Chun-Min's changes.
Comment 18•8 months ago
|
||
A patch has been attached on this bug, which was already closed. Filing a separate bug will ensure better tracking. If this was not by mistake and further action is needed, please alert the appropriate party. (Or: if the patch doesn't change behavior -- e.g. landing a test case, or fixing a typo -- then feel free to disregard this message)
| Assignee | ||
Updated•8 months ago
|
Updated•8 months ago
|
Comment 19•8 months ago
|
||
Comment on attachment 9549638 [details]
(secure)
The patch does not apply to the beta branch, note that we did uplift to beta (only) one of the dependencies, bug 2014857.
| Assignee | ||
Comment 20•8 months ago
|
||
(In reply to Pascal Chevrel:pascalc from comment #19)
Comment on attachment 9549638 [details]
(secure)The patch does not apply to the beta branch, note that we did uplift to beta (only) one of the dependencies, bug 2014857.
I have updated the patch to account for yet more uplifts that seem to have subversively snuck in before this. It will apply now.
This patch is necessary for tnikkel's work in dependent bug 2018113 to get uplifted later.
| Assignee | ||
Updated•8 months ago
|
Comment 21•8 months ago
|
||
| uplift | ||
Updated•8 months ago
|
Updated•8 months ago
|
Updated•8 months ago
|
Comment 22•8 months ago
|
||
| uplift | ||
Updated•8 months ago
|
Updated•8 months ago
|
Updated•8 months ago
|
Updated•4 months ago
|
Description
•