Bug 590771 (CVE-2010-3766)

nsDOMAttribute MutationObserver Remote Code Execution Vulnerability (ZDI-CAN-898)

RESOLVED FIXED

Status

()

Core
DOM: Core & HTML
--
critical
RESOLVED FIXED
7 years ago
4 years ago

People

(Reporter: reed, Assigned: mounir)

Tracking

(4 keywords)

unspecified
crash, testcase, verified1.9.1, verified1.9.2
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(blocking2.0 betaN+, blocking1.9.2 .13+, status1.9.2 .13-fixed, blocking1.9.1 .16+, status1.9.1 .16-fixed)

Details

(Whiteboard: [sg:critical?])

Attachments

(5 attachments)

(Reporter)

Description

7 years ago
Created attachment 469260 [details]
PoC

ZDI-CAN-898: Mozilla Firefox nsDOMAttribute MutationObserver Remote Code Execution Vulnerability

-- CVSS ----------------------------------------------------------------
10, (AV:N/AC:L/Au:N/C:C/I:C/A:C)

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

TippingPoint has identified a vulnerability affecting the following 
products:

    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 application's support of an API used
for element traversal. Due to a particular element not implementing
functionality required by the API, a use-after free vulnerability can be
made to occur. This can be used to achieve code execution under the
context of the application.

The issue occurs within the application's support of the NodeIterator
API that is used for DOM Traversal as outlined in the DOM specification
on w3.org. 

In order to support the node iteration, the application needs to keep
track of modifications to the dom tree in order to update the state of
the iterator. This is done explicitly by a pair of methods called
AddMutationObserver/RemoveMutationObserver. Anytime an element is
created, the observer list will be updated so that a node iterator can
adjust for modified elements.

When adding an element, it will need to update the MutationObserver list
as in the following code.

content/base/src/nsNodeIterator.cpp:185
nsNodeIterator::nsNodeIterator(nsINode *aRoot,
                               PRUint32 aWhatToShow,
                               nsIDOMNodeFilter *aFilter,
                               PRBool aExpandEntityReferences) :
    nsTraversal(aRoot, aWhatToShow, aFilter, aExpandEntityReferences),
    mDetached(PR_FALSE),
    mPointer(mRoot, PR_TRUE)
{
    aRoot->AddMutationObserver(this);         // XXX
}

nsNodeIterator::~nsNodeIterator()
{
    /* destructor code */
    if (!mDetached && mRoot)
        mRoot->RemoveMutationObserver(this);    // XXX
}

AddMutationObserver/RemoveMutationObserver will add the provided element
to a page-global list that can be queried by the NodeIterator.

content/base/src/nsGenericElement.cpp:295
void
nsINode::AddMutationObserver(nsIMutationObserver* aMutationObserver)
{
  nsSlots* slots = GetSlots();
  if (slots) {
   
slots->mMutationObservers.AppendElementUnlessExists(aMutationObserver);
  }
}

void
nsINode::RemoveMutationObserver(nsIMutationObserver* aMutationObserver)
{
  nsSlots* slots = GetExistingSlots();
  if (slots) {
    slots->mMutationObservers.RemoveElement(aMutationObserver);
  }
}

One element however does not update the mutation list. This is the
nsDOMAttribute and is defined in content/base/src/nsDOMAttribute.cpp.
This will allow someone to manipulate the nsDOMAttribute node without
the nsNodeIterator api being informed. This will bypass the type-safety
of the compiler and can lead to code execution.

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

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

This vulnerability was discovered by:
    * regenrecht
I get a js error on trunk:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMAttr.removeChild]"  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"  location: "JS frame :: https://bug590771.bugzilla.mozilla.org/attachment.cgi?id=469260&t=BcPe7a6cgh :: run :: line 11"  data: no]

On Firefox3.6.8, I get an alert saying "[object Text]".
Mounir will investigate.
Assignee: nobody → mounir.lamouri
(Assignee)

Comment 3

7 years ago
I believe this has been fixed on trunk with bug 540848 with the following changesets:
http://hg.mozilla.org/mozilla-central/rev/068150b06d11
http://hg.mozilla.org/mozilla-central/rev/13571a9165ea
Status: NEW → ASSIGNED
(Assignee)

Comment 4

7 years ago
Forget comment 3, this is not related actually.

Very likely, this is fixed on trunk because of a regression of bug 566416. I filed bug 598877 about the regression. Quickly, attributes.firstChild returns null in the test case with the current trunk which is wrong and make the script fail too early.
This bug expected, this is not fixed on trunk apparently.
(Assignee)

Comment 5

7 years ago
Created attachment 478909 [details] [diff] [review]
Tests for 1.9.1 and 1.9.2
Attachment #478909 - Flags: review?(jonas)
(Assignee)

Comment 6

7 years ago
Created attachment 478910 [details] [diff] [review]
Patch for 1.9.1 and 1.9.2 [checked-in]
Attachment #478910 - Flags: review?(jonas)
(Assignee)

Updated

7 years ago
Attachment #478910 - Flags: approval1.9.2.11?
Comment on attachment 478910 [details] [diff] [review]
Patch for 1.9.1 and 1.9.2 [checked-in]

