Bad cast in nsImageGeometryMixin
A bad cast in nsImageGeometryMixin caused a heap-buffer-overflow when a display item's geometry was accessed. An attacker could trigger a crash by loading a crafted page and pressing Tab.
Originally disclosed on Mozilla
- Fixed in 5 days
- Paid in 19 days
- Disclosed after 5 days
Created attachment 8784672
Testcase
1. Load testcase and press Tab to trigger.
2. Looks like a bad cast / type confusion issue.
auto lastGeometry =
static_cast<T*>(mozilla::FrameLayerBuilder::GetMostRecentGeometry(aItem));
if (lastGeometry) {
mLastDrawResult = lastGeometry->mLastDrawResult; // crashing here.
==6679==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60b0004e5028 at pc 0x7f0c222bbb93 bp 0x7fffba9ec040 sp 0x7fffba9ec038
READ of size 1 at 0x60b0004e5028 thread T0 (Web Content)
#0 0x7f0c222bbb92 in nsImageGeometryMixin layout/base/nsDisplayListInvalidation.h:101:39
#1 0x7f0c222bbb92 in nsDisplayItemGenericImageGeometry layout/base/nsDisplayListInvalidation.h:163
#2 0x7f0c222bbb92 in nsDisplayRangeFocusRing::AllocateGeometry(nsDisplayListBuilder*) layout/forms/nsRangeFrame.cpp:202
#3 0x7f0c21c3d579 in mozilla::FrameLayerBuilder::ComputeGeometryChangeForItem(mozilla::FrameLayerBuilder::DisplayItemData*) layout/base/FrameLayerBuilder.cpp:4366:22
#4 0x7f0c21c3c5ce in mozilla::FrameLayerBuilder::WillEndTransaction() layout/base/FrameLayerBuilder.cpp:1901:7
#5 0x7f0c21dcbc5f in nsDisplayList::PaintRoot(nsDisplayListBuilder*, nsRenderingContext*, unsigned int) layout/base/nsDisplayList.cpp:1894:17
#6 0x7f0c21e7cd99 in nsLayoutUtils::PaintFrame(nsRenderingContext*, nsIFrame*, nsRegion const&, unsigned int, nsDisplayListBuilderMode, nsLayoutUtils::PaintFrameFlags) layout/base/nsLayoutUtils.cpp:3603:10
#7 0x7f0c21f05989 in PresShell::Paint(nsView*, nsRegion const&, unsigned int) layout/base/nsPresShell.cpp:6640:5
#8 0x7f0c214bda0c in nsViewManager::ProcessPendingUpdatesPaint(nsIWidget*) view/nsViewManager.cpp:484:19
#9 0x7f0c214bc6ae in nsViewManager::ProcessPendingUpdatesForView(nsView*, bool) view/nsViewManager.cpp:415:33
#10 0x7f0c214c051d in nsViewManager::ProcessPendingUpdates() view/nsViewManager.cpp:1118:5
#11 0x7f0c21bf3b99 in nsRefreshDriver::Tick(long, mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:1898:9
#12 0x7f0c21bfeccd in TickDriver layout/base/nsRefreshDriver.cpp:275:13
#13 0x7f0c21bfeccd in mozilla::RefreshDriverTimer::TickRefreshDrivers(long, mozilla::TimeStamp, nsTArray<RefPtr<nsRefreshDriver> >&) layout/base/nsRefreshDriver.cpp:247
#14 0x7f0c21bfe929 in mozilla::RefreshDriverTimer::Tick(long, mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:266:5
#15 0x7f0c21c00934 in mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::NotifyVsync(mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:426:9
#16 0x7f0c2259ae74 in mozilla::layout::VsyncChild::RecvNotify(mozilla::TimeStamp const&) layout/ipc/VsyncChild.cpp:64:16
#17 0x7f0c1be65f39 in mozilla::layout::PVsyncChild::OnMessageReceived(IPC::Message const&) objdir-ff-asan/ipc/ipdl/PVsyncChild.cpp:240:20
#18 0x7f0c1b8b1151 in mozilla::ipc::PBackgroundChild::OnMessageReceived(IPC::Message const&) objdir-ff-asan/ipc/ipdl/PBackgroundChild.cpp:2048:28
#19 0x7f0c1b7da134 in mozilla::ipc::MessageChannel::DispatchAsyncMessage(IPC::Message const&) ipc/glue/MessageChannel.cpp:1662:25
#20 0x7f0c1b7d68f7 in mozilla::ipc::MessageChannel::DispatchMessage(IPC::Message&&) ipc/glue/MessageChannel.cpp:1600:17
#21 0x7f0c1b7c3bff in mozilla::ipc::MessageChannel::OnMaybeDequeueOne() ipc/glue/MessageChannel.cpp:1567:5
#22 0x7f0c1b7f4a62 in applyImpl<mozilla::ipc::MessageChannel, bool (mozilla::ipc::MessageChannel::*)()> objdir-ff-asan/dist/include/nsThreadUtils.h:729:12
#23 0x7f0c1b7f4a62 in apply<mozilla::ipc::MessageChannel, bool (mozilla::ipc::MessageChannel::*)()> objdir-ff-asan/dist/include/nsThreadUtils.h:735
#24 0x7f0c1b7f4a62 in mozilla::detail::RunnableMethodImpl<bool (mozilla::ipc::MessageChannel::*)(), false, true>::Run() objdir-ff-asan/dist/include/nsThreadUtils.h:764
#25 0x7f0c1b7f42ef in Run objdir-ff-asan/dist/include/mozilla/ipc/MessageChannel.h:545:29
#26 0x7f0c1b7f42ef in mozilla::ipc::MessageChannel::DequeueTask::Run() objdir-ff-asan/dist/include/mozilla/ipc/MessageChannel.h:564
#27 0x7f0c1aa15a1e in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1058:14
#28 0x7f0c1aa965e8 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/glue/nsThreadUtils.cpp:290:10
#29 0x7f0c1b7e17a1 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) ipc/glue/MessagePump.cpp:96:21
#30 0x7f0c1b754ad0 in RunInternal ipc/chromium/src/base/message_loop.cc:232:10
#31 0x7f0c1b754ad0 in RunHandler ipc/chromium/src/base/message_loop.cc:225
#32 0x7f0c1b754ad0 in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:205
#33 0x7f0c2153565f in nsBaseAppShell::Run() widget/nsBaseAppShell.cpp:156:27
#34 0x7f0c236e7697 in XRE_RunAppShell toolkit/xre/nsEmbedFunctions.cpp:846:22
#35 0x7f0c1b754ad0 in RunInternal ipc/chromium/src/base/message_loop.cc:232:10
#36 0x7f0c1b754ad0 in RunHandler ipc/chromium/src/base/message_loop.cc:225
#37 0x7f0c1b754ad0 in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:205
#38 0x7f0c236e6d58 in XRE_InitChildProcess toolkit/xre/nsEmbedFunctions.cpp:676:34
#39 0x511ab3 in content_process_main ipc/contentproc/plugin-container.cpp:197:19
#40 0x511ab3 in main browser/app/nsBrowserApp.cpp:369
#41 0x7f0c348e9f44 in __libc_start_main /build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:287
0x60b0004e5028 is located 0 bytes to the right of 40-byte region [0x60b0004e5000,0x60b0004e5028)
allocated by thread T0 (Web Content) here:
#0 0x4d5cc8 in malloc _asan_rtl_
#1 0x51296d in moz_xmalloc memory/mozalloc/mozalloc.cpp:110:17
#2 0x7f0c21f3009e in operator new objdir-ff-asan/dist/include/mozilla/mozalloc.h:193:12
#3 0x7f0c21f3009e in nsDisplayItem::AllocateGeometry(nsDisplayListBuilder*) layout/base/nsDisplayList.h:1484
#4 0x7f0c21c3d579 in mozilla::FrameLayerBuilder::ComputeGeometryChangeForItem(mozilla::FrameLayerBuilder::DisplayItemData*) layout/base/FrameLayerBuilder.cpp:4366:22
#5 0x7f0c21c3c5ce in mozilla::FrameLayerBuilder::WillEndTransaction() layout/base/FrameLayerBuilder.cpp:1901:7
#6 0x7f0c21dcbc5f in nsDisplayList::PaintRoot(nsDisplayListBuilder*, nsRenderingContext*, unsigned int) layout/base/nsDisplayList.cpp:1894:17
#7 0x7f0c21e7cd99 in nsLayoutUtils::PaintFrame(nsRenderingContext*, nsIFrame*, nsRegion const&, unsigned int, nsDisplayListBuilderMode, nsLayoutUtils::PaintFrameFlags) layout/base/nsLayoutUtils.cpp:3603:10
#8 0x7f0c21f05989 in PresShell::Paint(nsView*, nsRegion const&, unsigned int) layout/base/nsPresShell.cpp:6640:5
#9 0x7f0c214bda0c in nsViewManager::ProcessPendingUpdatesPaint(nsIWidget*) view/nsViewManager.cpp:484:19
#10 0x7f0c214bc6ae in nsViewManager::ProcessPendingUpdatesForView(nsView*, bool) view/nsViewManager.cpp:415:33
#11 0x7f0c214c051d in nsViewManager::ProcessPendingUpdates() view/nsViewManager.cpp:1118:5
#12 0x7f0c21bf3b99 in nsRefreshDriver::Tick(long, mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:1898:9
#13 0x7f0c21bfeccd in TickDriver layout/base/nsRefreshDriver.cpp:275:13
#14 0x7f0c21bfeccd in mozilla::RefreshDriverTimer::TickRefreshDrivers(long, mozilla::TimeStamp, nsTArray<RefPtr<nsRefreshDriver> >&) layout/base/nsRefreshDriver.cpp:247
#15 0x7f0c21bfe929 in mozilla::RefreshDriverTimer::Tick(long, mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:266:5
#16 0x7f0c21c00934 in mozilla::VsyncRefreshDriverTimer::RefreshDriverVsyncObserver::NotifyVsync(mozilla::TimeStamp) layout/base/nsRefreshDriver.cpp:426:9
#17 0x7f0c2259ae74 in mozilla::layout::VsyncChild::RecvNotify(mozilla::TimeStamp const&) layout/ipc/VsyncChild.cpp:64:16
#18 0x7f0c1be65f39 in mozilla::layout::PVsyncChild::OnMessageReceived(IPC::Message const&) objdir-ff-asan/ipc/ipdl/PVsyncChild.cpp:240:20
#19 0x7f0c1b8b1151 in mozilla::ipc::PBackgroundChild::OnMessageReceived(IPC::Message const&) objdir-ff-asan/ipc/ipdl/PBackgroundChild.cpp:2048:28
#20 0x7f0c1b7da134 in mozilla::ipc::MessageChannel::DispatchAsyncMessage(IPC::Message const&) ipc/glue/MessageChannel.cpp:1662:25
#21 0x7f0c1b7d68f7 in mozilla::ipc::MessageChannel::DispatchMessage(IPC::Message&&) ipc/glue/MessageChannel.cpp:1600:17
#22 0x7f0c1b7c3bff in mozilla::ipc::MessageChannel::OnMaybeDequeueOne() ipc/glue/MessageChannel.cpp:1567:5
#23 0x7f0c1b7f4a62 in applyImpl<mozilla::ipc::MessageChannel, bool (mozilla::ipc::MessageChannel::*)()> objdir-ff-asan/dist/include/nsThreadUtils.h:729:12
#24 0x7f0c1b7f4a62 in apply<mozilla::ipc::MessageChannel, bool (mozilla::ipc::MessageChannel::*)()> objdir-ff-asan/dist/include/nsThreadUtils.h:735
#25 0x7f0c1b7f4a62 in mozilla::detail::RunnableMethodImpl<bool (mozilla::ipc::MessageChannel::*)(), false, true>::Run() objdir-ff-asan/dist/include/nsThreadUtils.h:764
#26 0x7f0c1b7f42ef in Run objdir-ff-asan/dist/include/mozilla/ipc/MessageChannel.h:545:29
#27 0x7f0c1b7f42ef in mozilla::ipc::MessageChannel::DequeueTask::Run() objdir-ff-asan/dist/include/mozilla/ipc/MessageChannel.h:564
#28 0x7f0c1aa15a1e in nsThread::ProcessNextEvent(bool, bool*) xpcom/threads/nsThread.cpp:1058:14
#29 0x7f0c1aa965e8 in NS_ProcessNextEvent(nsIThread*, bool) xpcom/glue/nsThreadUtils.cpp:290:10
#30 0x7f0c1b7e17a1 in mozilla::ipc::MessagePump::Run(base::MessagePump::Delegate*) ipc/glue/MessagePump.cpp:96:21
#31 0x7f0c1b754ad0 in RunInternal ipc/chromium/src/base/message_loop.cc:232:10
#32 0x7f0c1b754ad0 in RunHandler ipc/chromium/src/base/message_loop.cc:225
#33 0x7f0c1b754ad0 in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:205
#34 0x7f0c2153565f in nsBaseAppShell::Run() widget/nsBaseAppShell.cpp:156:27
#35 0x7f0c236e7697 in XRE_RunAppShell toolkit/xre/nsEmbedFunctions.cpp:846:22
#36 0x7f0c1b754ad0 in RunInternal ipc/chromium/src/base/message_loop.cc:232:10
#37 0x7f0c1b754ad0 in RunHandler ipc/chromium/src/base/message_loop.cc:225
#38 0x7f0c1b754ad0 in MessageLoop::Run() ipc/chromium/src/base/message_loop.cc:205
SUMMARY: AddressSanitizer: heap-buffer-overflow (/mnt/scratch0/clusterfuzz/slave-bot/builds/linux_asan_firefox/custom/firefox/libxul.so+0x9805b92)
Shadow bytes around the buggy address:
0x0c16800949b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fd fd
0x0c16800949c0: fd fd fd fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c16800949d0: fa fa fa fa 00 00 00 00 00 00 fa fa fa fa fa fa
0x0c16800949e0: fa fa fa fa fa fa fa fa fa fa 00 00 00 00 00 fa
0x0c16800949f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c1680094a00: 00 00 00 00 00[fa]fa fa fa fa fa fa fa fa fa fa
0x0c1680094a10: fa fa fa fa fa fa 00 00 00 00 00 fa fa fa fa fa
0x0c1680094a20: fa fa fa fa fa fa fa fa fa fa fa fa fd fd fd fd
0x0c1680094a30: fd fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c1680094a40: fa fa fd fd fd fd fd fa fa fa fa fa fa fa fa fa
0x0c1680094a50: fa fa fa fa fa fa fa fa fd fd fd fd fd fa fa fa
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
==6679==ABORTING
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 a static_cast to the wrong display item type, so the code reads a field that does not exist in the actual object.
Impact
A crafted page could crash the browser tab (heap-buffer-overflow), but the text does not show code execution.
What the attacker needed
Victim loads a crafted page; victim presses Tab
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.
This is a memory safety bug in Firefox's layout engine. A type confusion means the code treats one kind of object as another, so it reads past the end of a buffer and crashes the browser tab.
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.