- Revision
- 275540
- Author
- [email protected]
- Date
- 2021-04-06 12:42:13 -0700 (Tue, 06 Apr 2021)
Log Message
Hold strong reference to xpc_connection_t in XPCServiceEventHandler
https://bugs.webkit.org/show_bug.cgi?id=224242
<rdar://74308418>
Patch by Alex Christensen <[email protected]> on 2021-04-06
Reviewed by David Kilzer.
There is a reasonable chance that by the time we get to the block of xpc_connection_set_event_handler
and back through WorkQueue::main().dispatchSync the xpc_connection_t has been freed.
Also, the adoption in each entry points was incorrect, causing a late overrelease when tearing down the process.
It was incorrect because we did not just create the connection or get it from any NS_RETURNS_RETAINED-like function.
It was causing rare crashes once everything else had released their hold on the connection.
* GPUProcess/EntryPoint/Cocoa/XPCService/GPUServiceEntryPoint.mm:
(GPU_SERVICE_INITIALIZER):
* NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkServiceEntryPoint.mm:
(NETWORK_SERVICE_INITIALIZER):
* PluginProcess/EntryPoint/Cocoa/XPCService/PluginServiceEntryPoint.mm:
(PLUGIN_SERVICE_INITIALIZER):
* Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
(WebKit::XPCServiceEventHandler):
* WebAuthnProcess/EntryPoint/Cocoa/XPCService/WebAuthnServiceEntryPoint.mm:
(WEBAUTHN_SERVICE_INITIALIZER):
* WebProcess/EntryPoint/Cocoa/XPCService/WebContentServiceEntryPoint.mm:
(WEBCONTENT_SERVICE_INITIALIZER):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (275539 => 275540)
--- trunk/Source/WebKit/ChangeLog 2021-04-06 19:41:12 UTC (rev 275539)
+++ trunk/Source/WebKit/ChangeLog 2021-04-06 19:42:13 UTC (rev 275540)
@@ -1,3 +1,31 @@
+2021-04-06 Alex Christensen <[email protected]>
+
+ Hold strong reference to xpc_connection_t in XPCServiceEventHandler
+ https://bugs.webkit.org/show_bug.cgi?id=224242
+ <rdar://74308418>
+
+ Reviewed by David Kilzer.
+
+ There is a reasonable chance that by the time we get to the block of xpc_connection_set_event_handler
+ and back through WorkQueue::main().dispatchSync the xpc_connection_t has been freed.
+
+ Also, the adoption in each entry points was incorrect, causing a late overrelease when tearing down the process.
+ It was incorrect because we did not just create the connection or get it from any NS_RETURNS_RETAINED-like function.
+ It was causing rare crashes once everything else had released their hold on the connection.
+
+ * GPUProcess/EntryPoint/Cocoa/XPCService/GPUServiceEntryPoint.mm:
+ (GPU_SERVICE_INITIALIZER):
+ * NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkServiceEntryPoint.mm:
+ (NETWORK_SERVICE_INITIALIZER):
+ * PluginProcess/EntryPoint/Cocoa/XPCService/PluginServiceEntryPoint.mm:
+ (PLUGIN_SERVICE_INITIALIZER):
+ * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
+ (WebKit::XPCServiceEventHandler):
+ * WebAuthnProcess/EntryPoint/Cocoa/XPCService/WebAuthnServiceEntryPoint.mm:
+ (WEBAUTHN_SERVICE_INITIALIZER):
+ * WebProcess/EntryPoint/Cocoa/XPCService/WebContentServiceEntryPoint.mm:
+ (WEBCONTENT_SERVICE_INITIALIZER):
+
2021-04-06 Brent Fulgham <[email protected]>
[macOS] Allow access to 'com.apple.system.logger' in the Base System
Modified: trunk/Source/WebKit/GPUProcess/EntryPoint/Cocoa/XPCService/GPUServiceEntryPoint.mm (275539 => 275540)
--- trunk/Source/WebKit/GPUProcess/EntryPoint/Cocoa/XPCService/GPUServiceEntryPoint.mm 2021-04-06 19:41:12 UTC (rev 275539)
+++ trunk/Source/WebKit/GPUProcess/EntryPoint/Cocoa/XPCService/GPUServiceEntryPoint.mm 2021-04-06 19:42:13 UTC (rev 275540)
@@ -59,6 +59,6 @@
WTF::initializeMainThread();
#if ENABLE(GPU_PROCESS)
- WebKit::XPCServiceInitializer<WebKit::GPUProcess, WebKit::GPUServiceInitializerDelegate>(adoptOSObject(connection), initializerMessage, priorityBoostMessage);
+ WebKit::XPCServiceInitializer<WebKit::GPUProcess, WebKit::GPUServiceInitializerDelegate>(connection, initializerMessage, priorityBoostMessage);
#endif // ENABLE(GPU_PROCESS)
}
Modified: trunk/Source/WebKit/NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkServiceEntryPoint.mm (275539 => 275540)
--- trunk/Source/WebKit/NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkServiceEntryPoint.mm 2021-04-06 19:41:12 UTC (rev 275539)
+++ trunk/Source/WebKit/NetworkProcess/EntryPoint/Cocoa/XPCService/NetworkServiceEntryPoint.mm 2021-04-06 19:42:13 UTC (rev 275540)
@@ -55,5 +55,5 @@
void NETWORK_SERVICE_INITIALIZER(xpc_connection_t connection, xpc_object_t initializerMessage, xpc_object_t priorityBoostMessage)
{
WTF::initializeMainThread();
- XPCServiceInitializer<NetworkProcess, NetworkServiceInitializerDelegate>(adoptOSObject(connection), initializerMessage, priorityBoostMessage);
+ XPCServiceInitializer<NetworkProcess, NetworkServiceInitializerDelegate>(connection, initializerMessage, priorityBoostMessage);
}
Modified: trunk/Source/WebKit/PluginProcess/EntryPoint/Cocoa/XPCService/PluginServiceEntryPoint.mm (275539 => 275540)
--- trunk/Source/WebKit/PluginProcess/EntryPoint/Cocoa/XPCService/PluginServiceEntryPoint.mm 2021-04-06 19:41:12 UTC (rev 275539)
+++ trunk/Source/WebKit/PluginProcess/EntryPoint/Cocoa/XPCService/PluginServiceEntryPoint.mm 2021-04-06 19:42:13 UTC (rev 275540)
@@ -81,6 +81,6 @@
// Remove the PluginProcess shim from the DYLD_INSERT_LIBRARIES environment variable so any processes
// spawned by the PluginProcess don't try to insert the shim and crash.
EnvironmentUtilities::removeValuesEndingWith("DYLD_INSERT_LIBRARIES", "/PluginProcessShim.dylib");
- XPCServiceInitializer<PluginProcess, PluginServiceInitializerDelegate>(adoptOSObject(connection), initializerMessage, priorityBoostMessage);
+ XPCServiceInitializer<PluginProcess, PluginServiceInitializerDelegate>(connection, initializerMessage, priorityBoostMessage);
#endif // ENABLE(NETSCAPE_PLUGIN_API)
}
Modified: trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm (275539 => 275540)
--- trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm 2021-04-06 19:41:12 UTC (rev 275539)
+++ trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm 2021-04-06 19:42:13 UTC (rev 275540)
@@ -64,6 +64,8 @@
{
static NeverDestroyed<OSObjectPtr<xpc_object_t>> priorityBoostMessage;
+ OSObjectPtr<xpc_connection_t> retainedPeerConnection(peer);
+
xpc_connection_set_target_queue(peer, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0));
xpc_connection_set_event_handler(peer, ^(xpc_object_t event) {
xpc_type_t type = xpc_get_type(event);
@@ -117,8 +119,8 @@
if (fd != -1)
dup2(fd, STDERR_FILENO);
- WorkQueue::main().dispatchSync([&] {
- initializerFunctionPtr(peer, event, priorityBoostMessage.get().get());
+ WorkQueue::main().dispatchSync([initializerFunctionPtr, event = OSObjectPtr<xpc_object_t>(event), retainedPeerConnection] {
+ initializerFunctionPtr(retainedPeerConnection.get(), event.get(), priorityBoostMessage.get().get());
setAppleLanguagesPreference();
});
Modified: trunk/Source/WebKit/WebAuthnProcess/EntryPoint/Cocoa/XPCService/WebAuthnServiceEntryPoint.mm (275539 => 275540)
--- trunk/Source/WebKit/WebAuthnProcess/EntryPoint/Cocoa/XPCService/WebAuthnServiceEntryPoint.mm 2021-04-06 19:41:12 UTC (rev 275539)
+++ trunk/Source/WebKit/WebAuthnProcess/EntryPoint/Cocoa/XPCService/WebAuthnServiceEntryPoint.mm 2021-04-06 19:42:13 UTC (rev 275540)
@@ -59,6 +59,6 @@
WTF::initializeMainThread();
#if ENABLE(WEB_AUTHN)
- WebKit::XPCServiceInitializer<WebKit::WebAuthnProcess, WebKit::WebAuthnServiceInitializerDelegate>(adoptOSObject(connection), initializerMessage, priorityBoostMessage);
+ WebKit::XPCServiceInitializer<WebKit::WebAuthnProcess, WebKit::WebAuthnServiceInitializerDelegate>(connection, initializerMessage, priorityBoostMessage);
#endif // ENABLE(WEB_AUTHN)
}
Modified: trunk/Source/WebKit/WebProcess/EntryPoint/Cocoa/XPCService/WebContentServiceEntryPoint.mm (275539 => 275540)
--- trunk/Source/WebKit/WebProcess/EntryPoint/Cocoa/XPCService/WebContentServiceEntryPoint.mm 2021-04-06 19:41:12 UTC (rev 275539)
+++ trunk/Source/WebKit/WebProcess/EntryPoint/Cocoa/XPCService/WebContentServiceEntryPoint.mm 2021-04-06 19:42:13 UTC (rev 275540)
@@ -50,5 +50,5 @@
InitWebCoreThreadSystemInterface();
#endif // PLATFORM(IOS_FAMILY)
- WebKit::XPCServiceInitializer<WebKit::WebProcess, WebKit::XPCServiceInitializerDelegate>(adoptOSObject(connection), initializerMessage, priorityBoostMessage);
+ WebKit::XPCServiceInitializer<WebKit::WebProcess, WebKit::XPCServiceInitializerDelegate>(connection, initializerMessage, priorityBoostMessage);
}