Please get reviews before asking for branch approval
Attachment #478910 - Flags: approval1.9.2.11?
Does this affect 1.9.1? If not, do we know what bug introduced the flaw?
blocking1.9.1: --- → ?
blocking1.9.2: --- → needed
status1.9.1: --- → ?
status1.9.2: --- → wanted
(Assignee)

Comment 9

7 years ago
(In reply to comment #8)
> Does this affect 1.9.1? If not, do we know what bug introduced the flaw?

I'm building 1.9.1 to check that.
Asking for 2.0 blocking considering this is affecting the trunk too.
blocking2.0: --- → ?
status2.0: --- → ?
(Assignee)

Comment 10

7 years ago
(In reply to comment #8)
> Does this affect 1.9.1? If not, do we know what bug introduced the flaw?

1.9.1 is also affected. The same patch applies and work.
(Assignee)

Updated

7 years ago
Attachment #478909 - Attachment description: Tests for 1.9.2 → Tests for 1.9.1 and 1.9.2
(Assignee)

Updated

7 years ago
Attachment #478910 - Attachment description: Patch for 1.9.2 → Patch for 1.9.1 and 1.9.2
Do we need a different trunk patch after the regression is fixed?

Updated

7 years ago
blocking2.0: ? → betaN+
(Assignee)

Comment 12

7 years ago
(In reply to comment #11)
> Do we need a different trunk patch after the regression is fixed?

Yes. The code has changed so the current patch will not fix the issue on trunk.
Comment on attachment 478910 [details] [diff] [review]
Patch for 1.9.1 and 1.9.2 [checked-in]

Add a comment to the declaration of AttributeChildRemoved that says that attributes never have more than 1 children and so this is always that one single child that is removed.

>diff --git a/content/base/src/nsNodeIterator.cpp b/content/base/src/nsNodeIterator.cpp
>--- a/content/base/src/nsNodeIterator.cpp
>+++ b/content/base/src/nsNodeIterator.cpp
>@@ -212,17 +212,17 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_END
> NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsNodeIterator)
>   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRoot)
>   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFilter)
> NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
> 
> // QueryInterface implementation for nsNodeIterator
> NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsNodeIterator)
>     NS_INTERFACE_MAP_ENTRY(nsIDOMNodeIterator)
>-    NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
>+    NS_INTERFACE_MAP_ENTRY(nsIMutationObserver2)
>     NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMNodeIterator)
>     NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(NodeIterator)
> NS_INTERFACE_MAP_END

You need to keep both interfaces in the interface map. We still want QIing to nsIMutationObserver to work.


