Stack-buffer-overflow in mozilla::StyleAnimationValue::GetScaleValue
A crafted HTML file triggers a stack-buffer-overflow read in Firefox's style animation code when an image's size becomes available during layout. The crash occurs because the code reads past a stack variable while checking whether a scale transform is animated.
Originally disclosed on Mozilla
- Fixed in 15 days
- Paid in 28 days
- Disclosed after 15 days
Created attachment 8830420 repro-file.html
Tested on:
OS: Ubuntu 16.04
Firefox: ASAN build from https://index.taskcluster.net/v1/task/gecko.v2.mozilla-central.latest.firefox.linux64-asan-opt/artifacts/public/build/target.tar.bz2 sourcestamp: c989c7b352279925edf138373e4ca3f1540dbd5f
ASAN-trace:
==28958==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffc72fa1918 at pc 0x7fef22f240af bp 0x7ffc72fa14b0 sp 0x7ffc72fa14a8 READ of size 8 at 0x7ffc72fa1918 thread T0 #0 0x7fef22f240ae in mozilla::StyleAnimationValue::GetScaleValue(nsIFrame const*) const /home/worker/workspace/build/src/layout/style/StyleAnimationValue.cpp:4828:33 #1 0x7fef23b0c37a in ContainsAnimatedScale /home/worker/workspace/build/src/layout/painting/ActiveLayerTracker.cpp:491:24 #2 0x7fef23b0c37a in mozilla::ActiveLayerTracker::IsScaleSubjectToAnimation(nsIFrame*) /home/worker/workspace/build/src/layout/painting/ActiveLayerTracker.cpp:518 #3 0x7fef2336fd75 in GetTransformToAncestorExcludingAnimated /home/worker/workspace/build/src/layout/base/nsLayoutUtils.cpp:2676:7 #4 0x7fef2336fd75 in nsLayoutUtils::GetTransformToAncestorScaleExcludingAnimated(nsIFrame*) /home/worker/workspace/build/src/layout/base/nsLayoutUtils.cpp:2695 #5 0x7fef235ef332 in nsImageFrame::MaybeDecodeForPredictedSize() /home/worker/workspace/build/src/layout/generic/nsImageFrame.cpp:729:7 #6 0x7fef235ee283 in nsImageFrame::OnSizeAvailable(imgIRequest*, imgIContainer*) /home/worker/workspace/build/src/layout/generic/nsImageFrame.cpp:587:7 #7 0x7fef235ed952 in nsImageFrame::Notify(imgIRequest*, int, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const*) /home/worker/workspace/build/src/layout/generic/nsImageFrame.cpp:503:12 #8 0x7fef1f0462b0 in nsImageLoadingContent::Notify(imgIRequest*, int, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const*) /home/worker/workspace/build/src/dom/base/nsImageLoadingContent.cpp:157:9 #9 0x7fef1ed586be in imgRequestProxy::Notify(int, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const*) /home/worker/workspace/build/src/image/imgRequestProxy.cpp:808:3 #10 0x7fef1ed103db in operator() /home/worker/workspace/build/src/image/ProgressTracker.cpp:320:42 #11 0x7fef1ed103db in void mozilla::image::ImageObserverNotifier<mozilla::image::ObserverTable const*>::operator()<void mozilla::image::SyncNotifyInternal<mozilla::image::ObserverTable const*>(mozilla::image::ObserverTable const* const&, bool, unsigned int, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const&)::{lambda(mozilla::image::IProgressObserver*)#1}>(void mozilla::image::SyncNotifyInternal<mozilla::image::ObserverTable const*>(mozilla::image::ObserverTable const* const&, bool, unsigned int, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const&)::{lambda(mozilla::image::IProgressObserver*)#1}) /home/worker/workspace/build/src/image/ProgressTracker.cpp:279 #12 0x7fef1ed10020 in void mozilla::image::SyncNotifyInternal<mozilla::image::ObserverTable const*>(mozilla::image::ObserverTable const* const&, bool, unsigned int, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const&) /home/worker/workspace/build/src/image/ProgressTracker.cpp:320:5 #13 0x7fef1ed0ba93 in operator() /home/worker/workspace/build/src/image/ProgressTracker.cpp:399:5 #14 0x7fef1ed0ba93 in Read<(lambda at /home/worker/workspace/build/src/image/ProgressTracker.cpp:398:19)> /home/worker/workspace/build/src/image/CopyOnWrite.h:154 #15 0x7fef1ed0ba93 in mozilla::image::ProgressTracker::SyncNotifyProgress(unsigned int, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const&) /home/worker/workspace/build/src/image/ProgressTracker.cpp:398 #16 0x7fef1ed14fc7 in mozilla::image::RasterImage::NotifyProgress(unsigned int, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const&, mozilla::Maybe<unsigned int> const&, mozilla::image::DecoderFlags, mozilla::image::SurfaceFlags) /home/worker/workspace/build/src/image/RasterImage.cpp:1597:3 #17 0x7fef1ed1f888 in mozilla::image::RasterImage::NotifyDecodeComplete(mozilla::image::DecoderFinalStatus const&, mozilla::image::ImageMetadata const&, mozilla::image::DecoderTelemetry const&, unsigned int, mozilla::gfx::IntRectTypedmozilla::gfx::UnknownUnits const&, mozilla::Maybe<unsigned int> const&, mozilla::image::DecoderFlags, mozilla::image::SurfaceFlags) /home/worker/workspace/build/src/image/RasterImage.cpp:1637:3 #18 0x7fef1ed942d9 in operator() /home/worker/workspace/build/src/image/IDecodingTask.cpp:87:5 #19 0x7fef1ed942d9 in mozilla::detail::RunnableFunction<mozilla::image::IDecodingTask::NotifyDecodeComplete(mozilla::NotNullmozilla::image::RasterImage*, mozilla::NotNullmozilla::image::Decoder*)::$_2>::Run() /home/worker/workspace/build/src/xpcom/threads/nsThreadUtils.h:314 #20 0x7fef1c937e8b in nsThread::ProcessNextEvent(bool, bool*) /home/worker/workspace/build/src/xpcom/threads/nsThread.cpp:1261:7 #21 0x7fef1c9347e0 in NS_ProcessNextEvent(nsIThread*, bool) /home/worker/workspace/build/src/xpcom/threads/nsThreadUtils.cpp:394:10 #22 0x7fef1d73eb0f in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) /home/worker/workspace/build/src/ipc/glue/MessagePump.cpp:96:21 #23 0x7fef1d6b0d98 in RunInternal /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:238:3 #24 0x7fef1d6b0d98 in RunHandler /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:231 #25 0x7fef1d6b0d98 in MessageLoop::Run() /home/worker/workspace/build/src/ipc/chromium/src/base/message_loop.cc:211 #26 0x7fef22b0707f in nsBaseAppShell::Run() /home/worker/workspace/build/src/widget/nsBaseAppShell.cpp:156:3 #27 0x7fef24b3e991 in nsAppStartup::Run() /home/worker/workspace/build/src/toolkit/components/startup/nsAppStartup.cpp:283:19 #28 0x7fef24cf91ac in XREMain::XRE_mainRun() /home/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4461:10 #29 0x7fef24cfacf1 in XREMain::XRE_main(int, char**, mozilla::BootstrapConfig const&) /home/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4638:8 #30 0x7fef24cfbfcc in XRE_main(int, char**, mozilla::BootstrapConfig const&) /home/worker/workspace/build/src/toolkit/xre/nsAppRunner.cpp:4729:16 #31 0x4df705 in do_main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:234:10 #32 0x4df705 in main /home/worker/workspace/build/src/browser/app/nsBrowserApp.cpp:305 #33 0x7fef37d1c82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f) #34 0x41ba58 in _start (/home/attekett/Downloads/firefox/firefox+0x41ba58)
Address 0x7ffc72fa1918 is located in stack of thread T0 at offset 600 in frame #0 0x7fef23b0bb1f in mozilla::ActiveLayerTracker::IsScaleSubjectToAnimation(nsIFrame*) /home/worker/workspace/build/src/layout/painting/ActiveLayerTracker.cpp:508
This frame has 5 object(s): [32, 80) '' [112, 160) '' [192, 256) '__begin.i' [288, 352) '__end.i' [384, 592) 'segment.i' <== Memory access at offset 600 overflows this variable HINT: this may be a false positive if your program uses some custom stack unwind mechanism or swapcontext (longjmp and C++ exceptions are supported) SUMMARY: AddressSanitizer: stack-buffer-overflow /home/worker/workspace/build/src/layout/style/StyleAnimationValue.cpp:4828:33 in mozilla::StyleAnimationValue::GetScaleValue(nsIFrame const*) const Shadow bytes around the buggy address: . . .
On debug-build:
[28901] ###!!! ASSERTION: uninitialized: 'mUnit != eUnit_Null', file /home/worker/workspace/build/src/obj-firefox/dist/include/mozilla/StyleAnimationValue.h, line 369 Assertion failure: GetUnit() == StyleAnimationValue::eUnit_Transform, at /home/worker/workspace/build/src/layout/style/StyleAnimationValue.cpp:4819
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 code assumes the animation value has a transform unit and reads a scale value from a stack object that is not actually a transform, causing an out-of-bounds read.
Impact
A crafted page could crash the browser through an out-of-bounds stack read, and the bug may be exploitable for code execution.
What the attacker needed
Victim opens a crafted HTML page; ASAN or debug build to observe the crash
How it was found
- Open the attached repro-file.html in an ASAN build of Firefox.
- The page loads an image whose size becomes available during layout.
- The image frame asks for the predicted size and walks the transform chain.
- The animation tracker checks whether scale is animated and reads past a stack variable.
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 web browser stores some temporary data on a small area of memory called the stack. This report shows that a specially made web page can make Firefox read past the end of that area, which is a memory safety bug. The result is a crash, and in some cases such bugs can be turned into code execution.
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.