Bug 572985 (CVE-2010-1214)

Plugin Parameter EnsureCachedAttrParamArrays Remote Code Execution Vulnerability (ZDI-CAN-821)




9 years ago
9 years ago


(Reporter: reed, Assigned: jaas)



Dependency tree / graph
Bug Flags:
in-testsuite ?

Firefox Tracking Flags

(blocking2.0 beta2+, blocking1.9.2 .7+, status1.9.2 .7-fixed, blocking1.9.1 .11+, status1.9.1 .11-fixed)


(Whiteboard: [sg:critical?])


(3 attachments, 3 obsolete attachments)

Created attachment 452201 [details]

ZDI-CAN-821: Mozilla Firefox Plugin Parameter EnsureCachedAttrParamArrays Remote Code Execution Vulnerability

-- ABSTRACT ------------------------------------------------------------

TippingPoint has identified a vulnerability affecting the following 

    Mozilla Firefox 3.6.x

-- VULNERABILITY DETAILS -----------------------------------------------

This vulnerability allows remote attackers to execute arbitrary code on
vulnerable installations of Mozilla Firefox. User interaction is
required to exploit this vulnerability in that the target must visit a
malicious page or open a malicious file.

The specific flaw exists within the browser's method for parsing child
elements out of a particular tag. The application will use a 32-bit
index to enumerate them, but will store it in a 16-bit signed integer
and then use it to allocate space for a cache.  When populating the
cache a buffer overflow will occur. This can lead to code execution
under the context of the application.

The issue occurs within the application's support for parameters within
plugins. The application will create a cache for each parameter value
and name. This is done by enumerating the total number of parameters and
storing it. When calculating the size needed for the cache, the
application will store the total number of results into a signed
integer. This will cause the arithmetic required to undercalculate the
size for the allocation. Later when this cache is populated the buffer
overflow will occur.

After parsing the elements required for a plugin, the application will
enter the following code which will count the number of elements for the
cached Attribute/Param array.

