Changeset 128003 in webkit


Ignore:
Timestamp:
Sep 9, 2012 3:48:00 PM (12 years ago)
Author:
weinig@apple.com
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().

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r127991 r128003  
     12012-09-08  Sam Weinig  <sam@webkit.org>
     2
     3        Switch to entering the sandbox directly from main(), rather than waiting for the initialization message
     4        https://bugs.webkit.org/show_bug.cgi?id=96194
     5
     6        Reviewed by Dan Bernstein.
     7
     8        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     9        (WebKit::ProcessLauncher::launchProcess):
     10        Pass a client identifier to WebProcess as a command line argument
     11        so that it can be used to create private temporary and cache directories.
     12
     13        * WebProcess/WebProcess.h:
     14        (WebProcess):
     15        * WebProcess/mac/WebProcessMac.mm:
     16        (WebKit::WebProcess::initializeSandbox):
     17        (WebKit::WebProcess::platformInitializeWebProcess):
     18        Expose the initializeSandbox() function and stop calling it from platformInitializeWebProcess()
     19        since it is now going to be called from WebProcessMain.  Also, move changing the current working
     20        directory to sandbox initialization function and replace use of creation parameters with just
     21        the client identifier.
     22
     23        * WebProcess/com.apple.WebProcess.sb.in:
     24        Add some new exceptions that come from entering the sandbox earlier in the AppKit
     25        initialization process. Don't allow access to com.apple.coreservices.appleevents.
     26
     27        * WebProcess/mac/WebProcessMainMac.mm:
     28        (WebKit::WebProcessMainXPC):
     29        (WebKit::WebProcessMain):
     30        Enter the sandbox explicitly, not waiting until the initialization message.  Also,
     31        since we now have an extra parameter for the client identifier, make the WebProcess
     32        launches the UIProcess code path work by extracting a client identifier from the
     33        client executable path.
     34
    1352012-09-09  Patrick Gansterer  <paroga@webkit.org>
    236
  • trunk/Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r125361 r128003  
    223223        RetainPtr<CFStringRef> cfLocalization(AdoptCF, WKCopyCFLocalizationPreferredName(NULL));
    224224        CString localization = String(cfLocalization.get()).utf8();
    225        
     225
     226        NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
     227        CString clientIdentifier = bundleIdentifier ? String([[NSBundle mainBundle] bundleIdentifier]).utf8() : *_NSGetProgname();
     228
    226229        // Make a unique, per pid, per process launcher web process service name.
    227230        CString serviceName = String::format("com.apple.WebKit.WebProcess-%d-%p", getpid(), this).utf8();
    228231
    229         const char* args[] = { [processAppExecutablePath fileSystemRepresentation], frameworkExecutablePath, "-type", processTypeAsString(m_launchOptions.processType), "-servicename", serviceName.data(), "-localization", localization.data(), 0 };
     232        const char* args[] = { [processAppExecutablePath fileSystemRepresentation], frameworkExecutablePath, "-type", processTypeAsString(m_launchOptions.processType), "-servicename", serviceName.data(), "-localization", localization.data(), "-client-identifier", clientIdentifier.data(), 0 };
    230233
    231234        // Register ourselves.
  • trunk/Source/WebKit2/WebProcess/WebProcess.h

    r127386 r128003  
    129129#if PLATFORM(MAC)
    130130    void initializeShim();
     131    void initializeSandbox(const String& clientIdentifier);
    131132
    132133#if USE(ACCELERATED_COMPOSITING)
  • trunk/Source/WebKit2/WebProcess/com.apple.WebProcess.sb.in

    r127384 r128003  
    5252       (home-literal "/Library/Preferences/com.apple.security.plist")
    5353       (home-literal "/Library/Preferences/com.apple.security.revocation.plist")
     54       (home-literal "/Library/Preferences/com.apple.speech.recognition.AppleSpeechRecognition.prefs.plist")
    5455       (home-literal "/Library/Application Support/SyncServices/Local/ClientsWithChanges/com.apple.Keychain")
    5556       (home-regex #"/Library/Preferences/com\.apple\.driver\.(AppleBluetoothMultitouch\.mouse|AppleBluetoothMultitouch\.trackpad|AppleHIDMouse)\.plist$")
     
    7172       (subpath "/Library/QuickTime")
    7273
    73        (home-subpath "/Library/Dictionaries"))
     74       (home-subpath "/Library/Dictionaries")
     75       (home-subpath "/Library/Keyboard Layouts")
     76       (home-subpath "/Library/Input Methods"))
    7477
    7578;; This should be updated when <rdar://problem/9355830> is fixed.
     
    148151       (global-name "com.apple.cfnetwork.AuthBrokerAgent")
    149152       (global-name "com.apple.PowerManagement.control")
     153       (global-name "com.apple.speech.recognitionserver")
    150154
    151155       ;; FIXME: This should be removed when <rdar://problem/9276393> is fixed.
     
    188192       (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2")
    189193       (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2-journal"))
     194
     195(deny mach-lookup (with no-log)
     196       (global-name "com.apple.coreservices.appleevents"))
  • trunk/Source/WebKit2/WebProcess/mac/WebProcessMac.mm

    r127384 r128003  
    181181#endif
    182182
    183 static void initializeSandbox(const WebProcessCreationParameters& parameters)
    184 {
     183void WebProcess::initializeSandbox(const String& clientIdentifier)
     184{
     185    [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] bundlePath]];
     186
    185187#if ENABLE(WEB_PROCESS_SANDBOX)
    186188
     
    192194#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
    193195    // Use private temporary and cache directories.
    194     String systemDirectorySuffix = "com.apple.WebProcess+" + parameters.uiProcessBundleIdentifier;
     196    String systemDirectorySuffix = "com.apple.WebProcess+" + clientIdentifier;
    195197    setenv("DIRHELPER_USER_DIR_SUFFIX", fileSystemRepresentation(systemDirectorySuffix).data(), 0);
    196198    char temporaryDirectory[PATH_MAX];
     
    249251void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters& parameters, CoreIPC::ArgumentDecoder*)
    250252{
    251     [[NSFileManager defaultManager] changeCurrentDirectoryPath:[[NSBundle mainBundle] bundlePath]];
    252 
    253     initializeSandbox(parameters);
    254 
    255253    SandboxExtension::consumePermanently(parameters.uiProcessBundleResourcePathExtensionHandle);
    256254    SandboxExtension::consumePermanently(parameters.localStorageDirectoryExtensionHandle);
  • trunk/Source/WebKit2/WebProcess/mac/WebProcessMainMac.mm

    r125944 r128003  
    3030#import "EnvironmentUtilities.h"
    3131#import "EnvironmentVariables.h"
     32#import "StringUtilities.h"
    3233#import "WebProcess.h"
    3334#import "WebSystemInterface.h"
     
    9495    RunLoop::initializeMainRunLoop();
    9596
    96     // Initialize the shim.
    9797    // FIXME: Make the shim work.
    9898    WebProcess::shared().initializeShim();
    99 
    100     // Create the connection.
     99    // FIXME: Pass the client identifier here.
     100    WebProcess::shared().initializeSandbox(String());
    101101    WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort, xpcConnection), RunLoop::main());
    102102
     
    125125    if (serviceName.isEmpty() && clientExecutable.isEmpty())
    126126        return EXIT_FAILURE;
     127
     128    String clientIdentifier;
    127129
    128130    // Get the server port.
     
    133135            WTFLogAlways("bootstrap_look_up result: %s (%x)\n", mach_error_string(kr), kr);
    134136            return 2;
     137        }
     138       
     139        clientIdentifier = commandLine["client-identifier"];
     140        if (!clientIdentifier) {
     141            WTFLogAlways("No client identifier passed to the WebProcess");
     142            return EXIT_FAILURE;
    135143        }
    136144    }
     
    186194            return EXIT_FAILURE;
    187195        }
     196
     197        RetainPtr<NSURL> clientExecutableURL = adoptNS([[NSURL alloc] initFileURLWithPath:nsStringFromWebCoreString(clientExecutable)]);
     198        RetainPtr<CFURLRef> clientBundleURL = adoptCF(WKCopyBundleURLForExecutableURL((CFURLRef)clientExecutableURL.get()));
     199        RetainPtr<NSBundle> clientBundle = adoptNS([[NSBundle alloc] initWithURL:(NSURL *)clientBundleURL.get()]);
     200       
     201        clientIdentifier = [clientBundle.get() bundleIdentifier];
     202        if (!clientIdentifier) {
     203            WTFLogAlways("Failed to obtain bundle identifier from the client executable. .\n");
     204            return EXIT_FAILURE;
     205        }
    188206    }
    189207#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
     
    207225    RunLoop::initializeMainRunLoop();
    208226
    209     // Initialize the shim.
    210     WebProcess::shared().initializeShim();
    211 
    212     // Create the connection.
    213     WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort), RunLoop::main());
    214 
    215     [pool drain];
    216 
    217227#if USE(APPKIT)
    218228     // Initialize AppKit.
     
    224234#endif
    225235
     236    WebProcess::shared().initializeShim();
     237    WebProcess::shared().initializeSandbox(clientIdentifier);
     238    WebProcess::shared().initialize(CoreIPC::Connection::Identifier(serverPort), RunLoop::main());
     239
    226240    WKAXRegisterRemoteApp();
    227    
     241
     242    [pool drain];
     243
    228244    RunLoop::run();
    229245
  • trunk/Tools/Scripts/run-test-webkit-api

    r103640 r128003  
    2727# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2828
    29 # Simplified "run" script for launching the WebKit2 estWebKitAPI.
     29# Simplified "run" script for launching TestWebKitAPI.
    3030
    3131use strict;
  • trunk/WebKitLibraries/ChangeLog

    r127318 r128003  
     12012-09-08  Sam Weinig  <sam@webkit.org>
     2
     3        Switch to entering the sandbox directly from main(), rather than waiting for the initialization message
     4        https://bugs.webkit.org/show_bug.cgi?id=96194
     5
     6        Reviewed by Dan Bernstein.
     7
     8        Update WKSI with SPI for getting the bundle URL from an executable URL.
     9
     10        * WebKitSystemInterface.h:
     11        * libWebKitSystemInterfaceLion.a:
     12        * libWebKitSystemInterfaceMountainLion.a:
     13        * libWebKitSystemInterfaceSnowLeopard.a:
     14        Adds WKCopyBundleURLForExecutableURL().
     15
    1162012-08-29  Tony Chang  <tony@chromium.org>
    217
  • trunk/WebKitLibraries/WebKitSystemInterface.h

    r124799 r128003  
    249249
    250250void WKSetVisibleApplicationName(CFStringRef);
     251
     252CFURLRef WKCopyBundleURLForExecutableURL(CFURLRef);
    251253
    252254typedef enum {
Note: See TracChangeset for help on using the changeset viewer.