Bug 101190 - [V8] Remove setDOMWrapper(wrapper, 0) from V8NPObject
Summary: [V8] Remove setDOMWrapper(wrapper, 0) from V8NPObject
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Kentaro Hara
URL:
Keywords:
Depends on:
Blocks: 101054
  Show dependency treegraph
 
Reported: 2012-11-05 00:37 PST by Kentaro Hara
Modified: 2012-11-06 05:21 PST (History)
3 users (show)

See Also:


Attachments
Patch (1.64 KB, patch)
2012-11-05 00:38 PST, Kentaro Hara
no flags Details | Formatted Diff | Diff
Patch (3.18 KB, patch)
2012-11-05 10:50 PST, Kentaro Hara
no flags Details | Formatted Diff | Diff
patch for landing (3.18 KB, patch)
2012-11-06 01:37 PST, Kentaro Hara
no flags Details | Formatted Diff | Diff
patch for landing (3.18 KB, patch)
2012-11-06 03:37 PST, Kentaro Hara
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Kentaro Hara 2012-11-05 00:37:12 PST
In bug 101054, we want to add an ASSERT() that guarantees that we don't pass 0 to setDOMWrapper(). On the other hand, V8NPObject.cpp is trying to pass 0 to setDOMWrapper() just before disposing a wrapper, which hits the ASSERT(). We should remove it.
Comment 1 Kentaro Hara 2012-11-05 00:38:33 PST
Created attachment 172284 [details]
Patch
Comment 2 Adam Barth 2012-11-05 07:47:24 PST
Comment on attachment 172284 [details]
Patch

What if other folks have a reference to the v8 object?  After this change, won't they have a use-after-free if they try to access the wrapped object?

In the DOM case, we only remove objects from the wrapper map when we get a weak handle callback.  In the case of NP objects, we can remove them when asked to do so explicitly by the plugin (you might want to check that I'm right about that---it's from memory).
Comment 3 Kentaro Hara 2012-11-05 07:50:15 PST
(In reply to comment #2)
> (From update of attachment 172284 [details])
> What if other folks have a reference to the v8 object?  After this change, won't they have a use-after-free if they try to access the wrapped object?

Just after this setDOMWrapper(wrapper, 0), the wrapper handle is immediately disposed and cleared. This means that other folks should not have a reference to the V8 object, doesn't it?
Comment 4 Adam Barth 2012-11-05 08:25:53 PST
> Just after this setDOMWrapper(wrapper, 0), the wrapper handle is immediately disposed and cleared. This means that other folks should not have a reference to the V8 object, doesn't it?

No, that just means that we don't have a reference anymore.  There could be other handles to the object, either local or persistent or internal to the JS VM.
Comment 5 Kentaro Hara 2012-11-05 08:39:17 PST
(In reply to comment #4)
> > Just after this setDOMWrapper(wrapper, 0), the wrapper handle is immediately disposed and cleared. This means that other folks should not have a reference to the V8 object, doesn't it?
> 
> No, that just means that we don't have a reference anymore.  There could be other handles to the object, either local or persistent or internal to the JS VM.

Yeah, makes sense... but that sounds like another problem. In bindings (even in V8NPObject.cpp), we do not do a null check for the result of toNative(handle). If there were other folks holding a handle to the wrapper, the folks might retrieve null pointers from internal fields and use them.
Comment 6 Adam Barth 2012-11-05 10:04:16 PST
I think only NP objects need to null-check toNative.
Comment 7 Kentaro Hara 2012-11-05 10:31:03 PST
(In reply to comment #6)
> I think only NP objects need to null-check toNative.

Thanks, now I understood things.

As far as I scanned the code, the only place where toNative(npObjectWrapper) is called is weakNPObjectCallback() in V8NPObject.cpp. Just after toNative(npObjectWrapper), we have an ASSERT() that checks if the retrieved npObject is not NULL. So, the world is working safely.
Comment 8 Kentaro Hara 2012-11-05 10:50:06 PST
Reopening to attach new patch.
Comment 9 Kentaro Hara 2012-11-05 10:50:09 PST
Created attachment 172363 [details]
Patch
Comment 10 Adam Barth 2012-11-05 14:02:10 PST
Comment on attachment 172363 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=172363&action=review

> Source/WebCore/bindings/v8/V8DOMWrapper.h:77
> +        static void resetDOMWrapper(v8::Handle<v8::Object> object, WrapperTypeInfo* type)

resetDOMWrapper -> clearDOMWrapper?
Comment 11 Kentaro Hara 2012-11-06 01:37:48 PST
Created attachment 172519 [details]
patch for landing
Comment 12 WebKit Review Bot 2012-11-06 03:34:59 PST
Comment on attachment 172519 [details]
patch for landing

Rejecting attachment 172519 [details] from commit-queue.

Failed to run "['/mnt/git/webkit-commit-queue/Tools/Scripts/webkit-patch', '--status-host=queues.webkit.org', '-..." exit_code: 1

ERROR: /mnt/git/webkit-commit-queue/Source/WebCore/ChangeLog neither lists a valid reviewer nor contains the string "Unreviewed" or "Rubber stamp" (case insensitive).

Full output: http://queues.webkit.org/results/14690390
Comment 13 Kentaro Hara 2012-11-06 03:37:37 PST
Created attachment 172542 [details]
patch for landing
Comment 14 WebKit Review Bot 2012-11-06 05:21:09 PST
Comment on attachment 172542 [details]
patch for landing

Clearing flags on attachment: 172542

Committed r133589: <http://trac.webkit.org/changeset/133589>
Comment 15 WebKit Review Bot 2012-11-06 05:21:12 PST
All reviewed patches have been landed.  Closing bug.