nsresult nsPluginInstanceOwner::EnsureCachedAttrParamArrays()
  if (mCachedAttrParamValues)
    return NS_OK;

  NS_PRECONDITION(((mNumCachedAttrs + mNumCachedParams) == 0) &&
                  "re-cache of attrs/params not implemented! use the DOM
                  "node directy instead");

  // first, we need to find out how much we need to allocate for our
  // arrays count up attributes
  mNumCachedAttrs = 0;

  PRUint32 cattrs = mContent->GetAttrCount();

  if (cattrs < 0x0000FFFF) {
    // unsigned 32 bits to unsigned 16 bits conversion
    mNumCachedAttrs = static_cast<PRUint16>(cattrs);
  } else {
    mNumCachedAttrs = 0xFFFE;  // minus one in case we add an extra
"src" entry below

  // now, we need to find all the PARAM tags that are children of us
  // however, be carefull NOT to include any PARAMs that don't have us
  // as a direct parent. For nested object (or applet) tags, be sure
  // to only round up the param tags that coorespond with THIS
  // instance. And also, weed out any bogus tags that may get in the
  // way, see bug 39609. Then, with any param tag that meet our
  // qualification, temporarly cache them in an nsCOMArray until
  // we can figure out what size to make our fixed char* array.

  mNumCachedParams = 0;

After counting the number of elements, this will be assigned to a 16-bit
integer and then used in an allocation.

  if (allParams) {
    PRUint32 numAllParams; 
    // loop through every so called dependent PARAM tag to check if it
    // "belongs" to us

    for (PRUint32 i = 0; i < numAllParams; i++) {
      nsCOMPtr<nsIDOMNode> pnode;
      allParams->Item(i, getter_AddRefs(pnode));

      nsCOMPtr<nsIDOMElement> domelement = do_QueryInterface(pnode);
      if (domelement) {
            nsCOMPtr<nsIDOMNode> mydomNode =
            if (parent == mydomNode) {

  // We're done with DOM method calls now; make sure we still have a

  PRUint32 cparams = ourParams.Count(); // unsigned 32 bits to unsigned
16 bits conversion
  if (cparams < 0x0000FFFF)
    mNumCachedParams = static_cast<PRUint16>(cparams);
    mNumCachedParams = 0xFFFF;


  PRInt16 numRealAttrs = mNumCachedAttrs;           // XXX: implied type
conversion from unsigned to signed
  nsAutoString data;
  if (mContent->Tag() == nsGkAtoms::object
    && !mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::src)
    && mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::data, data)) {

  // now lets make the arrays
  mCachedAttrParamNames  = (char **)PR_Calloc(sizeof(char *) *
(mNumCachedAttrs + 1 + mNumCachedParams), 1);            // XXX: signed
integer being used in an allocation
  mCachedAttrParamValues = (char **)PR_Calloc(sizeof(char *) *
(mNumCachedAttrs + 1 + mNumCachedParams), 1);            // XXX: signed
integer being used in an allocation

The following code will then populate the allocated memory with the
cache. This will overflow the underallocated buffer that was provided.

  // Some plugins (eg Flash, see bug 234675.) are actually sensitive to
  // attribute order.  So we want to make sure we give the plugin the
  // attributes in the order they came in in the source, to be
compatible with
  // other browsers.  Now in HTML, the storage order is the reverse of
  // source order, while in XML and XHTML it's the same as the source
  // (see the AddAttributes functions in the HTML and XML content
  PRInt16 start, end, increment;
  if (mContent->IsNodeOfType(nsINode::eHTML) &&
      mContent->NodeInfo()->NamespaceEquals(kNameSpaceID_None)) {
    // HTML.  Walk attributes in reverse order.
    start = numRealAttrs - 1;
    end = -1;
    increment = -1;
  } else {
    // XHTML or XML.  Walk attributes in forward order.
    start = 0;
    end = numRealAttrs;
    increment = 1;
  for (PRInt16 index = start; index != end; index += increment) {
    const nsAttrName* attrName = mContent->GetAttrNameAt(index);
    nsIAtom* atom = attrName->LocalName();
    nsAutoString value;
    mContent->GetAttr(attrName->NamespaceID(), atom, value);
    nsAutoString name;

    FixUpURLS(name, value);

    mCachedAttrParamNames [c] = ToNewUTF8String(name);
    mCachedAttrParamValues[c] = ToNewUTF8String(value);

Version(s)  tested: Mozilla Firefox 3.6.3
Platform(s) tested: Windows XP SP3

-- CREDIT --------------------------------------------------------------

This vulnerability was discovered by:
    * J23 (http://twitter.com/HansJ23)

Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.3a6pre) Gecko/20100617 Minefield/3.7a6pre
blocking1.9.2: ? → needed
status1.9.2: ? → wanted
roc: can you find an owner for this one?
Assignee: nobody → roc
I think Josh should own this
Assignee: roc → joshmoz

Comment 4

9 years ago
Created attachment 452967 [details] [diff] [review]
trunk fix v1.0


9 years ago
Attachment #452967 - Attachment description: fix v1.0 → trunk fix v1.0

Comment 5

9 years ago
Created attachment 452979 [details] [diff] [review]
trunk fix v1.1
Attachment #452967 - Attachment is obsolete: true
Attachment #452979 - Flags: review?(jst)

Comment 6

9 years ago
Created attachment 452982 [details] [diff] [review]
1.9.2 fix v1.0

This is a minimal backport of the fix to the 1.9.2 branch. However, a browser fix might not be enough. This patch fixes the crash in the browser's code but then the JEP goes down - looks like it also has a bug. JEP is used on the 1.9.2 branch but not trunk. Will ask Steven Michaud to look into it, we may have to include an updated JEP.
Attachment #452982 - Flags: review?(jst)

Comment 7

9 years ago
Comment on attachment 452979 [details] [diff] [review]
trunk fix v1.1

Patch has a problem, new one coming up.
Attachment #452979 - Attachment is obsolete: true
Attachment #452979 - Flags: review?(jst)


9 years ago
Attachment #452982 - Attachment is obsolete: true
Attachment #452982 - Flags: review?(jst)
Yup.  You forgot to reset nextAttrParamIndex to 0 before

+  for (PRUint16 i = 0; i < mNumCachedParams; i++) {
+    nsIDOMElement* param = ourParams.ObjectAt(i);
+    if (!param) {
+      continue;

I'll wait for your new patch.
(I assume the problem I found is also the one you found.)
Oops, scratch comment #8 -- I was wrong.

Comment 11

9 years ago
Created attachment 453092 [details] [diff] [review]
trunk fix v1.2
Attachment #453092 - Flags: review?(jst)

Comment 12

9 years ago
Created attachment 453093 [details] [diff] [review]
1.9.2 fix v1.1

This updated patch for 1.9.2 fixes the JEP crash as well.
Attachment #453093 - Flags: review?(jst)
> This updated patch for 1.9.2 fixes the JEP crash as well.

Thanks.  Glad to hear it!

Comment 14

9 years ago
Created attachment 453150 [details] [diff] [review]
1.9.1 fix v1.0
Attachment #453150 - Flags: review?(jst)
Attachment #453092 - Flags: review?(jst) → review+
Attachment #453093 - Flags: review?(jst) → review+
Is 1.9.1 actually vulnerable here?

Comment 16

9 years ago
1.9.1 is vulnerable, at least to a crash. The patch I posted fixes the problem.
blocking1.9.1: ? → needed
status1.9.1: ? → wanted

Comment 17

9 years ago
pushed to mozilla-central



9 years ago
blocking2.0: ? → beta2+
Attachment #453150 - Flags: review?(jst) → review+
FIXED on mozilla-central. We use the status1.9.1/status1.9.2 fields for branch resolution.
Last Resolved: 9 years ago
Resolution: --- → FIXED
"in-testsuite?" as a reminder to create/add the crash test once we've shipped this on the branches.
Flags: in-testsuite?
blocking1.9.1: needed → .11+
blocking1.9.2: needed → .6+
Attachment #453093 - Flags: approval1.9.2.6+
Comment on attachment 453093 [details] [diff] [review]
1.9.2 fix v1.1

Approved for, a=dveditz for release-drivers
Comment on attachment 453150 [details] [diff] [review]
1.9.1 fix v1.0

Approved for, a=dveditz for release-drivers
Attachment #453150 - Flags: approval1.9.1.11+

Comment 22

9 years ago
pushed to mozilla-1.9.2

status1.9.2: wanted → .6-fixed

Comment 23

9 years ago
pushed to mozilla-1.9.1

status1.9.1: wanted → .11-fixed
On 1.9.1 and 1.9.2, I'm not seeing new behavior post-fix. I'm also not seeing a crash pre-fix.

On or with the PoC, the browser doesn't crash but goes up to 98-100% CPU usage and hangs there for a few minutes. Eventually, the CPU usage goes back to normal. With and build 1, I'm seeming the same behavior. This is on Windows XP. 

What am I missing in order to see the crash?
Alias: CVE-2010-1214

Comment 25

9 years ago
Al - can you test on Mac OS X? I was able to reproduce on 1.9.1, 1.9.2, and 1.9.3 on Mac OS X.
Comment on attachment 453150 [details] [diff] [review]
1.9.1 fix v1.0

Requesting approval1.9.0.next on this patch so that we can take it in upcoming Camino 2.0.x security and stability updates.  If approved, I'll handle the checkins, unless the patch author requests otherwise.
Attachment #453150 - Flags: approval1.9.0.next?


9 years ago
Depends on: 580874
This caused regression bug 580874, I wouldn't take it on 1.9.0.next without the followup fix I'm going to attach there shortly.


9 years ago
status2.0: ? → ---

Comment 28

9 years ago
I don't think this caused bug 580874, bug 575836 is the cause and that is a different than this (though in the same area of code).


9 years ago
No longer depends on: 580874


9 years ago
Depends on: 575836
Comment on attachment 453150 [details] [diff] [review]
1.9.1 fix v1.0

Approved for, a=dveditz
Attachment #453150 - Flags: approval1.9.0.next? → approval1.9.0.next+
Checking in layout/generic/nsObjectFrame.cpp;
/cvsroot/mozilla/layout/generic/nsObjectFrame.cpp,v  <--  nsObjectFrame.cpp
new revision: 1.660; previous revision: 1.659
Keywords: fixed1.9.0.20
Group: core-security
You need to log in before you can comment on or make changes to this bug.