Bug 806031 (CVE-2013-0748)

[FIX] XBL.__proto__.toString is ugly and reveals address space layout

RESOLVED FIXED in Firefox 18

Status

()

Core
XBL
RESOLVED FIXED
5 years ago
4 years ago

People

(Reporter: Jesse Ruderman, Assigned: smaug)

Tracking

(Blocks: 1 bug, {sec-high, testcase})

Trunk
mozilla20
x86_64
Mac OS X
sec-high, testcase
Points:
---
Bug Flags:
in-testsuite ?

Firefox Tracking Flags

(firefox17 wontfix, firefox18+ fixed, firefox19+ fixed, firefox20+ fixed, firefox-esr1018+ fixed, firefox-esr1718+ fixed, b2g18 fixed)

Details

(Whiteboard: [adv-main18+][adv-esr17+][adv-esr10+])

Attachments

(4 attachments, 1 obsolete attachment)

(Reporter)

Description

5 years ago
Created attachment 675776 [details]
testcase

Got:
[object chrome://xbl-marquee/content/xbl-marquee.xml#marquee a646314]

Expected in opt, don't reveal address space info:
[object chrome://xbl-marquee/content/xbl-marquee.xml#marquee]

Expected in debug, format it properly:
[object chrome://xbl-marquee/content/xbl-marquee.xml#marquee @ 0x0a646314]

I can't find the code that's doing this.  But here's an example of code doing it right:
http://mxr.mozilla.org/mozilla-central/source/js/xpconnect/src/XPCWrappedNativeJSOps.cpp#74
(Reporter)

Updated

5 years ago
Blocks: 806034
The relevant code is nsXBLBinding::DoInitJSClass which does:

1372       // We need to create a unique classname based on aClassName and
1373       // parent_proto.  Append a space (an invalid URI character) to ensure that
1374       // we don't have accidental collisions with the case when parent_proto is
1375       // null and aClassName ends in some bizarre numbers (yeah, it's unlikely).
1376       jsid parent_proto_id;
1377       if (!::JS_GetObjectId(cx, parent_proto, &parent_proto_id)) {
1378         // Probably OOM
1379         return NS_ERROR_OUT_OF_MEMORY;
1380       }
1381 
1382       // One space, maybe "0x", at most 16 chars (on a 64-bit system) of long,
1383       // and a null-terminator (which PR_snprintf ensures is there even if the
1384       // string representation of what we're printing does not fit in the buffer
1385       // provided).
1386       char buf[20];
1387       PR_snprintf(buf, sizeof(buf), " %lx", parent_proto_id);
1388       className.Append(buf);

and then uses that as the .name of the JSClass, so it gets picked up by toString.

JS_GetObjectId seems to use the object pointer. :(
What we really want is a fast one-way hash of the parent_proto_id... ;)
(Reporter)

Comment 3

5 years ago
(In reply to Boris Zbarsky (:bz) from comment #2)
> What we really want is a fast one-way hash of the parent_proto_id... ;)

Does the result of the hash need to be guaranteed unique?
I suspect so, yes.  At least on a per-window basis...

But we have a hashtable with those strings as keys (which is why they need to be unique).  We could just do a lookup after hashing and if we get a hit iterate the hash, no?
What we did for the XSLT generate-id() function (which also needs to generate per-document unique identifiers) is that we simply output

((uintptr_t)node) - ((uintptr_t)node->GetOwnerDoc->GetWindow())

Would that work here?
Hmm.  This hashtable is cross-window, but there might be no real hits in it across windows because the protos would be different...

Looking at this more, we might be able to just not store this string the JSClass .name at all, and put it directly on nsXBLJSClass instead.
Can someone suggest a security rating for this issue?
(Reporter)

Comment 8

5 years ago
Hi Al. dveditz and I have been arguing in about that (e.g. in bug 806034).
Well, I'll mark this sec-high, and somebody can change it if they want.
Keywords: sec-high
(Assignee)

Comment 10

5 years ago
IMO sec-high should be assigned to someone. Taking.
Assignee: nobody → bugs
(Assignee)

Comment 11

4 years ago
So to keep the old behavior as much as possible, couldn't we store
binding name + 64bit id as class name, and store the current binding name + parent_proto_id
in nsXBLService::gClassTable.

I think also comment 6 hints about that.
(Assignee)

Comment 12

4 years ago
Created attachment 690347 [details] [diff] [review]
minimal patch?

To not reveal address space, reveal only an id.
Boris, what do you think of this conservative approach?
nsXBLBinding::DoInitJSClass could certainly be cleaned up a bit, but
I tried to keep the changes minimal. I explicitly decided to not have any
special classname for DEBUG.

Also, as far as I see PR_snprintf usage is currently wrong on 64bit.
Attachment #690347 - Flags: review?(bzbarsky)
(Assignee)

Comment 13

4 years ago
oh, fun. Static assert fires on 32bit.
(Assignee)

Comment 14

4 years ago
Ah, silly me. that assertion is just wrong.
(Assignee)

Comment 15

4 years ago
Created attachment 690354 [details] [diff] [review]
less silly assert
Attachment #690347 - Attachment is obsolete: true
Attachment #690347 - Flags: review?(bzbarsky)
Attachment #690354 - Flags: review?(bzbarsky)
Comment on attachment 690354 [details] [diff] [review]
less silly assert

r=me
Attachment #690354 - Flags: review?(bzbarsky) → review+
(Assignee)

Comment 17

4 years ago
Comment on attachment 690354 [details] [diff] [review]
less silly assert

[Security approval request comment]
How easily can the security issue be deduced from the patch? The issue perhaps easily, but it isn't
a security problem without having some other security bug.

Do comments in the patch, the check-in comment, or tests included in the patch paint a bulls-eye on the security problem? Not really. The comment will about having better toString for XBL classes.

Which older supported branches are affected by this flaw?
All

Do you have backports for the affected branches? If not, how different, hard to create, and risky will they be?
The patch should apply to all the branches with some minor merging. The code is _old_.

How likely is this patch to cause regressions; how much testing does it need?
I tried to take the most conservative approach - I don't expect regressions.
Attachment #690354 - Flags: sec-approval?
(Assignee)

Updated

4 years ago
Summary: XBL.__proto__.toString is ugly and reveals address space layout → [FIX] XBL.__proto__.toString is ugly and reveals address space layout
Attachment #690354 - Flags: sec-approval? → sec-approval+
status-firefox-esr10: --- → affected
status-firefox17: --- → affected
status-firefox18: --- → affected
status-firefox19: --- → affected
status-firefox20: --- → affected
status-firefox-esr17: --- → affected
tracking-firefox-esr10: --- → ?
tracking-firefox18: --- → ?
tracking-firefox19: --- → ?
tracking-firefox20: --- → ?
tracking-firefox-esr17: --- → ?
(Assignee)

Comment 18

4 years ago
https://hg.mozilla.org/mozilla-central/rev/718145f0d606
Status: NEW → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
(Assignee)

Comment 19

4 years ago
Comment on attachment 690354 [details] [diff] [review]
less silly assert

[Approval Request Comment]
Bug caused by (feature/regressing bug #): No bug, but XBL class sharing from year 2000
User impact if declined: See bug 806034
Testing completed (on m-c, etc.): just landed m-c 
Risk to taking this patch (and alternatives if risky): Shouldn't be too risky
String or UUID changes made by this patch: NA
Attachment #690354 - Flags: approval-mozilla-beta?
Attachment #690354 - Flags: approval-mozilla-aurora?

Updated

4 years ago
tracking-firefox-esr10: ? → 18+
tracking-firefox18: ? → +
tracking-firefox19: ? → +
tracking-firefox20: ? → +
tracking-firefox-esr17: ? → 18+
Comment on attachment 690354 [details] [diff] [review]
less silly assert

This will first land in beta 5, which should be manageable.
Attachment #690354 - Flags: approval-mozilla-beta?
Attachment #690354 - Flags: approval-mozilla-beta+
Attachment #690354 - Flags: approval-mozilla-aurora?
Attachment #690354 - Flags: approval-mozilla-aurora+
(Assignee)

Comment 21

4 years ago
Created attachment 692532 [details] [diff] [review]
esr17


See https://wiki.mozilla.org/Release_Management/ESR_Landing_Process for more info.
Attachment #692532 - Flags: approval-mozilla-esr17?
(Assignee)

Updated

4 years ago
status-firefox20: affected → fixed
Comment on attachment 692532 [details] [diff] [review]
esr17

approving for uplift to go along with ff18 (please land once this is also uplifted to mozilla-beta).
Attachment #692532 - Flags: approval-mozilla-esr17? → approval-mozilla-esr17+
Comment on attachment 690354 [details] [diff] [review]
less silly assert

Since this didn't make it into beta 5, we'll review the necessity of the fix for this internally reported bug during tomorrow's security triage.
Attachment #690354 - Flags: approval-mozilla-beta?
Attachment #690354 - Flags: approval-mozilla-beta+
Attachment #690354 - Flags: approval-mozilla-aurora?
Attachment #690354 - Flags: approval-mozilla-aurora+

Updated

4 years ago
Attachment #692532 - Flags: approval-mozilla-esr17+ → approval-mozilla-esr17?
Alex, I'd already landed this on all the branches and mid-aired with you updating the bug. How would you like me to proceed?

https://hg.mozilla.org/releases/mozilla-aurora/rev/e65cdbf38911
https://hg.mozilla.org/releases/mozilla-beta/rev/82e323659c9d
https://hg.mozilla.org/releases/mozilla-esr17/rev/f579c9a6d8f2
status-firefox17: affected → wontfix
status-firefox18: affected → fixed
status-firefox19: affected → fixed
status-firefox-esr17: affected → fixed
Flags: in-testsuite?
Target Milestone: --- → mozilla20
Comment on attachment 690354 [details] [diff] [review]
less silly assert

We'll leave this one in the build, given the fact that it's low risk and is exposed on pre-release branches. Fingers crossed :)
Attachment #690354 - Flags: approval-mozilla-beta?
Attachment #690354 - Flags: approval-mozilla-beta+
Attachment #690354 - Flags: approval-mozilla-aurora?
Attachment #690354 - Flags: approval-mozilla-aurora+

Updated

4 years ago
Attachment #692532 - Flags: approval-mozilla-esr17? → approval-mozilla-esr17+
We still need a patch for ESR10 here. Olli?
(Assignee)

Comment 27

4 years ago
Uh, I can't keep track on my security bugs :/
I'll write esr10 patch tomorrow.
(Assignee)

Comment 28

4 years ago
Created attachment 694801 [details] [diff] [review]
esr10

I was told try may not work too well with esr10 anymore, so crossing fingers.
The only changes to esr17 patch are merging + one nullptr -> nsnull.
Attachment #694801 - Flags: approval-mozilla-esr10?
https://hg.mozilla.org/releases/mozilla-b2g18/rev/82e323659c9d
status-b2g18: --- → fixed

Updated

4 years ago
Attachment #694801 - Flags: approval-mozilla-esr10? → approval-mozilla-esr10+
(Assignee)

Comment 30

4 years ago
https://hg.mozilla.org/releases/mozilla-esr10/rev/02cd40b93741
status-firefox-esr10: affected → fixed
Whiteboard: [adv-main18+][adv-esr17+][adv-esr10+]
Alias: CVE-2013-0748
Group: core-security
You need to log in before you can comment on or make changes to this bug.