Changeset 140926 in webkit


Ignore:
Timestamp:
Jan 26, 2013, 11:02:45 PM (12 years ago)
Author:
ap@apple.com
Message:

Use shared ChildProcess code to enter plug-in sandbox.

Reviewed by Sam Weinig.

There is one known behavior change from this refactoring: getpwuid_r is used
instead of NSHomeDirectory for home directory, mathcing other client processes.

  • PluginProcess/PluginProcess.cpp: (WebKit::PluginProcess::enterSandbox):
  • PluginProcess/PluginProcess.h: PluginProcess prevents ChildProcess attempt to enter the sandbox immediately on launch for now, because we don't have a sandbox profile directory path yet. It now keeps a copy of ChildProcessInitializationParameters, so that ChildProcess::initializeSandbox() could be called later.
  • PluginProcess/mac/PluginProcessMac.mm: (WebKit::PluginProcess::platformInitializeProcess): Store a copy of ChildProcessInitializationParameters for later. (WebKit::loadSandboxProfile): Build a sandbox profile from a common prefix and a plugin-specific part. (WebKit::PluginProcess::platformInitializePluginProcess): We can enter the sandbox now. (WebKit::PluginProcess::enterSandbox): Prepare SandboxInitializationParameters, and call ChildProcess::initializeSandbox().
  • Shared/mac/ChildProcessMac.mm: (WebKit::ChildProcess::initializeSandbox): Actually handle system directory suffix from parameters.
  • WebKit2.xcodeproj/project.pbxproj:
  • WebProcess/Plugins/Netscape/mac/NetscapeSandboxFunctions.h: Removed.
  • WebProcess/Plugins/Netscape/mac/NetscapeSandboxFunctions.mm: Removed.
