- Revision
- 268497
- Author
- rn...@webkit.org
- Date
- 2020-10-14 16:14:55 -0700 (Wed, 14 Oct 2020)
Log Message
Enabling IPC testing API should prevent the termination of WebContent process which sends an invalid IPC
https://bugs.webkit.org/show_bug.cgi?id=217698
Reviewed by Geoffrey Garen.
Source/WebKit:
A part of this was landed in r268431 but this patch formally disables UI process' default behavior
to terminate a Web process upon receiving an invalid message from it.
Tests: IPCTestingAPI.CanSendInvalidAsyncMessageWithoutTermination
IPCTestingAPI.CanSendInvalidMessageWithoutTermination
* Platform/IPC/Connection.cpp:
(IPC::Connection::dispatchSyncMessage): Disable the debug assertion if the IPC testing API is enabled.
* Platform/IPC/Connection.h:
(IPC::Connection::setIgnoreInvalidMessageForTesting): Added.
(IPC::Connection::ignoreInvalidMessageForTesting const): Added.
(IPC::Connection::m_ignoreInvalidMessageForTesting): Added.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy): Set the flag on WebProcessProxy to trigger the behavior.
(WebKit::WebPageProxy::launchProcess): Ditto.
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didReceiveInvalidMessage): Use the flag on Connection instead of reaching
out to the default page group.
(WebKit::WebProcessProxy::setIgnoreInvalidMessageForTesting): Added. Remember the fact we've enabled IPC
testing API in a member variable and propagate the flag to Connection if a Web process is already running.
(WebKit::WebProcessProxy::didFinishLaunching): Propagte the flag to the newly launched Web process.
* UIProcess/WebProcessProxy.h:
(WebKit::WebProcessProxy::m_ignoreInvalidMessageForTesting): Added.
Tools:
Added regression tests.
* TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm:
(IPCTestingAPI.CanSendInvalidAsyncMessageWithoutTermination):
(IPCTestingAPI.CanSendInvalidMessageWithoutTermination):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (268496 => 268497)
--- trunk/Source/WebKit/ChangeLog 2020-10-14 23:08:15 UTC (rev 268496)
+++ trunk/Source/WebKit/ChangeLog 2020-10-14 23:14:55 UTC (rev 268497)
@@ -1,3 +1,34 @@
+2020-10-14 Ryosuke Niwa <rn...@webkit.org>
+
+ Enabling IPC testing API should prevent the termination of WebContent process which sends an invalid IPC
+ https://bugs.webkit.org/show_bug.cgi?id=217698
+
+ Reviewed by Geoffrey Garen.
+
+ A part of this was landed in r268431 but this patch formally disables UI process' default behavior
+ to terminate a Web process upon receiving an invalid message from it.
+
+ Tests: IPCTestingAPI.CanSendInvalidAsyncMessageWithoutTermination
+ IPCTestingAPI.CanSendInvalidMessageWithoutTermination
+
+ * Platform/IPC/Connection.cpp:
+ (IPC::Connection::dispatchSyncMessage): Disable the debug assertion if the IPC testing API is enabled.
+ * Platform/IPC/Connection.h:
+ (IPC::Connection::setIgnoreInvalidMessageForTesting): Added.
+ (IPC::Connection::ignoreInvalidMessageForTesting const): Added.
+ (IPC::Connection::m_ignoreInvalidMessageForTesting): Added.
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::WebPageProxy): Set the flag on WebProcessProxy to trigger the behavior.
+ (WebKit::WebPageProxy::launchProcess): Ditto.
+ * UIProcess/WebProcessProxy.cpp:
+ (WebKit::WebProcessProxy::didReceiveInvalidMessage): Use the flag on Connection instead of reaching
+ out to the default page group.
+ (WebKit::WebProcessProxy::setIgnoreInvalidMessageForTesting): Added. Remember the fact we've enabled IPC
+ testing API in a member variable and propagate the flag to Connection if a Web process is already running.
+ (WebKit::WebProcessProxy::didFinishLaunching): Propagte the flag to the newly launched Web process.
+ * UIProcess/WebProcessProxy.h:
+ (WebKit::WebProcessProxy::m_ignoreInvalidMessageForTesting): Added.
+
2020-10-14 Per Arne Vollan <pvol...@apple.com>
[macOS] Issue sandbox extension to additional icon service when attachment element is enabled.
Modified: trunk/Source/WebKit/Platform/IPC/Connection.cpp (268496 => 268497)
--- trunk/Source/WebKit/Platform/IPC/Connection.cpp 2020-10-14 23:08:15 UTC (rev 268496)
+++ trunk/Source/WebKit/Platform/IPC/Connection.cpp 2020-10-14 23:14:55 UTC (rev 268497)
@@ -928,7 +928,7 @@
}
// FIXME: If the message was invalid, we should send back a SyncMessageError.
- ASSERT(decoder.isValid());
+ ASSERT(decoder.isValid() || m_ignoreInvalidMessageForTesting);
if (replyEncoder)
sendSyncReply(WTFMove(replyEncoder));
Modified: trunk/Source/WebKit/Platform/IPC/Connection.h (268496 => 268497)
--- trunk/Source/WebKit/Platform/IPC/Connection.h 2020-10-14 23:08:15 UTC (rev 268496)
+++ trunk/Source/WebKit/Platform/IPC/Connection.h 2020-10-14 23:14:55 UTC (rev 268497)
@@ -287,6 +287,11 @@
void enableIncomingMessagesThrottling();
+#if ENABLE(IPC_TESTING_API)
+ void setIgnoreInvalidMessageForTesting() { m_ignoreInvalidMessageForTesting = true; }
+ bool ignoreInvalidMessageForTesting() const { return m_ignoreInvalidMessageForTesting; }
+#endif
+
private:
Connection(Identifier, bool isServer, Client&);
void platformInitialize(Identifier);
@@ -409,6 +414,10 @@
RefPtr<WorkQueue> m_incomingSyncMessageCallbackQueue;
uint64_t m_nextIncomingSyncMessageCallbackID { 0 };
+#if ENABLE(IPC_TESTING_API)
+ bool m_ignoreInvalidMessageForTesting { false };
+#endif
+
#if HAVE(QOS_CLASSES)
pthread_t m_mainThread { 0 };
bool m_shouldBoostMainThreadOnSyncMessage { false };
Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (268496 => 268497)
--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2020-10-14 23:08:15 UTC (rev 268496)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp 2020-10-14 23:14:55 UTC (rev 268497)
@@ -570,6 +570,12 @@
m_inspectorDebuggable->init();
#endif
m_inspectorController->init();
+
+#if ENABLE(IPC_TESTING_API)
+ if (m_preferences->store().getBoolValueForKey(WebPreferencesKey::ipcTestingAPIEnabledKey()))
+ process.setIgnoreInvalidMessageForTesting();
+#endif
+
}
WebPageProxy::~WebPageProxy()
@@ -839,6 +845,11 @@
m_process->addExistingWebPage(*this, WebProcessProxy::BeginsUsingDataStore::Yes);
m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_webPageID, *this);
+#if ENABLE(IPC_TESTING_API)
+ if (m_preferences->store().getBoolValueForKey(WebPreferencesKey::ipcTestingAPIEnabledKey()))
+ m_process->setIgnoreInvalidMessageForTesting();
+#endif
+
finishAttachingToWebProcess(reason);
auto pendingInjectedBundleMessage = WTFMove(m_pendingInjectedBundleMessages);
Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp (268496 => 268497)
--- trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp 2020-10-14 23:08:15 UTC (rev 268496)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp 2020-10-14 23:14:55 UTC (rev 268497)
@@ -880,6 +880,11 @@
WebProcessPool::didReceiveInvalidMessage(messageName);
+#if ENABLE(IPC_TESTING_API)
+ if (connection.ignoreInvalidMessageForTesting())
+ return;
+#endif
+
// Terminate the WebContent process.
terminate();
@@ -955,6 +960,15 @@
#endif
}
+#if ENABLE(IPC_TESTING_API)
+void WebProcessProxy::setIgnoreInvalidMessageForTesting()
+{
+ if (state() == State::Running)
+ connection()->setIgnoreInvalidMessageForTesting();
+ m_ignoreInvalidMessageForTesting = true;
+}
+#endif
+
void WebProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connection::Identifier connectionIdentifier)
{
RELEASE_ASSERT(isMainThreadOrCheckDisabled());
@@ -979,6 +993,11 @@
m_processPool->processDidFinishLaunching(this);
m_backgroundResponsivenessTimer.updateState();
+#if ENABLE(IPC_TESTING_API)
+ if (m_ignoreInvalidMessageForTesting)
+ connection()->setIgnoreInvalidMessageForTesting();
+#endif
+
#if PLATFORM(IOS_FAMILY)
if (connection()) {
if (xpc_connection_t xpcConnection = connection()->xpcConnection())
Modified: trunk/Source/WebKit/UIProcess/WebProcessProxy.h (268496 => 268497)
--- trunk/Source/WebKit/UIProcess/WebProcessProxy.h 2020-10-14 23:08:15 UTC (rev 268496)
+++ trunk/Source/WebKit/UIProcess/WebProcessProxy.h 2020-10-14 23:14:55 UTC (rev 268497)
@@ -390,6 +390,10 @@
AudioSessionRoutingArbitratorProxy& audioSessionRoutingArbitrator() { return m_routingArbitrator.get(); }
#endif
+#if ENABLE(IPC_TESTING_API)
+ void setIgnoreInvalidMessageForTesting();
+#endif
+
protected:
WebProcessProxy(WebProcessPool&, WebsiteDataStore*, IsPrewarmed);
@@ -620,6 +624,10 @@
Optional<AudibleMediaActivity> m_audibleMediaActivity;
ShutdownPreventingScopeCounter m_shutdownPreventingScopeCounter;
+
+#if ENABLE(IPC_TESTING_API)
+ bool m_ignoreInvalidMessageForTesting { false };
+#endif
};
} // namespace WebKit
Modified: trunk/Tools/ChangeLog (268496 => 268497)
--- trunk/Tools/ChangeLog 2020-10-14 23:08:15 UTC (rev 268496)
+++ trunk/Tools/ChangeLog 2020-10-14 23:14:55 UTC (rev 268497)
@@ -1,3 +1,16 @@
+2020-10-14 Ryosuke Niwa <rn...@webkit.org>
+
+ Enabling IPC testing API should prevent the termination of WebContent process which sends an invalid IPC
+ https://bugs.webkit.org/show_bug.cgi?id=217698
+
+ Reviewed by Geoffrey Garen.
+
+ Added regression tests.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm:
+ (IPCTestingAPI.CanSendInvalidAsyncMessageWithoutTermination):
+ (IPCTestingAPI.CanSendInvalidMessageWithoutTermination):
+
2020-10-14 Aakash Jain <aakash_j...@apple.com>
[build.webkit.org] Add python 3 support - part 1
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm (268496 => 268497)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm 2020-10-14 23:08:15 UTC (rev 268496)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm 2020-10-14 23:14:55 UTC (rev 268497)
@@ -87,4 +87,50 @@
EXPECT_STREQ([alertMessage UTF8String], "hi");
}
+TEST(IPCTestingAPI, CanSendInvalidAsyncMessageWithoutTermination)
+{
+ RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
+ if ([feature.key isEqualToString:@"IPCTestingAPIEnabled"]) {
+ [[configuration preferences] _setEnabled:YES forInternalDebugFeature:feature];
+ break;
+ }
+ }
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
+
+ auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
+ [webView setUIDelegate:delegate.get()];
+
+ done = false;
+ [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>"
+ "IPC.sendMessage('UI', IPC.webPageProxyID, IPC.messages.WebPageProxy_ShowShareSheet.name, []);"
+ "alert('hi')</script>"];
+ TestWebKitAPI::Util::run(&done);
+
+ EXPECT_STREQ([alertMessage UTF8String], "hi");
+}
+
+TEST(IPCTestingAPI, CanSendInvalidMessageWithoutTermination)
+{
+ RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
+ if ([feature.key isEqualToString:@"IPCTestingAPIEnabled"]) {
+ [[configuration preferences] _setEnabled:YES forInternalDebugFeature:feature];
+ break;
+ }
+ }
+ RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
+
+ auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
+ [webView setUIDelegate:delegate.get()];
+
+ done = false;
+ [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>"
+ "IPC.sendSyncMessage('UI', IPC.webPageProxyID, IPC.messages.WebPageProxy_RunJavaScriptAlert.name, 100, [{type: 'uint64_t', value: IPC.frameID}]);"
+ "alert('hi')</script>"];
+ TestWebKitAPI::Util::run(&done);
+
+ EXPECT_STREQ([alertMessage UTF8String], "hi");
+}
+
#endif