Fix for <rdar://problem/8711576> The web process should be able to read resources...
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jan 2011 22:39:30 +0000 (22:39 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 14 Jan 2011 22:39:30 +0000 (22:39 +0000)
Reviewed by Sam Weinig.

Based on a patch by Ivan Krstić. This also makes the NSURLCache path a sandbox parameter.

* Shared/WebProcessCreationParameters.cpp:
(WebKit::WebProcessCreationParameters::encode):
(WebKit::WebProcessCreationParameters::decode):
Encode and decode the uiProcessBundleResourcePath member variable.

* Shared/WebProcessCreationParameters.h:
Add uiProcessBundleResourcePath member variable.

* UIProcess/mac/WebContextMac.mm:
(WebKit::WebContext::platformInitializeWebProcess):
Set the uiProcessBundleResourcePath member variable.

* WebProcess/com.apple.WebProcess.sb:
Allow read-only access to UI_PROCESS_BUNDLE_RESOURCE_DIR and all subdirectories.

* WebProcess/mac/WebProcessMac.mm:
(WebKit::initializeSandbox):
When initializing the sandbox, pass UI_PROCESS_BUNDLE_RESOURCE_DIR.

(WebKit::WebProcess::platformInitializeWebProcess):
Remove the code that would consume a sandbox extension for the url cache path.

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

WebKit2/ChangeLog
WebKit2/Shared/WebProcessCreationParameters.cpp
WebKit2/Shared/WebProcessCreationParameters.h
WebKit2/UIProcess/mac/WebContextMac.mm
WebKit2/WebProcess/com.apple.WebProcess.sb
WebKit2/WebProcess/mac/WebProcessMac.mm

index dd18486..285b8de 100644 (file)
@@ -2,6 +2,36 @@
 
         Reviewed by Sam Weinig.
 
+        Fix for <rdar://problem/8711576> The web process should be able to read resources from the UI process.
+
+        Based on a patch by Ivan Krstić. This also makes the NSURLCache path a sandbox parameter.
+
+        * Shared/WebProcessCreationParameters.cpp:
+        (WebKit::WebProcessCreationParameters::encode):
+        (WebKit::WebProcessCreationParameters::decode):
+        Encode and decode the uiProcessBundleResourcePath member variable.
+
+        * Shared/WebProcessCreationParameters.h:
+        Add uiProcessBundleResourcePath member variable.
+
+        * UIProcess/mac/WebContextMac.mm:
+        (WebKit::WebContext::platformInitializeWebProcess):
+        Set the uiProcessBundleResourcePath member variable.
+
+        * WebProcess/com.apple.WebProcess.sb:
+        Allow read-only access to UI_PROCESS_BUNDLE_RESOURCE_DIR and all subdirectories.
+
+        * WebProcess/mac/WebProcessMac.mm:
+        (WebKit::initializeSandbox):
+        When initializing the sandbox, pass UI_PROCESS_BUNDLE_RESOURCE_DIR.
+
+        (WebKit::WebProcess::platformInitializeWebProcess):
+        Remove the code that would consume a sandbox extension for the url cache path.
+
+2011-01-14  Anders Carlsson  <andersca@apple.com>
+
+        Reviewed by Sam Weinig.
+
         Delay initializing the sandbox until we get the InitializeWebProcess message.
 
         * WebProcess/mac/WebProcessMac.mm:
index 847450f..ceae6c1 100644 (file)
@@ -58,10 +58,10 @@ void WebProcessCreationParameters::encode(CoreIPC::ArgumentEncoder* encoder) con
 #if PLATFORM(MAC)
     encoder->encode(presenterApplicationPid);
     encoder->encode(nsURLCachePath);
-    encoder->encode(nsURLCachePathExtensionHandle);
     encoder->encode(nsURLCacheMemoryCapacity);
     encoder->encode(nsURLCacheDiskCapacity);
     encoder->encode(acceleratedCompositingPort);
+    encoder->encode(uiProcessBundleResourcePath);
 #elif PLATFORM(WIN)
     encoder->encode(shouldPaintNativeControls);
 #endif
@@ -99,14 +99,14 @@ bool WebProcessCreationParameters::decode(CoreIPC::ArgumentDecoder* decoder, Web
         return false;
     if (!decoder->decode(parameters.nsURLCachePath))
         return false;
-    if (!decoder->decode(parameters.nsURLCachePathExtensionHandle))
-        return false;
     if (!decoder->decode(parameters.nsURLCacheMemoryCapacity))
         return false;
     if (!decoder->decode(parameters.nsURLCacheDiskCapacity))
         return false;
     if (!decoder->decode(parameters.acceleratedCompositingPort))
         return false;
+    if (!decoder->decode(parameters.uiProcessBundleResourcePath))
+        return false;
 #elif PLATFORM(WIN)
     if (!decoder->decode(parameters.shouldPaintNativeControls))
         return false;
index 3d004b2..fe582b3 100644 (file)
@@ -74,12 +74,13 @@ struct WebProcessCreationParameters {
 
 #if PLATFORM(MAC)
     pid_t presenterApplicationPid;
-    String nsURLCachePath;
-    SandboxExtension::Handle nsURLCachePathExtensionHandle;
+    CString nsURLCachePath;
 
     uint64_t nsURLCacheMemoryCapacity;
     uint64_t nsURLCacheDiskCapacity;
     CoreIPC::MachPort acceleratedCompositingPort;
+
+    CString uiProcessBundleResourcePath;
 #elif PLATFORM(WIN)
     bool shouldPaintNativeControls;
 #endif
index 8a61aa7..ce4c3e6 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "WebKitSystemInterface.h"
 #include "WebProcessCreationParameters.h"
+#include <WebCore/FileSystem.h>
 #include <sys/param.h>
 
 using namespace WebCore;
@@ -73,9 +74,8 @@ void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& para
         cachePath = reinterpret_cast<CFStringRef>(NSHomeDirectory());
 
     NSURLCache *urlCache = [NSURLCache sharedURLCache];
-    parameters.nsURLCachePath = cachePath.get();
-    SandboxExtension::createHandle(cachePath.get(), SandboxExtension::ReadWrite, parameters.nsURLCachePathExtensionHandle);
-
+    
+    parameters.nsURLCachePath = fileSystemRepresentation([(NSString *)cachePath.get() stringByStandardizingPath]);
     parameters.nsURLCacheMemoryCapacity = [urlCache memoryCapacity];
     parameters.nsURLCacheDiskCapacity = [urlCache diskCapacity];
 
@@ -84,6 +84,9 @@ void WebContext::platformInitializeWebProcess(WebProcessCreationParameters& para
     if (renderServerPort != MACH_PORT_NULL)
         parameters.acceleratedCompositingPort = CoreIPC::MachPort(renderServerPort, MACH_MSG_TYPE_COPY_SEND);
 #endif
+
+    // FIXME: This should really be configurable; we shouldn't just blindly allow read access to the UI process bundle.
+    parameters.uiProcessBundleResourcePath = fileSystemRepresentation([[NSBundle mainBundle] resourcePath]);
 }
 
 } // namespace WebKit
index 0432bd5..2123c95 100644 (file)
 (if (positive? (string-length (param "DARWIN_USER_TEMP_DIR")))
     (allow file* (subpath (param "DARWIN_USER_TEMP_DIR"))))
 
+;; The NSURLCache directory.
+(if (positive? (string-length (param "NSURL_CACHE_DIR")))
+    (allow file* (subpath (param "NSURL_CACHE_DIR"))))
+
+;; The bundle resource path of the UI process.
+(if (positive? (string-length (param "UI_PROCESS_BUNDLE_RESOURCE_DIR")))
+    (allow file-read* (subpath (param "UI_PROCESS_BUNDLE_RESOURCE_DIR"))))
+
 ;; FIXME: overly permissive since we can't pre-enumerate the client
 ;; classes for graphics cards
 (allow iokit-open
index 092e5da..18dad6a 100644 (file)
@@ -135,6 +135,8 @@ static void initializeSandbox(const WebProcessCreationParameters& parameters)
         "WEBKIT2_FRAMEWORK_DIR", frameworkPath,
         "DARWIN_USER_TEMP_DIR", (const char*)tmpRealPath,
         "DARWIN_USER_CACHE_DIR", (const char*)cacheRealPath,
+        "NSURL_CACHE_DIR", (const char*)parameters.nsURLCachePath.data(),
+        "UI_PROCESS_BUNDLE_RESOURCE_DIR", (const char*)parameters.uiProcessBundleResourcePath.data(),
         NULL
     };
 
@@ -153,12 +155,7 @@ void WebProcess::platformInitializeWebProcess(const WebProcessCreationParameters
         NSUInteger cacheMemoryCapacity = parameters.nsURLCacheMemoryCapacity;
         NSUInteger cacheDiskCapacity = parameters.nsURLCacheDiskCapacity;
 
-        CString utf8CachePath = parameters.nsURLCachePath.utf8();
-        NSString *nsCachePath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:utf8CachePath.data() length:utf8CachePath.length()];
-
-        RefPtr<SandboxExtension> parentProcessURLCacheSandboxExtension = SandboxExtension::create(parameters.nsURLCachePathExtensionHandle);
-        parentProcessURLCacheSandboxExtension->consumePermanently();
-
+        NSString *nsCachePath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:parameters.nsURLCachePath.data() length:parameters.nsURLCachePath.length()];
         RetainPtr<NSURLCache> parentProcessURLCache(AdoptNS, [[NSURLCache alloc] initWithMemoryCapacity:cacheMemoryCapacity diskCapacity:cacheDiskCapacity diskPath:nsCachePath]);
         [NSURLCache setSharedURLCache:parentProcessURLCache.get()];
     }