Title: [128003] trunk
Revision
128003
Author
[email protected]
Date
2012-09-09 15:48:00 -0700 (Sun, 09 Sep 2012)

Log Message

Switch to entering the sandbox directly from main(), rather than waiting for the initialization message
https://bugs.webkit.org/show_bug.cgi?id=96194

Reviewed by Dan Bernstein.

Source/WebKit2: 

* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::ProcessLauncher::launchProcess):
Pass a client identifier to WebProcess as a command line argument
so that it can be used to create private temporary and cache directories.

* WebProcess/WebProcess.h:
(WebProcess):
* WebProcess/mac/WebProcessMac.mm:
(WebKit::WebProcess::initializeSandbox):
(WebKit::WebProcess::platformInitializeWebProcess):
Expose the initializeSandbox() function and stop calling it from platformInitializeWebProcess()
since it is now going to be called from WebProcessMain.  Also, move changing the current working
directory to sandbox initialization function and replace use of creation parameters with just
the client identifier.

* WebProcess/com.apple.WebProcess.sb.in:
Add some new exceptions that come from entering the sandbox earlier in the AppKit
initialization process. Don't allow access to com.apple.coreservices.appleevents.

* WebProcess/mac/WebProcessMainMac.mm:
(WebKit::WebProcessMainXPC):
(WebKit::WebProcessMain):
Enter the sandbox explicitly, not waiting until the initialization message.  Also,
since we now have an extra parameter for the client identifier, make the WebProcess
launches the UIProcess code path work by extracting a client identifier from the 
client executable path.

WebKitLibraries: 

Update WKSI with SPI for getting the bundle URL from an executable URL.

* WebKitSystemInterface.h:
* libWebKitSystemInterfaceLion.a:
* libWebKitSystemInterfaceMountainLion.a:
* libWebKitSystemInterfaceSnowLeopard.a:
Adds WKCopyBundleURLForExecutableURL().

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (128002 => 128003)


--- trunk/Source/WebKit2/ChangeLog	2012-09-09 22:26:52 UTC (rev 128002)
+++ trunk/Source/WebKit2/ChangeLog	2012-09-09 22:48:00 UTC (rev 128003)
@@ -1,3 +1,37 @@
+2012-09-08  Sam Weinig  <[email protected]>
+
+        Switch to entering the sandbox directly from main(), rather than waiting for the initialization message
+        https://bugs.webkit.org/show_bug.cgi?id=96194
+
+        Reviewed by Dan Bernstein.
+
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::ProcessLauncher::launchProcess):
+        Pass a client identifier to WebProcess as a command line argument
+        so that it can be used to create private temporary and cache directories.
+
+        * WebProcess/WebProcess.h:
+        (WebProcess):
+        * WebProcess/mac/WebProcessMac.mm:
+        (WebKit::WebProcess::initializeSandbox):
+        (WebKit::WebProcess::platformInitializeWebProcess):
+        Expose the initializeSandbox() function and stop calling it from platformInitializeWebProcess()
+        since it is now going to be called from WebProcessMain.  Also, move changing the current working
+        directory to sandbox initialization function and replace use of creation parameters with just
+        the client identifier.
+
+        * WebProcess/com.apple.WebProcess.sb.in:
+        Add some new exceptions that come from entering the sandbox earlier in the AppKit
+        initialization process. Don't allow access to com.apple.coreservices.appleevents.
+
+        * WebProcess/mac/WebProcessMainMac.mm:
+        (WebKit::WebProcessMainXPC):
+        (WebKit::WebProcessMain):
+        Enter the sandbox explicitly, not waiting until the initialization message.  Also,
+        since we now have an extra parameter for the client identifier, make the WebProcess
+        launches the UIProcess code path work by extracting a client identifier from the 
+        client executable path.
+
 2012-09-09  Patrick Gansterer  <[email protected]>
 
         Make the String initialization on the function side of String::number()

Modified: trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm (128002 => 128003)


--- trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2012-09-09 22:26:52 UTC (rev 128002)
+++ trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm	2012-09-09 22:48:00 UTC (rev 128003)
@@ -222,11 +222,14 @@
 
         RetainPtr<CFStringRef> cfLocalization(AdoptCF, WKCopyCFLocalizationPreferredName(NULL));
         CString localization = String(cfLocalization.get()).utf8();
-        
+
+        NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
+        CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
+
         // Make a unique, per pid, per process launcher web process service name.
         CString serviceName = String::format("com.apple.WebKit.WebProcess-%d-%p", getpid(), this).utf8();
 
-        const char* args[] = { [processAppExecutablePath fileSystemRepresentation], frameworkExecutablePath, "-type", processTypeAsString(m_launchOptions.processType), "-servicename", serviceName.data(), "-localization", localization.data(), 0 };
+        const char* args[] = { [processAppExecutablePath fileSystemRepresentation], frameworkExecutablePath, "-type", processTypeAsString(m_launchOptions.processType), "-servicename", serviceName.data(), "-localization", localization.data(), "-client-identifier", clientIdentifier.data(), 0 };
 
         // Register ourselves.
         kern_return_t kr = bootstrap_register2(bootstrap_port, const_cast<char*>(serviceName.data()), listeningPort, 0);

Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (128002 => 128003)


--- trunk/Source/WebKit2/WebProcess/WebProcess.h	2012-09-09 22:26:52 UTC (rev 128002)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h	2012-09-09 22:48:00 UTC (rev 128003)
@@ -128,6 +128,7 @@
 
 #if PLATFORM(MAC)
     void initializeShim();
+    void initializeSandbox(const String& clientIdentifier);
 
 #if USE(ACCELERATED_COMPOSITING)
     mach_port_t compositingRenderServerPort() const { return m_compositingRenderServerPort; }

Modified: trunk/Source/WebKit2/WebProcess/com.apple.WebProcess.sb.in (128002 => 128003)


--- trunk/Source/WebKit2/WebProcess/com.apple.WebProcess.sb.in	2012-09-09 22:26:52 UTC (rev 128002)
+++ trunk/Source/WebKit2/WebProcess/com.apple.WebProcess.sb.in	2012-09-09 22:48:00 UTC (rev 128003)
@@ -51,6 +51,7 @@
        (home-literal "/Library/Preferences/com.apple.WebFoundation.plist")
        (home-literal "/Library/Preferences/com.apple.security.plist")
        (home-literal "/Library/Preferences/com.apple.security.revocation.plist")
+       (home-literal "/Library/Preferences/com.apple.speech.recognition.AppleSpeechRecognition.prefs.plist")
        (home-literal "/Library/Application Support/SyncServices/Local/ClientsWithChanges/com.apple.Keychain")
        (home-regex #"/Library/Preferences/com\.apple\.driver\.(AppleBluetoothMultitouch\.mouse|AppleBluetoothMultitouch\.trackpad|AppleHIDMouse)\.plist$")
 
@@ -70,7 +71,9 @@
        (subpath "/Library/Video/Plug-Ins")
        (subpath "/Library/QuickTime")
 
-       (home-subpath "/Library/Dictionaries"))
+       (home-subpath "/Library/Dictionaries")
+       (home-subpath "/Library/Keyboard Layouts")
+       (home-subpath "/Library/Input Methods"))
 
 ;; This should be updated when <rdar://problem/9355830> is fixed.
 ;; Read-only extensions from UIProcess
@@ -147,6 +150,7 @@
        (global-name "com.apple.windowserver.active")
        (global-name "com.apple.cfnetwork.AuthBrokerAgent")
        (global-name "com.apple.PowerManagement.control")
+       (global-name "com.apple.speech.recognitionserver")
 
        ;; FIXME: This should be removed when <rdar://problem/9276393> is fixed.
        (global-name "com.apple.metadata.mds"))
