Title: [282152] branches/safari-612-branch
Revision
282152
Author
repst...@apple.com
Date
2021-09-08 10:22:26 -0700 (Wed, 08 Sep 2021)

Log Message

Cherry-pick r281965. rdar://problem/82877374

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

    <rdar://82682650>

    Patch by Alex Christensen <achristen...@webkit.org> 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 <achristen...@webkit.org> on 2021-09-02
    Reviewed by Chris Dumez.

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

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281965 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-612-branch/Source/WebKit/ChangeLog (282151 => 282152)


--- branches/safari-612-branch/Source/WebKit/ChangeLog	2021-09-08 17:20:44 UTC (rev 282151)
+++ branches/safari-612-branch/Source/WebKit/ChangeLog	2021-09-08 17:22:26 UTC (rev 282152)
@@ -1,3 +1,56 @@
+2021-09-08  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r281965. rdar://problem/82877374
+
+    Gracefully recover from WebAuthnProcess crashes
+    https://bugs.webkit.org/show_bug.cgi?id=229828
+    Source/WebKit:
+    
+    <rdar://82682650>
+    
+    Patch by Alex Christensen <achristen...@webkit.org> 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 <achristen...@webkit.org> on 2021-09-02
+    Reviewed by Chris Dumez.
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
+    (TestWebKitAPI::TEST):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281965 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-02  Alex Christensen  <achristen...@webkit.org>
+
+            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-01  Russell Epstein  <repst...@apple.com>
 
         Cherry-pick r281817. rdar://problem/82652467

Modified: branches/safari-612-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm (282151 => 282152)


--- branches/safari-612-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2021-09-08 17:20:44 UTC (rev 282151)
+++ branches/safari-612-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPool.mm	2021-09-08 17:22:26 UTC (rev 282152)
@@ -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: branches/safari-612-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h (282151 => 282152)


--- branches/safari-612-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2021-09-08 17:20:44 UTC (rev 282151)
+++ branches/safari-612-branch/Source/WebKit/UIProcess/API/Cocoa/WKProcessPoolPrivate.h	2021-09-08 17:22:26 UTC (rev 282152)
@@ -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: branches/safari-612-branch/Source/WebKit/UIProcess/WebAuthentication/WebAuthnProcessProxy.cpp (282151 => 282152)


--- branches/safari-612-branch/Source/WebKit/UIProcess/WebAuthentication/WebAuthnProcessProxy.cpp	2021-09-08 17:20:44 UTC (rev 282151)
+++ branches/safari-612-branch/Source/WebKit/UIProcess/WebAuthentication/WebAuthnProcessProxy.cpp	2021-09-08 17:22:26 UTC (rev 282152)
@@ -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: branches/safari-612-branch/Tools/ChangeLog (282151 => 282152)


--- branches/safari-612-branch/Tools/ChangeLog	2021-09-08 17:20:44 UTC (rev 282151)
+++ branches/safari-612-branch/Tools/ChangeLog	2021-09-08 17:22:26 UTC (rev 282152)
@@ -1,3 +1,47 @@
+2021-09-08  Alan Coon  <alanc...@apple.com>
+
+        Cherry-pick r281965. rdar://problem/82877374
+
+    Gracefully recover from WebAuthnProcess crashes
+    https://bugs.webkit.org/show_bug.cgi?id=229828
+    Source/WebKit:
+    
+    <rdar://82682650>
+    
+    Patch by Alex Christensen <achristen...@webkit.org> 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 <achristen...@webkit.org> on 2021-09-02
+    Reviewed by Chris Dumez.
+    
+    * TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
+    (TestWebKitAPI::TEST):
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@281965 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2021-09-02  Alex Christensen  <achristen...@webkit.org>
+
+            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-01  Russell Epstein  <repst...@apple.com>
 
         Cherry-pick r281817. rdar://problem/82652467

Modified: branches/safari-612-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm (282151 => 282152)


--- branches/safari-612-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm	2021-09-08 17:20:44 UTC (rev 282151)
+++ branches/safari-612-branch/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm	2021-09-08 17:22:26 UTC (rev 282152)
@@ -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
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to