Bug 173803 - Assert that callback ID is not 0 or -1 during encoding and decoding
Summary: Assert that callback ID is not 0 or -1 during encoding and decoding
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2017-06-23 21:02 PDT by Ryosuke Niwa
Modified: 2017-06-29 20:03 PDT (History)
6 users (show)

See Also:


Attachments
Adds assertion (129.96 KB, patch)
2017-06-23 22:58 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Fixed iOS build (161.77 KB, patch)
2017-06-23 23:25 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
WPE build fix attempt (162.79 KB, patch)
2017-06-23 23:35 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Another WPE build fix attempt (167.48 KB, patch)
2017-06-23 23:55 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Yet another WPE build fix attempt (167.70 KB, patch)
2017-06-24 00:07 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
More GTK+ and WPE build fixes (171.03 KB, patch)
2017-06-24 00:21 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Another GTK+ and WPE build fixes (171.00 KB, patch)
2017-06-24 00:28 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Yet another GTK+ and WPE build fixes (171.01 KB, patch)
2017-06-24 00:38 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Even more GTK+ and WPE build fixes (172.47 KB, patch)
2017-06-24 00:47 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Another GTK+ build fix (172.96 KB, patch)
2017-06-24 00:53 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff
Updated per Dan's comments (168.26 KB, patch)
2017-06-25 21:34 PDT, Ryosuke Niwa
beidson: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2017-06-23 21:02:48 PDT
To diagnose a hang inside the m_callbacks in WebPageProxy, assert that callbackID is not 0 or -1 in IPC message encode/decode code
Comment 1 Ryosuke Niwa 2017-06-23 22:58:55 PDT
Created attachment 313771 [details]
Adds assertion
Comment 2 Ryosuke Niwa 2017-06-23 23:25:40 PDT
Created attachment 313773 [details]
Fixed iOS build
Comment 3 Ryosuke Niwa 2017-06-23 23:35:10 PDT
Created attachment 313774 [details]
WPE build fix attempt
Comment 4 Ryosuke Niwa 2017-06-23 23:55:31 PDT
Created attachment 313775 [details]
Another WPE build fix attempt
Comment 5 Ryosuke Niwa 2017-06-24 00:07:33 PDT
Created attachment 313776 [details]
Yet another WPE build fix attempt
Comment 6 Ryosuke Niwa 2017-06-24 00:21:25 PDT
Created attachment 313777 [details]
More GTK+ and WPE build fixes
Comment 7 Ryosuke Niwa 2017-06-24 00:28:35 PDT
Created attachment 313779 [details]
Another GTK+ and WPE build fixes
Comment 8 Ryosuke Niwa 2017-06-24 00:38:38 PDT
Created attachment 313780 [details]
Yet another GTK+ and WPE build fixes
Comment 9 Ryosuke Niwa 2017-06-24 00:47:47 PDT
Created attachment 313781 [details]
Even more GTK+ and WPE build fixes
Comment 10 Ryosuke Niwa 2017-06-24 00:53:32 PDT
Created attachment 313782 [details]
Another GTK+ build fix
Comment 11 Radar WebKit Bug Importer 2017-06-24 01:09:45 PDT
<rdar://problem/32964323>
Comment 12 mitz 2017-06-24 08:04:23 PDT
Comment on attachment 313782 [details]
Another GTK+ build fix

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

> Source/WebKit2/ChangeLog:47
> +        (WebKit::SpecificCallbackMap): Added. Used in WebCookieManagerProxy.

In earlier work, we replaced specific maps with generic ones. Why keep the ones in WebCookieManagerProxy separate?

> Source/WebKit2/ChangeLog:646
> +>>>>>>> .r218782

