Closed Bug 1134131 Opened 9 years ago Closed 9 years ago

Type confusion with <picture> and <source> elements

Categories

(Core :: DOM: Core & HTML, defect)

x86_64
Windows 8.1
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla38
Tracking Status
firefox35 --- disabled
firefox36 --- wontfix
firefox37 + disabled
firefox38 + fixed
firefox-esr31 --- unaffected
b2g-v1.4 --- unaffected
b2g-v2.0 --- unaffected
b2g-v2.0M --- unaffected
b2g-v2.1 --- disabled
b2g-v2.1S --- disabled
b2g-v2.2 --- disabled
b2g-master --- fixed

People

(Reporter: nils, Assigned: longsonr)

References

Details

(Keywords: sec-critical)

Attachments

(3 files)

Attached file testcase
The following code in HTMLImageElement::TryCreateResponsiveSelector is vulnerable to a type confusion issue:

  bool isSourceTag = aSourceNode->Tag() == nsGkAtoms::source;
  if (isSourceTag) {
    DebugOnly<nsINode *> parent(nsINode::GetParentNode());
    MOZ_ASSERT(parent && parent->Tag() == nsGkAtoms::picture);
    MOZ_ASSERT(IsPreviousSibling(aSourceNode, this));
    MOZ_ASSERT(pictureEnabled);

    // Check media and type
    HTMLSourceElement *src = static_cast<HTMLSourceElement*>(aSourceNode);
    if (!src->MatchesCurrentMedia()) {
      return false;
    }

The code only checks whether aSourceNode has the tag name "source" without validating the namespace. The attached testcase demonstrates the issues.
Attached file ASAN output on crash
Attached patch Possible fix?Splinter Review
Comment on attachment 8565890 [details] [diff] [review]
Possible fix?

Are you able to test whether this patch fixes the vulnerability?
Attachment #8565890 - Flags: feedback?(nils)
Assignee: nobody → longsonr
I can confirm that the testcase doesn't crash in an ASAN build with the patch applied.
Attachment #8565890 - Flags: review?(jst)
[Tracking Requested - why for this release]: Security bug.

This affects 33 and later; we may want to backport this to aurora/beta...
Blocks: picture
Comment on attachment 8565890 [details] [diff] [review]
Possible fix?

Looks good, r=jst
Attachment #8565890 - Flags: review?(jst) → review+
Comment on attachment 8565890 [details] [diff] [review]
Possible fix?

[Security approval request comment]
How easily could an exploit be constructed based on the patch? You'd know you needed to create something using a picture tag in a non-html namespace but not exactly how to do that.
Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem? no.

Which older supported branches are affected by this flaw? Firefox 33 onwards preffed off, only preffed on in Firefox 38

If not all supported branches, which bug introduced the flaw? bug 870022, bug 1017875 turned the pref on.

Do you have backports for the affected branches? If not, how different, hard to create, and risky will they be? I think the patch will apply to all branches. 

How likely is this patch to cause regressions; how much testing does it need? The ASAN test has been rerun on it and no longer fails. This whole area could do with more tests but that seems to be bug 1017878 as far as I can tell.
Attachment #8565890 - Flags: sec-approval?
This needs a security rating before it can be approved. It isn't clear to me what the effects of this are on the end use and the risks. Is the crash exploitable? ASAN calls it a heap-buffer-overflow but it does that a lot.
Flags: sec-bounty?
I would suspect this is exploitable. The type confusion results in a heap buffer overflow. By confusing an Element (smaller) type object with a HTMLSourceElement (larger) object we end up reading past the original object, reading a pointer which might be controlled by an attacker. Looking at the crash in windbg suggests an exploitable condition as well:

5758e15c 8b4314          mov     eax,dword ptr [ebx+14h] ds:002b:5a5a5a6e=????????

An object pointer is read from freed memory, the code then continues working with this bogus object pointer.
Comment on attachment 8565890 [details] [diff] [review]
Possible fix?

sec-approval+ for trunk checkin.
Attachment #8565890 - Flags: sec-approval? → sec-approval+
Blocks: 1134280
https://hg.mozilla.org/mozilla-central/rev/67ea8244ccf3
Status: NEW → RESOLVED
Closed: 9 years ago
Flags: in-testsuite?
Resolution: --- → FIXED
Target Milestone: --- → mozilla38
Comment on attachment 8565890 [details] [diff] [review]
Possible fix?

Review of attachment 8565890 [details] [diff] [review]:
-----------------------------------------------------------------

Feedback already given in previous comment.
Attachment #8565890 - Flags: feedback?(nils)
Flags: sec-bounty? → sec-bounty+
Group: core-security → core-security-release
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: