Title: [253163] trunk/Source
Revision
253163
Author
[email protected]
Date
2019-12-05 12:20:48 -0800 (Thu, 05 Dec 2019)

Log Message

MESSAGE_CHECK BackForwardItemIdentifier on incoming IPC from the WebProcess
https://bugs.webkit.org/show_bug.cgi?id=204899

Reviewed by Ryosuke Niwa.

Source/WebCore:

* Sources.txt:
* history/BackForwardItemIdentifier.cpp: Added.
(WebCore::BackForwardItemIdentifier::isValid const):
* history/BackForwardItemIdentifier.h:
(WebCore::operator!=):

Source/WebKit:

MESSAGE_CHECK BackForwardItemIdentifier on incoming IPC from the WebProcess. This is important since we use this identifier
to look up the WebBackForwardListItem in a HashMap, and looking up a bad ID could corrupt said HashMap.

* Shared/WebBackForwardListItem.cpp:
Make sure the WebBackForwardListItem is always constructed and destroyed on the main thread, to avoid corrupting
the allItems() HashMap.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::willGoToBackForwardListItem):
(WebKit::WebPageProxy::backForwardGoToItemShared):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::updateBackForwardItem):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (253162 => 253163)


--- trunk/Source/WebCore/ChangeLog	2019-12-05 20:18:42 UTC (rev 253162)
+++ trunk/Source/WebCore/ChangeLog	2019-12-05 20:20:48 UTC (rev 253163)
@@ -1,3 +1,16 @@
+2019-12-05  Chris Dumez  <[email protected]>
+
+        MESSAGE_CHECK BackForwardItemIdentifier on incoming IPC from the WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=204899
+
+        Reviewed by Ryosuke Niwa.
+
+        * Sources.txt:
+        * history/BackForwardItemIdentifier.cpp: Added.
+        (WebCore::BackForwardItemIdentifier::isValid const):
+        * history/BackForwardItemIdentifier.h:
+        (WebCore::operator!=):
+
 2019-12-05  Zalan Bujtas  <[email protected]>
 
         [LFC][IFC] Trim trailing letter-spacing at inline container boundary

Modified: trunk/Source/WebCore/Sources.txt (253162 => 253163)


--- trunk/Source/WebCore/Sources.txt	2019-12-05 20:18:42 UTC (rev 253162)
+++ trunk/Source/WebCore/Sources.txt	2019-12-05 20:20:48 UTC (rev 253163)
@@ -1086,6 +1086,7 @@
 
 history/BackForwardCache.cpp
 history/BackForwardController.cpp
+history/BackForwardItemIdentifier.cpp
 history/CachedFrame.cpp
 history/CachedPage.cpp
 history/HistoryItem.cpp

Added: trunk/Source/WebCore/history/BackForwardItemIdentifier.cpp (0 => 253163)


--- trunk/Source/WebCore/history/BackForwardItemIdentifier.cpp	                        (rev 0)
+++ trunk/Source/WebCore/history/BackForwardItemIdentifier.cpp	2019-12-05 20:20:48 UTC (rev 253163)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "BackForwardItemIdentifier.h"
+
+namespace WebCore {
+
+bool BackForwardItemIdentifier::isValid() const
+{
+    return HashTraits<BackForwardItemIdentifier>::emptyValue() != *this && !HashTraits<BackForwardItemIdentifier>::isDeletedValue(*this);
+}
+
+}

Modified: trunk/Source/WebCore/history/BackForwardItemIdentifier.h (253162 => 253163)


--- trunk/Source/WebCore/history/BackForwardItemIdentifier.h	2019-12-05 20:18:42 UTC (rev 253162)
+++ trunk/Source/WebCore/history/BackForwardItemIdentifier.h	2019-12-05 20:20:48 UTC (rev 253163)
@@ -45,6 +45,8 @@
 
     String string() const { return makeString(processIdentifier.toUInt64(), '-', itemIdentifier.toUInt64()); }
 
+    WEBCORE_EXPORT bool isValid() const;
+
 #if !LOG_DISABLED
     const char* logString() const;
 #endif
@@ -64,6 +66,11 @@
     return a.processIdentifier == b.processIdentifier &&  a.itemIdentifier == b.itemIdentifier;
 }
 
+inline bool operator!=(const BackForwardItemIdentifier& a, const BackForwardItemIdentifier& b)
+{
+    return !(a == b);
+}
+
 template<class Encoder>
 void BackForwardItemIdentifier::encode(Encoder& encoder) const
 {

Modified: trunk/Source/WebKit/ChangeLog (253162 => 253163)


--- trunk/Source/WebKit/ChangeLog	2019-12-05 20:18:42 UTC (rev 253162)
+++ trunk/Source/WebKit/ChangeLog	2019-12-05 20:20:48 UTC (rev 253163)
@@ -1,3 +1,23 @@
+2019-12-05  Chris Dumez  <[email protected]>
+
+        MESSAGE_CHECK BackForwardItemIdentifier on incoming IPC from the WebProcess
+        https://bugs.webkit.org/show_bug.cgi?id=204899
+
+        Reviewed by Ryosuke Niwa.
+
+        MESSAGE_CHECK BackForwardItemIdentifier on incoming IPC from the WebProcess. This is important since we use this identifier
+        to look up the WebBackForwardListItem in a HashMap, and looking up a bad ID could corrupt said HashMap.
+
+        * Shared/WebBackForwardListItem.cpp:
+        Make sure the WebBackForwardListItem is always constructed and destroyed on the main thread, to avoid corrupting
+        the allItems() HashMap.
+
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::willGoToBackForwardListItem):
+        (WebKit::WebPageProxy::backForwardGoToItemShared):
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::updateBackForwardItem):
+
 2019-12-05  Kate Cheney  <[email protected]>
 
         [MSVC] WebResourceLoadStatisticsStore.h is reporting warning C4804: '/': unsafe use of type 'bool' in operation

Modified: trunk/Source/WebKit/Shared/WebBackForwardListItem.cpp (253162 => 253163)


--- trunk/Source/WebKit/Shared/WebBackForwardListItem.cpp	2019-12-05 20:18:42 UTC (rev 253162)
+++ trunk/Source/WebKit/Shared/WebBackForwardListItem.cpp	2019-12-05 20:20:48 UTC (rev 253163)
@@ -60,6 +60,7 @@
 
 HashMap<BackForwardItemIdentifier, WebBackForwardListItem*>& WebBackForwardListItem::allItems()
 {
+    RELEASE_ASSERT(RunLoop::isMain());
     static NeverDestroyed<HashMap<BackForwardItemIdentifier, WebBackForwardListItem*>> items;
     return items;
 }

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (253162 => 253163)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-12-05 20:18:42 UTC (rev 253162)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2019-12-05 20:20:48 UTC (rev 253163)
@@ -1573,6 +1573,8 @@
 
 void WebPageProxy::willGoToBackForwardListItem(const BackForwardItemIdentifier& itemID, bool inBackForwardCache)
 {
+    MESSAGE_CHECK(m_process, itemID.isValid());
+
     PageClientProtector protector(pageClient());
 
     if (auto* item = m_backForwardList->itemForID(itemID))
@@ -5925,6 +5927,8 @@
 
 void WebPageProxy::backForwardGoToItemShared(Ref<WebProcessProxy>&& process, const BackForwardItemIdentifier& itemID, CompletionHandler<void(SandboxExtension::Handle&&)>&& completionHandler)
 {
+    MESSAGE_CHECK(process, itemID.isValid());
+
     auto* item = m_backForwardList->itemForID(itemID);
     if (!item)
         return completionHandler({ });

Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (253162 => 253163)


--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-12-05 20:18:42 UTC (rev 253162)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp	2019-12-05 20:20:48 UTC (rev 253163)
@@ -627,6 +627,8 @@
 
 void WebProcessProxy::updateBackForwardItem(const BackForwardListItemState& itemState)
 {
+    MESSAGE_CHECK(itemState.identifier.isValid());
+
     auto* item = WebBackForwardListItem::itemForID(itemState.identifier);
     if (!item || !isAllowedToUpdateBackForwardItem(*item))
         return;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to