@@ -187,3 +191,6 @@
        ;; FIXME: Should be removed after <rdar://problem/10463881> is fixed.
        (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2")
        (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2-journal"))
+
+(deny mach-lookup (with no-log)
+       (global-name "com.apple.coreservices.appleevents"))

Modified: trunk/Source/WebKit2/WebProcess/mac/WebProcessMac.mm (128002 => 128003)


--- trunk/Source/WebKit2/WebProcess/mac/WebProcessMac.mm	2012-09-09 22:26:52 UTC (rev 128002)
+++ trunk/Source/WebKit2/WebProcess/mac/WebProcessMac.mm	2012-09-09 22:48:00 UTC (rev 128003)
@@ -180,8 +180,10 @@
 
 #endif
 
-static void initializeSandbox(const WebProcessCreationParameters& parameters)
+void WebProcess::initializeSandbox(const String& clientIdentifier)
 {
+    [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] bundlePath]];
+
 #if ENABLE(WEB_PROCESS_SANDBOX)
 
 #if DEBUG_BYPASS_SANDBOX
@@ -191,7 +193,7 @@
 
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
     // Use private temporary and cache directories.
-    String systemDirectorySuffix = "com.apple.WebProcess+" + parameters.uiProcessBundleIdentifier;
+    String systemDirectorySuffix = "com.apple.WebProcess+" + clientIdentifier;
     setenv("DIRHELPER_USER_DIR_SUFFIX", fileSystemRepresentation(systemDirectorySuffix).data(), 0);
     char temporaryDirectory[PATH_MAX];
     if (!confstr(_CS_DARWIN_USER_TEMP_DIR, temporaryDirectory, sizeof(temporaryDirectory))) {
@@ -248,10 +250,6 @@
     
 void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::ArgumentDecoder*)
 {
-    [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] bundlePath]];
-
-    initializeSandbox(parameters);
-
     SandboxExtension::consumePermanently(parameters.uiProcessBundleResourcePathExtensionHandle);
     SandboxExtension::consumePermanently(parameters.localStorageDirectoryExtensionHandle);
     SandboxExtension::consumePermanently(parameters.databaseDirectoryExtensionHandle);

Modified: trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm (128002 => 128003)


--- trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm	2012-09-09 22:26:52 UTC (rev 128002)
+++ trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm	2012-09-09 22:48:00 UTC (rev 128003)
@@ -29,6 +29,7 @@
 #import "CommandLine.h"
 #import "EnvironmentUtilities.h"
 #import "EnvironmentVariables.h"
+#import "StringUtilities.h"
 #import "WebProcess.h"
 #import "WebSystemInterface.h"
 #import <WebCore/RunLoop.h>
@@ -93,11 +94,10 @@
     WTF::initializeMainThread();
     RunLoop::initializeMainRunLoop();
 
-    // Initialize the shim.
     // FIXME: Make the shim work.
     WebProcess::shared().initializeShim();
-
-    // Create the connection.
+    // FIXME: Pass the client identifier here.
+    WebProcess::shared().initializeSandbox(String());
     WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort, xpcConnection), RunLoop::main());
 
     WKAXRegisterRemoteApp();
@@ -125,6 +125,8 @@
     if (serviceName.isEmpty() && clientExecutable.isEmpty())
         return EXIT_FAILURE;
 
+    String clientIdentifier;
+
     // Get the server port.
     mach_port_t serverPort;
     if (clientExecutable.isEmpty()) {
@@ -133,6 +135,12 @@
             WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr);
             return 2;
         }
+        
+        clientIdentifier = commandLine["client-identifier"];
+        if (!clientIdentifier) {
+            WTFLogAlways("No client identifier passed to the WebProcess");
+            return EXIT_FAILURE;
+        }
     }
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     else {
@@ -185,6 +193,16 @@
             WTFLogAlways("Failed to obtain send right for port received from the UI process.\n");
             return EXIT_FAILURE;
         }
