Changeset 268497 in webkit


Ignore:
Timestamp:
Oct 14, 2020 4:14:55 PM (4 years ago)
Author:
rniwa@webkit.org
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):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r268492 r268497  
     12020-10-14  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Enabling IPC testing API should prevent the termination of WebContent process which sends an invalid IPC
     4        https://bugs.webkit.org/show_bug.cgi?id=217698
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        A part of this was landed in r268431 but this patch formally disables UI process' default behavior
     9        to terminate a Web process upon receiving an invalid message from it.
     10
     11        Tests: IPCTestingAPI.CanSendInvalidAsyncMessageWithoutTermination
     12               IPCTestingAPI.CanSendInvalidMessageWithoutTermination
     13
     14        * Platform/IPC/Connection.cpp:
     15        (IPC::Connection::dispatchSyncMessage): Disable the debug assertion if the IPC testing API is enabled.
     16        * Platform/IPC/Connection.h:
     17        (IPC::Connection::setIgnoreInvalidMessageForTesting): Added.
     18        (IPC::Connection::ignoreInvalidMessageForTesting const): Added.
     19        (IPC::Connection::m_ignoreInvalidMessageForTesting): Added.
     20        * UIProcess/WebPageProxy.cpp:
     21        (WebKit::WebPageProxy::WebPageProxy): Set the flag on WebProcessProxy to trigger the behavior.
     22        (WebKit::WebPageProxy::launchProcess): Ditto.
     23        * UIProcess/WebProcessProxy.cpp:
     24        (WebKit::WebProcessProxy::didReceiveInvalidMessage): Use the flag on Connection instead of reaching
     25        out to the default page group.
     26        (WebKit::WebProcessProxy::setIgnoreInvalidMessageForTesting): Added. Remember the fact we've enabled IPC
     27        testing API in a member variable and propagate the flag to Connection if a Web process is already running.
     28        (WebKit::WebProcessProxy::didFinishLaunching): Propagte the flag to the newly launched Web process.
     29        * UIProcess/WebProcessProxy.h:
     30        (WebKit::WebProcessProxy::m_ignoreInvalidMessageForTesting): Added.
     31
    1322020-10-14  Per Arne Vollan  <pvollan@apple.com>
    233
  • trunk/Source/WebKit/Platform/IPC/Connection.cpp

    r268423 r268497  
    929929
    930930    // FIXME: If the message was invalid, we should send back a SyncMessageError.
    931     ASSERT(decoder.isValid());
     931    ASSERT(decoder.isValid() || m_ignoreInvalidMessageForTesting);
    932932
    933933    if (replyEncoder)
  • trunk/Source/WebKit/Platform/IPC/Connection.h

    r268423 r268497  
    288288    void enableIncomingMessagesThrottling();
    289289
     290#if ENABLE(IPC_TESTING_API)
     291    void setIgnoreInvalidMessageForTesting() { m_ignoreInvalidMessageForTesting = true; }
     292    bool ignoreInvalidMessageForTesting() const { return m_ignoreInvalidMessageForTesting; }
     293#endif
     294
    290295private:
    291296    Connection(Identifier, bool isServer, Client&);
     
    409414    RefPtr<WorkQueue> m_incomingSyncMessageCallbackQueue;
    410415    uint64_t m_nextIncomingSyncMessageCallbackID { 0 };
     416
     417#if ENABLE(IPC_TESTING_API)
     418    bool m_ignoreInvalidMessageForTesting { false };
     419#endif
    411420
    412421#if HAVE(QOS_CLASSES)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r268492 r268497  
    571571#endif
    572572    m_inspectorController->init();
     573
     574#if ENABLE(IPC_TESTING_API)
     575    if (m_preferences->store().getBoolValueForKey(WebPreferencesKey::ipcTestingAPIEnabledKey()))
     576        process.setIgnoreInvalidMessageForTesting();
     577#endif
     578
    573579}
    574580
     
    839845    m_process->addExistingWebPage(*this, WebProcessProxy::BeginsUsingDataStore::Yes);
    840846    m_process->addMessageReceiver(Messages::WebPageProxy::messageReceiverName(), m_webPageID, *this);
     847
     848#if ENABLE(IPC_TESTING_API)
     849    if (m_preferences->store().getBoolValueForKey(WebPreferencesKey::ipcTestingAPIEnabledKey()))
     850        m_process->setIgnoreInvalidMessageForTesting();
     851#endif
    841852
    842853    finishAttachingToWebProcess(reason);
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.cpp

    r268486 r268497  
    881881    WebProcessPool::didReceiveInvalidMessage(messageName);
    882882
     883#if ENABLE(IPC_TESTING_API)
     884    if (connection.ignoreInvalidMessageForTesting())
     885        return;
     886#endif
     887
    883888    // Terminate the WebContent process.
    884889    terminate();
     
    956961}
    957962
     963#if ENABLE(IPC_TESTING_API)
     964void WebProcessProxy::setIgnoreInvalidMessageForTesting()
     965{
     966    if (state() == State::Running)
     967        connection()->setIgnoreInvalidMessageForTesting();
     968    m_ignoreInvalidMessageForTesting = true;
     969}
     970#endif
     971
    958972void WebProcessProxy::didFinishLaunching(ProcessLauncher* launcher, IPC::Connection::Identifier connectionIdentifier)
    959973{
     
    979993    m_processPool->processDidFinishLaunching(this);
    980994    m_backgroundResponsivenessTimer.updateState();
     995
     996#if ENABLE(IPC_TESTING_API)
     997    if (m_ignoreInvalidMessageForTesting)
     998        connection()->setIgnoreInvalidMessageForTesting();
     999#endif
    9811000
    9821001#if PLATFORM(IOS_FAMILY)
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.h

    r268458 r268497  
    391391#endif
    392392
     393#if ENABLE(IPC_TESTING_API)
     394    void setIgnoreInvalidMessageForTesting();
     395#endif
     396
    393397protected:
    394398    WebProcessProxy(WebProcessPool&, WebsiteDataStore*, IsPrewarmed);
     
    621625
    622626    ShutdownPreventingScopeCounter m_shutdownPreventingScopeCounter;
     627
     628#if ENABLE(IPC_TESTING_API)
     629    bool m_ignoreInvalidMessageForTesting { false };
     630#endif
    623631};
    624632
  • trunk/Tools/ChangeLog

    r268496 r268497  
     12020-10-14  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Enabling IPC testing API should prevent the termination of WebContent process which sends an invalid IPC
     4        https://bugs.webkit.org/show_bug.cgi?id=217698
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Added regression tests.
     9
     10        * TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm:
     11        (IPCTestingAPI.CanSendInvalidAsyncMessageWithoutTermination):
     12        (IPCTestingAPI.CanSendInvalidMessageWithoutTermination):
     13
    1142020-10-14  Aakash Jain  <aakash_jain@apple.com>
    215
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/IPCTestingAPI.mm

    r268486 r268497  
    8888}
    8989
     90TEST(IPCTestingAPI, CanSendInvalidAsyncMessageWithoutTermination)
     91{
     92    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     93    for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
     94        if ([feature.key isEqualToString:@"IPCTestingAPIEnabled"]) {
     95            [[configuration preferences] _setEnabled:YES forInternalDebugFeature:feature];
     96            break;
     97        }
     98    }
     99    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
     100
     101    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     102    [webView setUIDelegate:delegate.get()];
     103
     104    done = false;
     105    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>"
     106        "IPC.sendMessage('UI', IPC.webPageProxyID, IPC.messages.WebPageProxy_ShowShareSheet.name, []);"
     107        "alert('hi')</script>"];
     108    TestWebKitAPI::Util::run(&done);
     109
     110    EXPECT_STREQ([alertMessage UTF8String], "hi");
     111}
     112
     113TEST(IPCTestingAPI, CanSendInvalidMessageWithoutTermination)
     114{
     115    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     116    for (_WKInternalDebugFeature *feature in [WKPreferences _internalDebugFeatures]) {
     117        if ([feature.key isEqualToString:@"IPCTestingAPIEnabled"]) {
     118            [[configuration preferences] _setEnabled:YES forInternalDebugFeature:feature];
     119            break;
     120        }
     121    }
     122    RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration.get()]);
     123
     124    auto delegate = adoptNS([[IPCTestingAPIDelegate alloc] init]);
     125    [webView setUIDelegate:delegate.get()];
     126
     127    done = false;
     128    [webView synchronouslyLoadHTMLString:@"<!DOCTYPE html><script>"
     129        "IPC.sendSyncMessage('UI', IPC.webPageProxyID, IPC.messages.WebPageProxy_RunJavaScriptAlert.name, 100, [{type: 'uint64_t', value: IPC.frameID}]);"
     130        "alert('hi')</script>"];
     131    TestWebKitAPI::Util::run(&done);
     132
     133    EXPECT_STREQ([alertMessage UTF8String], "hi");
     134}
     135
    90136#endif
Note: See TracChangeset for help on using the changeset viewer.