Bugzilla@Mozilla – Bug 569162
GC hazard with lookupProperty callers with scripted proxy handlers
Last modified: 2011-01-27 17:28:41 PST
Summon comment box
lookupProperty and other object ops calls might not root obj.
Created attachment 448307 [details] [review] patch
Proxies didn't exist in 192 and 191, so no need to block.
Comment on attachment 448307 [details] [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
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] [review] patch We will try to fix the general case.
(In reply to comment #5) > (From update of attachment 448307 [details] [review]) > We will try to fix the general case. What's the status here?
ping...?
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.
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?) Yes. > > Need a new patch for branches only? Yes.
Andreas: Is the patch in this bug a valid start for an older branch patch or should it be marked obsolete?
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?
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.
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
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.
Created attachment 479783 [details] [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 on attachment 479783 [details] [review] newborn rooting in liveconnect Fragile, but this code will EOL soon enough. Thanks, /be
can we land this?
(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.
(In reply to comment #21) > The patch is for 1.8.* branches only. I meant 1.9.* branches
Comment on attachment 479783 [details] [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.
http://hg.mozilla.org/releases/mozilla-1.9.2/rev/48d24bce1c77 http://hg.mozilla.org/releases/mozilla-1.9.1/rev/166a45227d1c