Last Comment Bug 569162 - GC hazard with lookupProperty callers with scripted proxy handlers
: GC hazard with lookupProperty callers with scripted proxy handlers
Status: RESOLVED FIXED
[sg:critical?][ccbr][critsmash:patch]...
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Other Branch
: All All
: -- normal (vote)
: ---
Assigned To: Igor Bukanov
:
: Jason Orendorff [:jorendorff]
Mentors:
Depends on:
Blocks: harmony:proxies 568465
  Show dependency treegraph
 
Reported: 2010-05-30 16:38 PDT by Andreas Gal :gal
Modified: 2011-01-27 17:28 PST (History)
12 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---
unaffected
.13+
.13-fixed
.16+
.16-fixed


Attachments
patch (7.16 KB, patch)
2010-05-30 16:40 PDT, Andreas Gal :gal
no flags Details | Diff | Splinter Review
newborn rooting in liveconnect (3.37 KB, patch)
2010-09-30 08:22 PDT, Igor Bukanov
brendan: review+
christian: approval1.9.2.13+
christian: approval1.9.1.16+
Details | Diff | Splinter Review

Description Andreas Gal :gal 2010-05-30 16:38:35 PDT
lookupProperty and other object ops calls might not root obj.
Comment 1 Andreas Gal :gal 2010-05-30 16:40:24 PDT
Created attachment 448307 [details] [diff] [review]
patch
Comment 2 Andreas Gal :gal 2010-05-30 16:45:02 PDT
Proxies didn't exist in 192 and 191, so no need to block.
Comment 3 Brendan Eich [:brendan] 2010-05-30 17:06:45 PDT
Comment on attachment 448307 [details] [diff] [review]
patch

>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);

etc.

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

/be
Comment 4 Andreas Gal :gal 2010-05-30 18:01:48 PDT
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 5 Andreas Gal :gal 2010-05-30 20:07:48 PDT
Comment on attachment 448307 [details] [diff] [review]
patch

We will try to fix the general case.
Comment 6 Robert Sayre 2010-06-15 13:28:33 PDT
(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?
Comment 7 Robert Sayre 2010-06-22 13:17:41 PDT
ping...?
Comment 8 Robert Sayre 2010-07-13 15:40:26 PDT
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.
Comment 9 Damon Sicore (:damons) 2010-08-24 13:19:04 PDT
What specific action is next here?
Comment 10 Daniel Veditz [:dveditz] 2010-08-24 13:25:12 PDT
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?
Comment 11 Igor Bukanov 2010-08-24 14:03:38 PDT
(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?)

Yes.

> 
> Need a new patch for branches only?

Yes.
Comment 12 Daniel Veditz [:dveditz] 2010-08-30 10:30:16 PDT
Andreas: Is the patch in this bug a valid start for an older branch patch or should it be marked obsolete?
Comment 13 Johnny Stenback (:jst, jst@mozilla.com) 2010-09-21 13:23:17 PDT
Sayrer to follow up here per critkill meeting.
Comment 14 Andreas Gal :gal 2010-09-28 15:10:43 PDT
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?
Comment 15 Igor Bukanov 2010-09-29 07:20:43 PDT
The bad pattern to watch is cases like

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

code_that_potentialy_can_run_gc

pobj->dropProperty();

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.
Comment 16 Brendan Eich [:brendan] 2010-09-29 20:48:16 PDT
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.

/be
Comment 17 Igor Bukanov 2010-09-30 01:24:06 PDT
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.
Comment 18 Igor Bukanov 2010-09-30 08:22:56 PDT
Created attachment 479783 [details] [diff] [review]
newborn rooting in liveconnect

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.
Comment 19 Brendan Eich [:brendan] 2010-10-02 21:16:10 PDT
Comment on attachment 479783 [details] [diff] [review]
newborn rooting in liveconnect

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

/be
Comment 20 Robert Sayre 2010-10-05 13:49:05 PDT
can we land this?
Comment 21 Igor Bukanov 2010-10-06 02:31:41 PDT
(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.
Comment 22 Igor Bukanov 2010-10-06 04:47:38 PDT
(In reply to comment #21)
> The patch is for 1.8.* branches only. 

I meant 1.9.* branches
Comment 23 christian 2010-10-06 10:25:36 PDT
Comment on attachment 479783 [details] [diff] [review]
newborn rooting in liveconnect

a=LegNeato for 1.9.2.12 and 1.9.1.15. Please land only on the mozilla-1.9.2 default branch and mozilla-1.9.1 default branch, *not* the relbranches.

Note You need to log in before you can comment on or make changes to this bug.