Stray conflict marker.
Comment 13 Ryosuke Niwa 2017-06-25 21:33:49 PDT
(In reply to mitz from comment #12)
> Comment on attachment 313782 [details]
> Another GTK+ build fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=313782&action=review
> 
> > Source/WebKit2/ChangeLog:47
> > +        (WebKit::SpecificCallbackMap): Added. Used in WebCookieManagerProxy.
> 
> In earlier work, we replaced specific maps with generic ones. Why keep the
> ones in WebCookieManagerProxy separate?

Okay, I wasn't aware of that refactoring effort. Fixed.

> > Source/WebKit2/ChangeLog:646
> > +>>>>>>> .r218782
> 
> Stray conflict marker.

Removed.
Comment 14 Ryosuke Niwa 2017-06-25 21:34:08 PDT
Created attachment 313820 [details]
Updated per Dan's comments
Comment 15 Chris Dumez 2017-06-25 21:59:55 PDT
We don’t really need this anymore, do we? I think adding MESSAGE_CHECKs on UI process side for hardening would likely suffice to protect against this in the future.
Comment 16 Ryosuke Niwa 2017-06-26 00:53:48 PDT
(In reply to Chris Dumez from comment #15)
> We don’t really need this anymore, do we? I think adding MESSAGE_CHECKs on
> UI process side for hardening would likely suffice to protect against this
> in the future.

I think it's still useful to wrap CallbackID in a class so that we can easily add diagnostics in the future. For example, we should really be making the decode() function fail when a callbackID is not optional and it's 0 or -1.
Comment 17 Geoffrey Garen 2017-06-26 11:02:53 PDT
Comment on attachment 313820 [details]
Updated per Dan's comments

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

> Source/WebKit2/Shared/OptionalCallbackID.h:62
> +    static ALWAYS_INLINE bool isValidCallbackID(uint64_t rawId)
> +    {
> +        return !HashTraits<uint64_t>::isDeletedValue(rawId);
> +    }

Why do we consider emptyValue() to be valid? Isn't that the bug we're trying to catch?
Comment 18 Ryosuke Niwa 2017-06-26 11:04:01 PDT
(In reply to Geoffrey Garen from comment #17)
> Comment on attachment 313820 [details]
> Updated per Dan's comments
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=313820&action=review
> 
> > Source/WebKit2/Shared/OptionalCallbackID.h:62
> > +    static ALWAYS_INLINE bool isValidCallbackID(uint64_t rawId)
> > +    {
> > +        return !HashTraits<uint64_t>::isDeletedValue(rawId);
> > +    }
> 
> Why do we consider emptyValue() to be valid? Isn't that the bug we're trying
> to catch?

For OptionalCallbackID, we use 0 to mean it's not set. I have a separate release assertion when the value is used like WTF::Optional.
Comment 19 Brady Eidson 2017-06-27 15:03:19 PDT
Comment on attachment 313820 [details]
Updated per Dan's comments

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

> Source/WebKit2/Shared/CallbackID.h:35
> +namespace WTF {
> +
> +struct CallbackIDHash;
> +
> +}

I don't usually see empty lines between namespace and forward decls like this.

> Source/WebKit2/UIProcess/GenericCallback.h:209
> +    // FIXME: Every caller should pass in activityToken
> +    template<typename... T>
> +    CallbackID put(Function<void(T...)>&& function)
> +    {
> +        auto callback = GenericCallbackType<sizeof...(T), T...>::type::create(WTFMove(function));
> +        return put(WTFMove(callback));
> +    }

Is it okay to punt on this FIXME right now?
Comment 20 Ryosuke Niwa 2017-06-27 15:06:23 PDT
(In reply to Brady Eidson from comment #19)
> Comment on attachment 313820 [details]
> Updated per Dan's comments
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=313820&action=review
> 
> > Source/WebKit2/Shared/CallbackID.h:35
> > +namespace WTF {
> > +
> > +struct CallbackIDHash;
> > +
> > +}
> 
> I don't usually see empty lines between namespace and forward decls like
> this.
> 
> > Source/WebKit2/UIProcess/GenericCallback.h:209
> > +    // FIXME: Every caller should pass in activityToken
> > +    template<typename... T>
> > +    CallbackID put(Function<void(T...)>&& function)
> > +    {
> > +        auto callback = GenericCallbackType<sizeof...(T), T...>::type::create(WTFMove(function));
> > +        return put(WTFMove(callback));
> > +    }
> 
> Is it okay to punt on this FIXME right now?

I wanted to fix it in a separate patch at least to reduce the chance of this patch introducing a new regression.
Comment 21 Brady Eidson 2017-06-28 16:05:15 PDT
(In reply to Ryosuke Niwa from comment #20)
> (In reply to Brady Eidson from comment #19)
> > Comment on attachment 313820 [details]
> > Updated per Dan's comments
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=313820&action=review
> > 
> > > Source/WebKit2/Shared/CallbackID.h:35
> > > +namespace WTF {
> > > +
> > > +struct CallbackIDHash;
> > > +
> > > +}
> > 
> > I don't usually see empty lines between namespace and forward decls like
> > this.
> > 
> > > Source/WebKit2/UIProcess/GenericCallback.h:209
> > > +    // FIXME: Every caller should pass in activityToken
> > > +    template<typename... T>
> > > +    CallbackID put(Function<void(T...)>&& function)
> > > +    {
> > > +        auto callback = GenericCallbackType<sizeof...(T), T...>::type::create(WTFMove(function));
> > > +        return put(WTFMove(callback));
> > > +    }
> > 
> > Is it okay to punt on this FIXME right now?
> 
> I wanted to fix it in a separate patch at least to reduce the chance of this
> patch introducing a new regression.

Could we file a bug and include it in the comment?
Comment 22 Ryosuke Niwa 2017-06-29 20:03:36 PDT
(In reply to Brady Eidson from comment #21)
> (In reply to Ryosuke Niwa from comment #20)
> > (In reply to Brady Eidson from comment #19)
> > > Comment on attachment 313820 [details]
> > > Updated per Dan's comments
> > > 
> > > View in context:
> > > https://bugs.webkit.org/attachment.cgi?id=313820&action=review
> > > 
> > > > Source/WebKit2/Shared/CallbackID.h:35
> > > > +namespace WTF {
> > > > +
> > > > +struct CallbackIDHash;
> > > > +
> > > > +}
> > > 
> > > I don't usually see empty lines between namespace and forward decls like
> > > this.
> > > 
> > > > Source/WebKit2/UIProcess/GenericCallback.h:209
> > > > +    // FIXME: Every caller should pass in activityToken
> > > > +    template<typename... T>
> > > > +    CallbackID put(Function<void(T...)>&& function)
> > > > +    {
> > > > +        auto callback = GenericCallbackType<sizeof...(T), T...>::type::create(WTFMove(function));
> > > > +        return put(WTFMove(callback));
> > > > +    }
> > > 
> > > Is it okay to punt on this FIXME right now?
> > 
> > I wanted to fix it in a separate patch at least to reduce the chance of this
> > patch introducing a new regression.
> 
> Could we file a bug and include it in the comment?

Filed https://bugs.webkit.org/show_bug.cgi?id=174007 to track this.

Thanks for the review.
Comment 23 Ryosuke Niwa 2017-06-29 20:03:56 PDT
Committed r218985: <http://trac.webkit.org/changeset/218985>