Closed Bug 569162 Opened 10 years ago Closed 10 years ago

GC hazard with lookupProperty callers with scripted proxy handlers


(Core :: JavaScript Engine, defect)

Other Branch
Not set



Tracking Status
status2.0 --- unaffected
blocking1.9.2 --- .13+
status1.9.2 --- .13-fixed
blocking1.9.1 --- .16+
status1.9.1 --- .16-fixed


(Reporter: gal, Assigned: igor)



(Whiteboard: [sg:critical?][ccbr][critsmash:patch][stale][1.9.x branches])


(1 file, 1 obsolete file)

lookupProperty and other object ops calls might not root obj.
Attached patch patch (obsolete) — Splinter Review
Assignee: general → gal
Attachment #448307 - Flags: review?(brendan)
Blocks: 568465
No longer depends on: 568465
Proxies didn't exist in 192 and 191, so no need to block.
blocking1.9.2: ? → ---
status1.9.1: ? → ---
Comment on attachment 448307 [details] [diff] [review]

>diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp
>--- a/js/src/jsproxy.cpp
>+++ b/js/src/jsproxy.cpp
>@@ -513,40 +513,43 @@ ReturnedValueMustNotBePrimitive(JSContex
>     return true;
> }
> bool
> JSScriptedProxyHandler::getPropertyDescriptor(JSContext *cx, JSObject *proxy, jsid id,
>                                               JSPropertyDescriptor *desc)
> {
>     JSObject *handler = JSVAL_TO_OBJECT(proxy->getProxyHandler());
>+    AutoObjectRooter objr(cx, proxy);
>     AutoValueRooter tvr(cx);
>     return FundamentalTrap(cx, handler, ATOM(getPropertyDescriptor), tvr.addr()) &&
>            TryHandlerTrap(cx, proxy, Trap1(cx, handler, tvr.value(), id, tvr.addr())) &&
>            ReturnedValueMustNotBePrimitive(cx, proxy, ATOM(getPropertyDescriptor), tvr.value()) &&
>            ParsePropertyDescriptorObject(cx, proxy, id, tvr.value(), desc);


Ok, who is violating caller-roots? What caller(s) passed unrooted proxy into this and similar methods?

Quoting Igor: "Most if not all all callers of  lookupProperty pass pointer to unrooted JSObject * from the native stack for the objp parameter." I can dig into it a bit and find out where this happens. There aren't that many call sites (25ish). We should take the discussion to the other bug. If we decide to fix that one we can invalidate this one.
Comment on attachment 448307 [details] [diff] [review]

We will try to fix the general case.
Attachment #448307 - Flags: review?(brendan)
Whiteboard: [sg:critical?]
Whiteboard: [sg:critical?] → [sg:critical?][ccbr][critsmash:investigating]
Whiteboard: [sg:critical?][ccbr][critsmash:investigating] → [sg:critical?][ccbr][critsmash:patch]
(In reply to comment #5)
> (From update of attachment 448307 [details] [diff] [review])
> We will try to fix the general case.

What's the status here?
blocking2.0: final+ → ---
we have a conservative stack scanner on 1.9.3, so this doesn't bite there. the patch here isn't the greatest, so more research needed.
Whiteboard: [sg:critical?][ccbr][critsmash:patch] → [sg:critical?][ccbr][critsmash:patch][stale]
What specific action is next here?
Am I understanding the bug state correctly?
 - we no longer have a security problem in 1.9.3 (comment 8)
 - despite lack of proxies this is potentially exploitable in 1.9.1 and 1.9.2?
   (due to LiveConnect?)

Need a new patch for branches only?
(In reply to comment #10)
> Am I understanding the bug state correctly?
>  - we no longer have a security problem in 1.9.3 (comment 8)

Yes - the conservative scanner has fixed this nicely.

>  - despite lack of proxies this is potentially exploitable in 1.9.1 and 1.9.2?
>    (due to LiveConnect?)


> Need a new patch for branches only?

blocking1.9.1: --- → ?
blocking1.9.2: --- → ?
Andreas: Is the patch in this bug a valid start for an older branch patch or should it be marked obsolete?
blocking1.9.1: ? → .13+
blocking1.9.2: ? → .10+
Whiteboard: [sg:critical?][ccbr][critsmash:patch][stale] → [sg:critical?][ccbr][critsmash:patch][stale][1.9.x branches]
Sayrer to follow up here per critkill meeting.
Igor, what do you think what we should do here? I don't think its worth fixing this "the right way" by ensuring caller-roots. My patch should be simple enough to backport. Brendan, any objections?
Attachment #448307 - Flags: feedback?(igor)
The bad pattern to watch is cases like

any_of_lookupProperty_variants(..., &pobj, &prop)



After some greping I have found a potential issues in JS_SetWatchPoint and obj_toSource. But if the hazards would be confirmed, then at those places we also have an issue where a GC may run with obj locked, so the  hazards may exists even on the trunk we have not yet eliminated support for thread-shared objects.

So I think the suggested approach would be to look at all dropProperty calls (there about 100 of them on 1.9.2 branch but the vast mayoralty of them are trivially safe), locate the above pattern and try to reorganize the code to avoid the potential GC calls fixing the bugs.
The GC doesn't wait for title locks, it knows it is serialized with all requests.

I do agree with coment 15 last paragraph, but who will do the work?

The attached patch is for jsproxy.cpp, new in fx4 -- nothing to backport. What am I missing? Anyway, callee-roots is generally unsound.

Although the callee roots do not work in general, to solve the GC hazards here it is sufficient that liveconnect would copy the pobj result into the newborn root.

As regarding running the GC with the title lock taken, that GC comes from a GC thing allocator. That may also report OOM reports and it is good practice to ensure that all locks are released during those.
Assignee: gal → igor
The patch puts the result of lookupProperty in liveconnect into newborn roots. This should protect the result against bugs where the last-ditch can happen before the caller calls obj->dropProperty.

I will file as separated bug the issues of running the GC or doing OOM reporting with title lock held.
Attachment #448307 - Attachment is obsolete: true
Attachment #479783 - Flags: review?(brendan)
Attachment #448307 - Flags: feedback?(igor)
blocking1.9.1: .14+ → .15+
blocking1.9.2: .11+ → .12+
Comment on attachment 479783 [details] [diff] [review]
newborn rooting in liveconnect

Fragile, but this code will EOL soon enough. Thanks,

Attachment #479783 - Flags: review?(brendan) → review+
can we land this?
Attachment #479783 - Flags: approval1.9.2.12?
Attachment #479783 - Flags: approval1.9.1.15?
(In reply to comment #20)
> can we land this?

The patch is for 1.8.* branches only. It does not exist on the trunk due to the conservative scanner.
Closed: 10 years ago
Resolution: --- → FIXED
(In reply to comment #21)
> The patch is for 1.8.* branches only. 

I meant 1.9.* branches
Comment on attachment 479783 [details] [diff] [review]
newborn rooting in liveconnect

a=LegNeato for and Please land only on the mozilla-1.9.2 default branch and mozilla-1.9.1 default branch, *not* the relbranches.
Attachment #479783 - Flags: approval1.9.2.12?
Attachment #479783 - Flags: approval1.9.2.12+
Attachment #479783 - Flags: approval1.9.1.15?
Attachment #479783 - Flags: approval1.9.1.15+
Group: core-security
Attachment #479783 - Attachment is private: false
You need to log in before you can comment on or make changes to this bug.