>+nsNodeUtils::AttributeChildRemoved(nsINode* aAttribute,
>+                                   nsIContent* aChild)
>+{
>+  NS_PRECONDITION(aAttribute->IsNodeOfType(nsINode::eATTRIBUTE),
>+                  "container must be a nsIAttribute");
>+
>+  // This is a variant of IMPL_MUTATION_NOTIFICATION.

Add a comment to IMPL_MUTATION_NOTIFICATION so that if someone modifies that, this code is modified too.

r=me with those changes.
Attachment #478910 - Flags: review?(jonas) → review+
Attachment #478909 - Flags: review?(jonas) → review+
(Assignee)

Comment 14

7 years ago
Shouldn't this be blocking 1.9.1 too?
blocking1.9.1: ? → needed
status1.9.1: ? → wanted
(Assignee)

Updated

7 years ago
Attachment #478909 - Flags: approval1.9.2.11?
Attachment #478909 - Flags: approval1.9.1.14?
(Assignee)

Updated

7 years ago
Attachment #478910 - Flags: approval1.9.2.11?
Attachment #478910 - Flags: approval1.9.1.14?
(Assignee)

Updated

7 years ago
Attachment #478909 - Flags: approval1.9.2.11?
Attachment #478909 - Flags: approval1.9.1.14?
(Assignee)

Updated

7 years ago
Attachment #478910 - Flags: approval1.9.2.11?
Attachment #478910 - Flags: approval1.9.1.14?
(Assignee)

Comment 15

7 years ago
Removing approval requests given that I've been told on IRC that this shouldn't land for this release.
(Assignee)

Comment 16

7 years ago
(In reply to comment #15)
> Removing approval requests given that I've been told on IRC that this shouldn't
> land for this release.

1.9.1 and 1.9.2 branches.
(Assignee)

Comment 17

7 years ago
Created attachment 479331 [details] [diff] [review]
Tests for trunk
Attachment #479331 - Flags: review?(jonas)
(Assignee)

Comment 18

7 years ago
Created attachment 479332 [details] [diff] [review]
Patch for trunk [checked-in]
Attachment #479332 - Flags: review?(jonas)
(Assignee)

Comment 19

7 years ago
I actually found a few regressions from bug 566416 and my patch for trunk is built on top of them, so I'm marking them as dependencies.
Depends on: 598877, 600466, 600468, 600471
Attachment #479331 - Flags: review?(jonas) → review+
Attachment #479332 - Flags: review?(jonas) → review+
blocking1.9.1: needed → ?
blocking1.9.2: needed → ?
(Assignee)

Comment 20

7 years ago
Comment on attachment 479332 [details] [diff] [review]
Patch for trunk [checked-in]

Patch pushed on mozilla-central:
http://hg.mozilla.org/mozilla-central/rev/56403a9ae8b6
Attachment #479332 - Attachment description: Patch for trunk → Patch for trunk [checked-in]
Should this be marked FIXED?

If not, what remains to do?
(Assignee)

Comment 22

7 years ago
Patches should be pushed on branches (according to branch rules, I have to wait a few days before asking for an approval and it's not really urgent). In addition, I think that tests will have to be pushed after branch releases.
blocking1.9.1: ? → .15+
blocking1.9.2: ? → .12+
(Assignee)

Comment 23

7 years ago
Pushed in 1.9.1 and 1.9.2:
http://hg.mozilla.org/releases/mozilla-1.9.1/rev/bcfb355e5c2b
http://hg.mozilla.org/releases/mozilla-1.9.2/rev/dc30f8b144a9

I will push all tests after 1.9.1 and 1.9.2 branching.
status1.9.1: wanted → .15-fixed
status1.9.2: wanted → .12-fixed
(Assignee)

Updated

7 years ago
Attachment #478910 - Attachment description: Patch for 1.9.1 and 1.9.2 → Patch for 1.9.1 and 1.9.2 [checked-in]
(Reporter)

Comment 24

7 years ago
Fixed on trunk == RESOLVED FIXED. Branches are tracked separately.
Status: ASSIGNED → RESOLVED
Last Resolved: 7 years ago
Resolution: --- → FIXED
(Reporter)

Comment 25

7 years ago
(In reply to comment #22)
> Patches should be pushed on branches (according to branch rules, I have to wait
> a few days before asking for an approval and it's not really urgent). In
> addition, I think that tests will have to be pushed after branch releases.

(In reply to comment #23)
> Pushed in 1.9.1 and 1.9.2:
> http://hg.mozilla.org/releases/mozilla-1.9.1/rev/bcfb355e5c2b
> http://hg.mozilla.org/releases/mozilla-1.9.2/rev/dc30f8b144a9

What happened to the "asking for an approval" thing? *all* branch patches require approval before landing.

> I will push all tests after 1.9.1 and 1.9.2 branching.

No, wait until after the release has been made before landing tests.
(Reporter)

Updated

7 years ago
Attachment #478910 - Flags: approval1.9.2.13?
Attachment #478910 - Flags: approval1.9.1.16?
(Assignee)

Comment 26

7 years ago
> (In reply to comment #23)
> > Pushed in 1.9.1 and 1.9.2:
> > http://hg.mozilla.org/releases/mozilla-1.9.1/rev/bcfb355e5c2b
> > http://hg.mozilla.org/releases/mozilla-1.9.2/rev/dc30f8b144a9
> 
> What happened to the "asking for an approval" thing? *all* branch patches
> require approval before landing.

It has been marked as 'blocking'. Isn't that enough?

> > I will push all tests after 1.9.1 and 1.9.2 branching.
> 
> No, wait until after the release has been made before landing tests.

That's what I meant.
No, the approval policy for released branches is different than the one for under-development branches. For released branches all patches require approval, regardless of blocking status.
Note that eventually Firefox 4 will end up in that state -- think of the branches as perpetual "Release Candidate" stage. Rules for each tree are always on their tinderboxen, and they differ. Please check.
Comment on attachment 478910 [details] [diff] [review]
Patch for 1.9.1 and 1.9.2 [checked-in]

retroactive approval for 1.9.2.13 and 1.9.1.16, a=dveditz for release-drivers
Attachment #478910 - Flags: approval1.9.2.13?
Attachment #478910 - Flags: approval1.9.2.13+
Attachment #478910 - Flags: approval1.9.1.16?
Attachment #478910 - Flags: approval1.9.1.16+
Alias: ZDI-CAN-898
(Reporter)

Updated

7 years ago
Alias: ZDI-CAN-898
Alias: CVE-2010-3766
Verified fixed for 1.9.2 with Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13pre) Gecko/20101117 Namoroka/3.6.13pre and for 1.9.1 with Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.16pre) Gecko/20101117 Shiretoko/3.5.16pre using PoC.
Keywords: verified1.9.1, verified1.9.2
(Assignee)

Comment 31

7 years ago
Tests pushed on trunk:
http://hg.mozilla.org/mozilla-central/rev/be885fbb66c2
(Assignee)

Comment 32

7 years ago
Tests pushed in 1.9.1 and 1.9.2 branches:
http://hg.mozilla.org/releases/mozilla-1.9.1/rev/d1f3e4b9a9d9
http://hg.mozilla.org/releases/mozilla-1.9.2/rev/9e561d402701
(Assignee)

Updated

7 years ago
Flags: in-testsuite+

Updated

7 years ago
status2.0: ? → ---
Group: core-security
Depends on: 708198
Component: DOM: Traversal-Range → DOM: Core & HTML
Product: Core → Core
You need to log in before you can comment on or make changes to this bug.