Closed Bug 2018103 Opened 9 months ago Closed 9 months ago

YCbCr ColorDepth Mismatch Heap-Buffer-Overflow in SWGL Compositor

Categories

(Core :: Graphics, defect)

defect

Tracking

()

RESOLVED FIXED
150 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr140 149+ fixed
firefox148 --- wontfix
firefox149 + fixed
firefox150 + fixed

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: textureLinearUnpackedR16 in gfx/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:

  1. RenderTextureHostSWGL::UpdatePlanes() selects LOCAL_GL_R16 internal format
  2. wr_swgl_set_texture_buffer() is called with the original byte stride
  3. SWGL's init_sampler() divides the byte stride by bpp=2 to get element stride
  4. The element stride is now stride/2, but the texture width remains unchanged
  5. 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

  1. Content → Parent: PTexture creation with malicious SurfaceDescriptorBuffer
  2. Parent validation: CreateBackendIndependentTextureHost() → ComputeYCbCrBufferSize() → PASSES (doesn't check colorDepth)
  3. Parent compositing: RenderBufferTextureHost::MapPlane() → RenderTextureHostSWGL::UpdatePlanes() → wr_swgl_set_texture_buffer() with R16 format
  4. 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)

I tested that this repros with the patches for bug 2015268 and bug 2014857 applied.

Attached patch exploit.patch — — Splinter Review
Assignee: nobody → jschwartzentruber
Attached file test_colordepth.html —
Attached file crash_stack.txt —

Full log from local repro.

Assignee: jschwartzentruber → nobody

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?

Severity: -- → S2
Flags: needinfo?(mozilla)
Flags: needinfo?(mozilla) → needinfo?(lsalzman)
Attached file (secure) —
Assignee: nobody → lsalzman
Status: NEW → ASSIGNED
Flags: needinfo?(lsalzman)

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):
Attachment #9548074 - Flags: approval-mozilla-esr140?
Attachment #9548074 - Flags: approval-mozilla-beta?
Depends on: CVE-2026-4708
Depends on: 2014857
Depends on: CVE-2026-4710
Group: gfx-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 9 months ago
Resolution: --- → FIXED
Target Milestone: --- → 150 Branch

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?

Flags: needinfo?(lsalzman)

And once it gets review bug 2018113 will want to land on top of this bug and the other dependant bugs listed here.

(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.

Flags: needinfo?(lsalzman)

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.

Attached file (secure) —
Attachment #9549632 - Flags: approval-mozilla-esr140?
Attached file (secure) —

I made patches for 140 and 149 that should uplift without any dependency on Chun-Min's changes.

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)

Attachment #9549638 - Flags: approval-mozilla-beta?
Attachment #9549638 - Flags: approval-mozilla-beta? → approval-mozilla-beta+

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.

Flags: needinfo?(lsalzman)
Attachment #9549638 - Flags: approval-mozilla-beta+ → approval-mozilla-beta-

(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.

Flags: needinfo?(lsalzman)
Flags: needinfo?(pascalc)
Attachment #9549632 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+
Attachment #9548074 - Flags: approval-mozilla-esr140?
Attachment #9548074 - Flags: approval-mozilla-beta?
QA Whiteboard: [sec] [uplift] [qa-triage-done-c150/b149]
Whiteboard: [adv-main149-][adv-ESR140.9-]
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: