Title: [281965] trunk
Revision
281965
Author
[email protected]
Date
2021-09-02 16:25:16 -0700 (Thu, 02 Sep 2021)

Log Message

Gracefully recover from WebAuthnProcess crashes
https://bugs.webkit.org/show_bug.cgi?id=229828
Source/WebKit:

<rdar://82682650>

Patch by Alex Christensen <[email protected]> on 2021-09-02
Reviewed by Chris Dumez.

When a WebAuthn process closes, it can't be connected with again, which causes persistent web process "crashes".
Let's start a new process when this happens instead.

* UIProcess/API/Cocoa/WKProcessPool.mm:
(+[WKProcessPool _webAuthnProcessIdentifier]):
* UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
* UIProcess/WebAuthentication/WebAuthnProcessProxy.cpp:
(WebKit::sharedProcess):
(WebKit::WebAuthnProcessProxy::singleton):
(WebKit::WebAuthnProcessProxy::webAuthnProcessCrashed):

Tools:

Patch by Alex Christensen <[email protected]> on 2021-09-02
Reviewed by Chris Dumez.

* TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (281964 => 281965)


--- trunk/Source/WebKit/ChangeLog	2021-09-02 23:21:24 UTC (rev 281964)
+++ trunk/Source/WebKit/ChangeLog	2021-09-02 23:25:16 UTC (rev 281965)
@@ -1,3 +1,22 @@
+2021-09-02  Alex Christensen  <[email protected]>
+
+        Gracefully recover from WebAuthnProcess crashes
+        https://bugs.webkit.org/show_bug.cgi?id=229828
+        <rdar://82682650>
+
+        Reviewed by Chris Dumez.
+
+        When a WebAuthn process closes, it can't be connected with again, which causes persistent web process "crashes".
+        Let's start a new process when this happens instead.
+
+        * UIProcess/API/Cocoa/WKProcessPool.mm:
+        (+[WKProcessPool _webAuthnProcessIdentifier]):
+        * UIProcess/API/Cocoa/WKProcessPoolPrivate.h:
+        * UIProcess/WebAuthentication/WebAuthnProcessProxy.cpp:
+        (WebKit::sharedProcess):
+        (WebKit::WebAuthnProcessProxy::singleton):
+        (WebKit::WebAuthnProcessProxy::webAuthnProcessCrashed):
+
 2021-09-02  Chris Dumez  <[email protected]>
 
         [ BigSur arm64 Debug EWS ] ASSERTION FAILED: m_uncommittedState.state == State::Provisional

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (281964 => 281965)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2021-09-02 23:21:24 UTC (rev 281964)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2021-09-02 23:25:16 UTC (rev 281965)
@@ -38,6 +38,7 @@
 #import "WKObject.h"
 #import "WKWebViewInternal.h"
 #import "WKWebsiteDataStoreInternal.h"
+#import "WebAuthnProcessProxy.h"
 #import "WebBackForwardCache.h"
 #import "WebCertificateInfo.h"
 #import "WebCookieManagerProxy.h"
@@ -196,6 +197,15 @@
     return [url URLByAppendingPathComponent:@"WebsiteData" isDirectory:YES];
 }
 
++ (pid_t)_webAuthnProcessIdentifier
+{
+#if ENABLE(WEB_AUTHN)
+    return WebKit::WebAuthnProcessProxy::singleton().processIdentifier();
+#else
+    return 0;
+#endif
+}
+
 - (void)_setAllowsSpecificHTTPSCertificate:(NSArray *)certificateChain forHost:(NSString *)host
 {
 }

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (281964 => 281965)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2021-09-02 23:21:24 UTC (rev 281964)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2021-09-02 23:25:16 UTC (rev 281965)
@@ -71,6 +71,7 @@
 
 + (NSURL *)_websiteDataURLForContainerWithURL:(NSURL *)containerURL;
 + (NSURL *)_websiteDataURLForContainerWithURL:(NSURL *)containerURL bundleIdentifierIfNotInContainer:(NSString *)bundleIdentifier;
++ (pid_t)_webAuthnProcessIdentifier WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 - (void)_warmInitialProcess WK_API_AVAILABLE(macos(10.12), ios(10.0));
 - (void)_automationCapabilitiesDidChange WK_API_AVAILABLE(macos(10.12), ios(10.0));

Modified: trunk/Source/WebKit/UIProcess/WebAuthentication/WebAuthnProcessProxy.cpp (281964 => 281965)


--- trunk/Source/WebKit/UIProcess/WebAuthentication/WebAuthnProcessProxy.cpp	2021-09-02 23:21:24 UTC (rev 281964)
+++ trunk/Source/WebKit/UIProcess/WebAuthentication/WebAuthnProcessProxy.cpp	2021-09-02 23:25:16 UTC (rev 281965)
@@ -51,24 +51,30 @@
 namespace WebKit {
 using namespace WebCore;
 
+static RefPtr<WebAuthnProcessProxy>& sharedProcess()
+{
+    static NeverDestroyed<RefPtr<WebAuthnProcessProxy>> process;
+    return process.get();
+}
+
 WebAuthnProcessProxy& WebAuthnProcessProxy::singleton()
 {
     ASSERT(RunLoop::isMain());
 
-    static std::once_flag onceFlag;
-    static LazyNeverDestroyed<Ref<WebAuthnProcessProxy>> webAuthnProcess;
+    auto createAndInitializeNewProcess = [] {
+        auto webAuthnProcess = adoptRef(*new WebAuthnProcessProxy);
 
-    std::call_once(onceFlag, [] {
-        webAuthnProcess.construct(adoptRef(*new WebAuthnProcessProxy));
-
         WebAuthnProcessCreationParameters parameters;
 
         // Initialize the WebAuthn process.
-        webAuthnProcess.get()->send(Messages::WebAuthnProcess::InitializeWebAuthnProcess(parameters), 0);
-        webAuthnProcess.get()->updateProcessAssertion();
-    });
+        webAuthnProcess->send(Messages::WebAuthnProcess::InitializeWebAuthnProcess(parameters), 0);
+        webAuthnProcess->updateProcessAssertion();
+        return webAuthnProcess;
+    };
 
-    return webAuthnProcess.get();
+    if (!sharedProcess())
+        sharedProcess() = createAndInitializeNewProcess();
+    return *sharedProcess();
 }
 
 WebAuthnProcessProxy::WebAuthnProcessProxy()
@@ -118,6 +124,7 @@
 {
     for (auto& processPool : WebProcessPool::allProcessPools())
         processPool->terminateAllWebContentProcesses();
+    sharedProcess() = nullptr;
 }
 
 void WebAuthnProcessProxy::didClose(IPC::Connection&)

Modified: trunk/Tools/ChangeLog (281964 => 281965)


--- trunk/Tools/ChangeLog	2021-09-02 23:21:24 UTC (rev 281964)
+++ trunk/Tools/ChangeLog	2021-09-02 23:25:16 UTC (rev 281965)
@@ -1,5 +1,15 @@
 2021-09-02  Alex Christensen  <[email protected]>
 
+        Gracefully recover from WebAuthnProcess crashes
+        https://bugs.webkit.org/show_bug.cgi?id=229828
+
+        Reviewed by Chris Dumez.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
+        (TestWebKitAPI::TEST):
+
+2021-09-02  Alex Christensen  <[email protected]>
+
         Reject non-IPv4 hostnames that end in numbers
         https://bugs.webkit.org/show_bug.cgi?id=228826
 

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm (281964 => 281965)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm	2021-09-02 23:21:24 UTC (rev 281964)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm	2021-09-02 23:25:16 UTC (rev 281965)
@@ -37,6 +37,7 @@
 #import <WebCore/PublicKeyCredentialCreationOptions.h>
 #import <WebCore/PublicKeyCredentialRequestOptions.h>
 #import <WebKit/WKPreferencesPrivate.h>
+#import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKUIDelegatePrivate.h>
 #import <WebKit/_WKAuthenticationExtensionsClientInputs.h>
 #import <WebKit/_WKAuthenticationExtensionsClientOutputs.h>
@@ -2057,6 +2058,32 @@
 }
 #endif // USE(APPLE_INTERNAL_SDK) || PLATFORM(IOS)
 
+TEST(WebAuthenticationPanel, RecoverAfterAuthNProcessCrash)
+{
+    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+    [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
+    [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationModernExperimentalFeature()];
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration]);
+    EXPECT_EQ([WKProcessPool _webAuthnProcessIdentifier], 0);
+    [webView objectByEvaluatingJavaScript:@"internals.setMockWebAuthenticationConfiguration({ })"];
+    auto firstWebPID = [webView _webProcessIdentifier];
+    auto firstWebAuthnPID = [WKProcessPool _webAuthnProcessIdentifier];
+    EXPECT_NE(firstWebPID, 0);
+    EXPECT_NE(firstWebAuthnPID, 0);
+
+    kill(firstWebAuthnPID, SIGKILL);
+    while ([WKProcessPool _webAuthnProcessIdentifier] || [webView _webProcessIdentifier])
+        Util::spinRunLoop();
+    [webView objectByEvaluatingJavaScript:@"internals.setMockWebAuthenticationConfiguration({ })"];
+    auto secondWebPID = [webView _webProcessIdentifier];
+    auto secondWebAuthnPID = [WKProcessPool _webAuthnProcessIdentifier];
+    EXPECT_NE(secondWebAuthnPID, 0);
+    EXPECT_NE(secondWebAuthnPID, firstWebAuthnPID);
+    EXPECT_NE(secondWebPID, 0);
+    EXPECT_NE(secondWebPID, firstWebPID);
+}
+
 } // namespace TestWebKitAPI
 
 #endif // ENABLE(WEB_AUTHN)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to