+
+        RetainPtr<NSURL> clientExecutableURL = adoptNS([[NSURL alloc] initFileURLWithPath:nsStringFromWebCoreString(clientExecutable)]);
+        RetainPtr<CFURLRef> clientBundleURL = adoptCF(WKCopyBundleURLForExecutableURL((CFURLRef)clientExecutableURL.get()));
+        RetainPtr<NSBundle> clientBundle = adoptNS([[NSBundle alloc] initWithURL:(NSURL *)clientBundleURL.get()]);
+        
+        clientIdentifier = [clientBundle.get() bundleIdentifier];
+        if (!clientIdentifier) {
+            WTFLogAlways("Failed to obtain bundle identifier from the client executable. .\n");
+            return EXIT_FAILURE;
+        }
     }
 #endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
 
@@ -206,14 +224,6 @@
     WTF::initializeMainThread();
     RunLoop::initializeMainRunLoop();
 
-    // Initialize the shim.
-    WebProcess::shared().initializeShim();
-
-    // Create the connection.
-    WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort), RunLoop::main());
-
-    [pool drain];
-
 #if USE(APPKIT)
      // Initialize AppKit.
     [NSApplication sharedApplication];
@@ -223,8 +233,14 @@
     [[NSApplication sharedApplication] _installAutoreleasePoolsOnCurrentThreadIfNecessary];
 #endif
 
+    WebProcess::shared().initializeShim();
+    WebProcess::shared().initializeSandbox(clientIdentifier);
+    WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort), RunLoop::main());
+
     WKAXRegisterRemoteApp();
-    
+
+    [pool drain];
+
     RunLoop::run();
 
     // FIXME: Do more cleanup here.

Modified: trunk/Tools/Scripts/run-test-webkit-api (128002 => 128003)


--- trunk/Tools/Scripts/run-test-webkit-api	2012-09-09 22:26:52 UTC (rev 128002)
+++ trunk/Tools/Scripts/run-test-webkit-api	2012-09-09 22:48:00 UTC (rev 128003)
@@ -26,7 +26,7 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-# Simplified "run" script for launching the WebKit2 estWebKitAPI.
+# Simplified "run" script for launching TestWebKitAPI.
 
 use strict;
 use FindBin;

Modified: trunk/WebKitLibraries/ChangeLog (128002 => 128003)


--- trunk/WebKitLibraries/ChangeLog	2012-09-09 22:26:52 UTC (rev 128002)
+++ trunk/WebKitLibraries/ChangeLog	2012-09-09 22:48:00 UTC (rev 128003)
@@ -1,3 +1,18 @@
+2012-09-08  Sam Weinig  <[email protected]>
+
+        Switch to entering the sandbox directly from main(), rather than waiting for the initialization message
+        https://bugs.webkit.org/show_bug.cgi?id=96194
+
+        Reviewed by Dan Bernstein.
+
+        Update WKSI with SPI for getting the bundle URL from an executable URL.
+
+        * WebKitSystemInterface.h:
+        * libWebKitSystemInterfaceLion.a:
+        * libWebKitSystemInterfaceMountainLion.a:
+        * libWebKitSystemInterfaceSnowLeopard.a:
+        Adds WKCopyBundleURLForExecutableURL().
+
 2012-08-29  Tony Chang  <[email protected]>
 
         Remove ENABLE_CSS3_FLEXBOX compile time flag

Modified: trunk/WebKitLibraries/WebKitSystemInterface.h (128002 => 128003)


--- trunk/WebKitLibraries/WebKitSystemInterface.h	2012-09-09 22:26:52 UTC (rev 128002)
+++ trunk/WebKitLibraries/WebKitSystemInterface.h	2012-09-09 22:48:00 UTC (rev 128003)
@@ -249,6 +249,8 @@
 
 void WKSetVisibleApplicationName(CFStringRef);
 
+CFURLRef WKCopyBundleURLForExecutableURL(CFURLRef);
+
 typedef enum {
     WKMediaUIPartFullscreenButton   = 0,
     WKMediaUIPartMuteButton,

Modified: trunk/WebKitLibraries/libWebKitSystemInterfaceLion.a


(Binary files differ)

Modified: trunk/WebKitLibraries/libWebKitSystemInterfaceMountainLion.a


(Binary files differ)

Modified: trunk/WebKitLibraries/libWebKitSystemInterfaceSnowLeopard.a


(Binary files differ)
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to