Location:
trunk/Source/WebKit2
Files:
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r140924 r140926  
     12013-01-26  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Use shared ChildProcess code to enter plug-in sandbox.
     4
     5        Reviewed by Sam Weinig.
     6
     7        There is one known behavior change from this refactoring: getpwuid_r is used
     8        instead of NSHomeDirectory for home directory, mathcing other client processes.
     9
     10        * PluginProcess/PluginProcess.cpp: (WebKit::PluginProcess::enterSandbox):
     11        * PluginProcess/PluginProcess.h:
     12        PluginProcess prevents ChildProcess attempt to enter the sandbox immediately on
     13        launch for now, because we don't have a sandbox profile directory path yet.
     14        It now keeps a copy of ChildProcessInitializationParameters, so that
     15        ChildProcess::initializeSandbox() could be called later.
     16
     17        * PluginProcess/mac/PluginProcessMac.mm:
     18        (WebKit::PluginProcess::platformInitializeProcess): Store a copy of ChildProcessInitializationParameters
     19        for later.
     20        (WebKit::loadSandboxProfile): Build a sandbox profile from a common prefix and
     21        a plugin-specific part.
     22        (WebKit::PluginProcess::platformInitializePluginProcess): We can enter the sandbox now.
     23        (WebKit::PluginProcess::enterSandbox): Prepare SandboxInitializationParameters,
     24        and call ChildProcess::initializeSandbox().
     25
     26        * Shared/mac/ChildProcessMac.mm:
     27        (WebKit::ChildProcess::initializeSandbox): Actually handle system directory suffix
     28        from parameters.
     29
     30        * WebKit2.xcodeproj/project.pbxproj:
     31        * WebProcess/Plugins/Netscape/mac/NetscapeSandboxFunctions.h: Removed.
     32        * WebProcess/Plugins/Netscape/mac/NetscapeSandboxFunctions.mm: Removed.
     33
    1342013-01-26  Sam Weinig  <sam@webkit.org>
    235
  • trunk/Source/WebKit2/PluginProcess/PluginProcess.cpp

    r139257 r140926  
    9191}
    9292
     93#if !PLATFORM(MAC)
     94void PluginProcess::enterSandbox(const String&)
     95{
     96}
     97#endif
     98
    9399void PluginProcess::removeWebProcessConnection(WebProcessConnection* webProcessConnection)
    94100{
  • trunk/Source/WebKit2/PluginProcess/PluginProcess.h

    r140730 r140926  
    7373    ~PluginProcess();
    7474
     75    void enterSandbox(const String& sandboxProfileDirectoryPath);
     76
    7577    // ChildProcess
    7678    virtual void initializeProcess(const ChildProcessInitializationParameters&) OVERRIDE;
    7779    virtual bool shouldTerminate() OVERRIDE;
    7880
    79     // FIXME: PluginProcess should switch to common code for sandbox initialization.
     81    // Prevent entering the sandbox during first stage of process initialization. We can't do enter the sandbox before receiving
     82    // sandbox profile directory in initialization message.
    8083    virtual void initializeSandbox(const ChildProcessInitializationParameters&, SandboxInitializationParameters&) OVERRIDE { }
    8184
     
    99102    void minimumLifetimeTimerFired();
    100103
     104    // Stored for delayed sandbox initialization.
     105    ChildProcessInitializationParameters m_childProcessInitializationParameters;
     106
    101107    // Our web process connections.
    102108    Vector<RefPtr<WebProcessConnection> > m_webProcessConnections;
     
    111117
    112118    WebCore::RunLoop::Timer<PluginProcess> m_minimumLifetimeTimer;
    113    
     119
    114120#if USE(ACCELERATED_COMPOSITING) && PLATFORM(MAC)
    115121    // The Mach port used for accelerated compositing.
    116122    mach_port_t m_compositingRenderServerPort;
    117123#endif
    118 
    119124};
    120125
  • trunk/Source/WebKit2/PluginProcess/mac/PluginProcessMac.mm

    r140865 r140926  
    3434#import "PluginProcessProxyMessages.h"
    3535#import "PluginProcessCreationParameters.h"
     36#import "SandboxInitializationParameters.h"
    3637#import <CoreAudio/AudioHardware.h>
    3738#import <WebCore/LocalizedStrings.h>
     
    3940#import <dlfcn.h>
    4041#import <objc/runtime.h>
     42#import <sysexits.h>
    4143#import <wtf/HashSet.h>
    42 
    43 #import "NetscapeSandboxFunctions.h"
    4444
    4545using namespace WebCore;
     
    271271}
    272272
    273 void PluginProcess::platformInitializeProcess(const ChildProcessInitializationParameters&)
    274 {
     273void PluginProcess::platformInitializeProcess(const ChildProcessInitializationParameters& parameters)
     274{
     275    m_childProcessInitializationParameters = parameters;
     276
    275277    RunLoop::setUseApplicationRunLoopOnMainRunLoop();
    276278
     
    304306}
    305307
    306 static void initializeSandbox(const String& pluginPath, const String& sandboxProfileDirectoryPath)
     308static String loadSandboxProfile(const String& pluginPath, const String& sandboxProfileDirectoryPath)
    307309{
    308310    if (sandboxProfileDirectoryPath.isEmpty())
    309         return;
     311        return String();
    310312
    311313    RetainPtr<CFURLRef> pluginURL = adoptCF(CFURLCreateWithFileSystemPath(0, pluginPath.createCFString().get(), kCFURLPOSIXPathStyle, false));
    312314    if (!pluginURL)
    313         return;
     315        return String();
    314316
    315317    RetainPtr<CFBundleRef> pluginBundle = adoptCF(CFBundleCreate(kCFAllocatorDefault, pluginURL.get()));
    316318    if (!pluginBundle)
    317         return;
     319        return String();
    318320   
    319321    CFStringRef bundleIdentifier = CFBundleGetIdentifier(pluginBundle.get());
    320322    if (!bundleIdentifier)
    321         return;
     323        return String();
    322324
    323325    RetainPtr<CFURLRef> sandboxProfileDirectory = adoptCF(CFURLCreateWithFileSystemPath(0, sandboxProfileDirectoryPath.createCFString().get(), kCFURLPOSIXPathStyle, TRUE));
     
    328330    RetainPtr<NSString> profileString = adoptNS([[NSString alloc] initWithContentsOfURL:(NSURL *)sandboxURL.get() encoding:NSUTF8StringEncoding error:NULL]);
    329331    if (!profileString)
    330         return;
     332        return String();
    331333
    332334    sandboxURL = adoptCF(CFURLCreateWithFileSystemPathRelativeToBase(0, CFSTR("com.apple.WebKit.plugin-common.sb"), kCFURLPOSIXPathStyle, FALSE, sandboxProfileDirectory.get()));
     
    334336    RetainPtr<NSString> commonProfileString = adoptNS([[NSString alloc] initWithContentsOfURL:(NSURL *)sandboxURL.get() encoding:NSUTF8StringEncoding error:NULL]);
    335337    if (!commonProfileString)
    336         return;
    337 
    338     profileString = [commonProfileString.get() stringByAppendingString:profileString.get()];
    339 
    340     enterSandbox([profileString.get() UTF8String]);
     338        return String();
     339
     340    return [commonProfileString.get() stringByAppendingString:profileString.get()];
    341341}
    342342
     
    361361    WKSetVisibleApplicationName((CFStringRef)applicationName);
    362362
    363     // FIXME: Use ChildProcess::initializeSandbox.
    364     WebKit::initializeSandbox(m_pluginPath, parameters.sandboxProfileDirectoryPath);
     363    // FIXME: PluginProcess initializes sandbox later than normal for ChildProcesses, because it needs
     364    // to know profile directory path. Switch to normal initialization scheme once the path can be determined earlier.
     365    enterSandbox(parameters.sandboxProfileDirectoryPath);
    365366
    366367    if (parameters.processType == TypeSnapshotProcess)
     
    368369}
    369370
     371void PluginProcess::enterSandbox(const String& sandboxProfileDirectoryPath)
     372{
     373    SandboxInitializationParameters sandboxParameters;
     374
     375    String sandboxProfile = loadSandboxProfile(m_pluginPath, sandboxProfileDirectoryPath);
     376    if (sandboxProfile.isEmpty())
     377        return;
     378
     379    sandboxParameters.setSandboxProfile(sandboxProfile);
     380
     381#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1080
     382    // Use private temporary and cache directories.
     383    char temporaryDirectory[PATH_MAX];
     384    if (!confstr(_CS_DARWIN_USER_TEMP_DIR, temporaryDirectory, sizeof(temporaryDirectory))) {
     385        WTFLogAlways("PluginProcess: couldn't retrieve system temporary directory path: %d\n", errno);
     386        exit(EX_OSERR);
     387    }
     388
     389    if (strlcpy(temporaryDirectory, [[[[NSFileManager defaultManager] stringWithFileSystemRepresentation:temporaryDirectory length:strlen(temporaryDirectory)] stringByAppendingPathComponent:@"WebKitPlugin-XXXXXX"] fileSystemRepresentation], sizeof(temporaryDirectory)) >= sizeof(temporaryDirectory)
     390        || !mkdtemp(temporaryDirectory)) {
     391        WTFLogAlways("PluginProcess: couldn't create private temporary directory '%s'\n", temporaryDirectory);
     392        exit(EX_OSERR);
     393    }
     394
     395    sandboxParameters.setSystemDirectorySuffix([[[[NSFileManager defaultManager] stringWithFileSystemRepresentation:temporaryDirectory length:strlen(temporaryDirectory)] lastPathComponent] fileSystemRepresentation]);
     396#endif
     397
     398    sandboxParameters.addPathParameter("PLUGIN_PATH", m_pluginPath);
     399
     400    RetainPtr<CFStringRef> cachePath(AdoptCF, WKCopyFoundationCacheDirectory());
     401    sandboxParameters.addPathParameter("NSURL_CACHE_DIR", (NSString *)cachePath.get());
     402
     403    RetainPtr<NSDictionary> defaults = adoptNS([[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithBool:YES], @"NSUseRemoteSavePanel", nil]);
     404    [[NSUserDefaults standardUserDefaults] registerDefaults:defaults.get()];
     405
     406    ChildProcess::initializeSandbox(m_childProcessInitializationParameters, sandboxParameters);
     407}
     408
    370409} // namespace WebKit
    371410
  • trunk/Source/WebKit2/Shared/mac/ChildProcessMac.mm

    r140853 r140926  
    8686    String defaultProfilePath = [webkit2Bundle pathForResource:[[NSBundle mainBundle] bundleIdentifier] ofType:@"sb"];
    8787
    88     String defaultSystemDirectorySuffix = String([[NSBundle mainBundle] bundleIdentifier]) + "+" + parameters.clientIdentifier;
    89     sandboxParameters.setSystemDirectorySuffix(defaultSystemDirectorySuffix);
     88    if (sandboxParameters.systemDirectorySuffix().isNull()) {
     89        String defaultSystemDirectorySuffix = String([[NSBundle mainBundle] bundleIdentifier]) + "+" + parameters.clientIdentifier;
     90        sandboxParameters.setSystemDirectorySuffix(defaultSystemDirectorySuffix);
     91    }
    9092
    9193    sandboxParameters.addPathParameter("WEBKIT2_FRAMEWORK_DIR", [[webkit2Bundle bundlePath] stringByDeletingLastPathComponent]);
  • trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj

    r140924 r140926  
    10421042                E179FD9C134D38060015B883 /* ArgumentCodersMac.h in Headers */ = {isa = PBXBuildFile; fileRef = E179FD9B134D38060015B883 /* ArgumentCodersMac.h */; };
    10431043                E179FD9F134D38250015B883 /* ArgumentCodersMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = E179FD9E134D38250015B883 /* ArgumentCodersMac.mm */; };
    1044                 E17BF99614D0A73E00A5A069 /* NetscapeSandboxFunctions.h in Headers */ = {isa = PBXBuildFile; fileRef = E17BF99514D0A73E00A5A069 /* NetscapeSandboxFunctions.h */; };
    1045                 E17BF99814D0AA8300A5A069 /* NetscapeSandboxFunctions.mm in Sources */ = {isa = PBXBuildFile; fileRef = E17BF99714D0AA8300A5A069 /* NetscapeSandboxFunctions.mm */; };
    10461044                E18C92F412DB9E7100CF2AEB /* PrintInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18C92F312DB9E7100CF2AEB /* PrintInfo.cpp */; };
    10471045                E18E690B169B563F009B6670 /* SecItemShimProxy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E18E6909169B563F009B6670 /* SecItemShimProxy.cpp */; };
     
    23872385                E179FD9B134D38060015B883 /* ArgumentCodersMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ArgumentCodersMac.h; sourceTree = "<group>"; };
    23882386                E179FD9E134D38250015B883 /* ArgumentCodersMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ArgumentCodersMac.mm; sourceTree = "<group>"; };
    2389                 E17BF99514D0A73E00A5A069 /* NetscapeSandboxFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NetscapeSandboxFunctions.h; sourceTree = "<group>"; };
    2390                 E17BF99714D0AA8300A5A069 /* NetscapeSandboxFunctions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NetscapeSandboxFunctions.mm; sourceTree = "<group>"; };
    23912387                E18C92F312DB9E7100CF2AEB /* PrintInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrintInfo.cpp; sourceTree = "<group>"; };
    23922388                E18E6909169B563F009B6670 /* SecItemShimProxy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SecItemShimProxy.cpp; sourceTree = "<group>"; };
     
    27652761                        children = (
    27662762                                1AE5B7F911E7AED200BA6767 /* NetscapePluginMac.mm */,
    2767                                 E17BF99514D0A73E00A5A069 /* NetscapeSandboxFunctions.h */,
    2768                                 E17BF99714D0AA8300A5A069 /* NetscapeSandboxFunctions.mm */,
    27692763                                1A2D92201281DC1B001EB962 /* PluginProxyMac.mm */,
    27702764                        );
     
    47954789                                1A4A9C5612B816CF008FE984 /* NetscapePluginModule.h in Headers */,
    47964790                                1AA5889211EE70400061B882 /* NetscapePluginStream.h in Headers */,
    4797                                 E17BF99614D0A73E00A5A069 /* NetscapeSandboxFunctions.h in Headers */,
    47984791                                513A164D1630A9BF005D7D22 /* NetworkConnectionToWebProcess.h in Headers */,
    47994792                                51DD9F2916367DA2001578E9 /* NetworkConnectionToWebProcessMessages.h in Headers */,
     
    58265819                                1A4A9C9A12B821CD008FE984 /* NetscapePluginModuleMac.mm in Sources */,
    58275820                                1AA5889311EE70400061B882 /* NetscapePluginStream.cpp in Sources */,
    5828                                 E17BF99814D0AA8300A5A069 /* NetscapeSandboxFunctions.mm in Sources */,
    58295821                                513A164C1630A9BF005D7D22 /* NetworkConnectionToWebProcess.cpp in Sources */,
    58305822                                51DD9F2816367DA2001578E9 /* NetworkConnectionToWebProcessMessageReceiver.cpp in Sources */,
Note: See TracChangeset for help on using the changeset viewer.