⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 263295 in webkit


Ignore:
Timestamp:
Jun 19, 2020, 4:37:55 PM (6 years ago)
Author:
pvollan@apple.com
Message:

[macOS] Connections to the preference daemon are established before entering the sandbox
https://bugs.webkit.org/show_bug.cgi?id=213379

Reviewed by Darin Adler.

Source/WebCore/PAL:

Use correct parameter types in _CFPrefsSetDirectModeEnabled and _CFPrefsSetReadOnly, and move
_CFPrefsSetDirectModeEnabled inside an Objective-C guard, since BOOL only seems to be a builtin
type in Objective-C.

  • pal/spi/cf/CFUtilitiesSPI.h:

Source/WebKit:

On macOS, connections to the preference daemon are established before entering the sandbox. These connections also persist
after entering the sandbox and denying access to the preference daemon. There should not be attempts to connect to the
preference daemon before entering the sandbox, since these attempts will not be stopped by the sandbox. This patch moves
code that connects to the preference daemon to be executed after the sandbox has been entered. That includes code to
prevent connections to the Dock and code to initialize WebKit logging. Also, instead of calling [NSBundle bundleForClass:],
call [NSBundle bundleWithIdentifier:], since calling [NSBundle bundleForClass:] will connect to the preference daemon.
Finally, allow the syscall SYS_gethostuuid, since that is needed by CoreFoundation when there is no access to the
preference daemon.

No new tests. This should be covered by existing tests. It would be nice to have a test to make sure that there are no
connections to the preference daemon just before entering the sandbox, but I am not aware of how to implement this.

  • NetworkProcess/mac/NetworkProcessMac.mm:

(WebKit::NetworkProcess::initializeSandbox):

  • Shared/AuxiliaryProcess.cpp:

(WebKit::AuxiliaryProcess::initialize):

  • Shared/Cocoa/WebKit2InitializeCocoa.mm:

(WebKit::runInitializationCode):

  • Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:

(WebKit::XPCServiceMain):

  • Shared/mac/AuxiliaryProcessMac.mm:

(WebKit::webKit2Bundle):

  • WebProcess/cocoa/WebProcessCocoa.mm:

(WebKit::WebProcess::platformInitializeWebProcess):
(WebKit::WebProcess::initializeSandbox):

  • WebProcess/com.apple.WebProcess.sb.in:
Location:
trunk/Source
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/PAL/ChangeLog

    r263255 r263295  
     12020-06-19  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [macOS] Connections to the preference daemon are established before entering the sandbox
     4        https://bugs.webkit.org/show_bug.cgi?id=213379
     5
     6        Reviewed by Darin Adler.
     7
     8        Use correct parameter types in _CFPrefsSetDirectModeEnabled and _CFPrefsSetReadOnly, and move
     9        _CFPrefsSetDirectModeEnabled inside an Objective-C guard, since BOOL only seems to be a builtin
     10        type in Objective-C.
     11
     12        * pal/spi/cf/CFUtilitiesSPI.h:
     13
    1142020-06-19  Myles C. Maxfield  <mmaxfield@apple.com>
    215
  • trunk/Source/WebCore/PAL/pal/spi/cf/CFUtilitiesSPI.h

    r262639 r263295  
    5959void __CFRunLoopSetOptionsReason(__CFRunLoopOptions opts, CFStringRef reason);
    6060
    61 void _CFPrefsSetDirectModeEnabled(bool enabled);
    62 void _CFPrefsSetReadOnly(bool flag);
     61#ifdef __OBJC__
     62void _CFPrefsSetDirectModeEnabled(BOOL enabled);
     63#endif
     64void _CFPrefsSetReadOnly(Boolean flag);
    6365
    6466WTF_EXTERN_C_END
  • trunk/Source/WebKit/ChangeLog

    r263293 r263295  
     12020-06-19  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [macOS] Connections to the preference daemon are established before entering the sandbox
     4        https://bugs.webkit.org/show_bug.cgi?id=213379
     5
     6        Reviewed by Darin Adler.
     7
     8        On macOS, connections to the preference daemon are established before entering the sandbox. These connections also persist
     9        after entering the sandbox and denying access to the preference daemon. There should not be attempts to connect to the
     10        preference daemon before entering the sandbox, since these attempts will not be stopped by the sandbox. This patch moves
     11        code that connects to the preference daemon to be executed after the sandbox has been entered. That includes code to
     12        prevent connections to the Dock and code to initialize WebKit logging. Also, instead of calling [NSBundle bundleForClass:],
     13        call [NSBundle bundleWithIdentifier:], since calling [NSBundle bundleForClass:] will connect to the preference daemon.
     14        Finally, allow the syscall SYS_gethostuuid, since that is needed by CoreFoundation when there is no access to the
     15        preference daemon.
     16
     17        No new tests. This should be covered by existing tests. It would be nice to have a test to make sure that there are no
     18        connections to the preference daemon just before entering the sandbox, but I am not aware of how to implement this.
     19
     20        * NetworkProcess/mac/NetworkProcessMac.mm:
     21        (WebKit::NetworkProcess::initializeSandbox):
     22        * Shared/AuxiliaryProcess.cpp:
     23        (WebKit::AuxiliaryProcess::initialize):
     24        * Shared/Cocoa/WebKit2InitializeCocoa.mm:
     25        (WebKit::runInitializationCode):
     26        * Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm:
     27        (WebKit::XPCServiceMain):
     28        * Shared/mac/AuxiliaryProcessMac.mm:
     29        (WebKit::webKit2Bundle):
     30        * WebProcess/cocoa/WebProcessCocoa.mm:
     31        (WebKit::WebProcess::platformInitializeWebProcess):
     32        (WebKit::WebProcess::initializeSandbox):
     33        * WebProcess/com.apple.WebProcess.sb.in:
     34
    1352020-06-19  Chris Dumez  <cdumez@apple.com>
    236
  • trunk/Source/WebKit/NetworkProcess/mac/NetworkProcessMac.mm

    r258665 r263295  
    8888{
    8989    // Need to overide the default, because service has a different bundle ID.
    90     NSBundle *webKit2Bundle = [NSBundle bundleForClass:NSClassFromString(@"WKWebView")];
     90    auto webKitBundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit"];
    9191
    92     sandboxParameters.setOverrideSandboxProfilePath([webKit2Bundle pathForResource:@"com.apple.WebKit.NetworkProcess" ofType:@"sb"]);
     92    sandboxParameters.setOverrideSandboxProfilePath(makeString(String([webKitBundle resourcePath]), "/com.apple.WebKit.NetworkProcess.sb"));
    9393
    9494    AuxiliaryProcess::initializeSandbox(parameters, sandboxParameters);
  • trunk/Source/WebKit/Shared/AuxiliaryProcess.cpp

    r261254 r263295  
    2828
    2929#include "ContentWorldShared.h"
     30#include "LogInitialization.h"
    3031#include "Logging.h"
    3132#include "SandboxInitializationParameters.h"
     33#include <WebCore/LogInitialization.h>
    3234#include <pal/SessionID.h>
    3335
     
    7678    SandboxInitializationParameters sandboxParameters;
    7779    initializeSandbox(parameters, sandboxParameters);
     80
     81#if !LOG_DISABLED || !RELEASE_LOG_DISABLED
     82    WebCore::initializeLogChannelsIfNecessary();
     83    WebKit::initializeLogChannelsIfNecessary();
     84#endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    7885
    7986    initializeProcessName(parameters);
  • trunk/Source/WebKit/Shared/Cocoa/WebKit2InitializeCocoa.mm

    r262878 r263295  
    2727#import "WebKit2Initialize.h"
    2828
    29 #import "LogInitialization.h"
    3029#import "VersionChecks.h"
    3130#import <JavaScriptCore/InitializeThreading.h>
    32 #import <WebCore/LogInitialization.h>
    3331#import <mutex>
    3432#import <wtf/MainThread.h>
     
    5755
    5856    WTF::RefCountedBase::enableThreadingChecksGlobally();
    59 
    60 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    61     WebCore::initializeLogChannelsIfNecessary();
    62     WebKit::initializeLogChannelsIfNecessary();
    63 #endif // !LOG_DISABLED || !RELEASE_LOG_DISABLED
    6457}
    6558
  • trunk/Source/WebKit/Shared/EntryPointUtilities/Cocoa/XPCService/XPCServiceMain.mm

    r262730 r263295  
    3333#import <wtf/RetainPtr.h>
    3434#import <wtf/spi/darwin/XPCSPI.h>
    35 
    36 #if PLATFORM(MAC)
    37 #import <pal/spi/mac/NSApplicationSPI.h>
    38 #endif
    3935
    4036namespace WebKit {
     
    170166    // Don't allow Apple Events in WebKit processes. This can be removed when <rdar://problem/14012823> is fixed.
    171167    setenv("__APPLEEVENTSSERVICENAME", "", 1);
    172 
    173     // We don't need to talk to the dock.
    174     if (Class nsApplicationClass = NSClassFromString(@"NSApplication")) {
    175         if ([nsApplicationClass respondsToSelector:@selector(_preventDockConnections)])
    176             [nsApplicationClass _preventDockConnections];
    177     }
    178168#endif
    179169
  • trunk/Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm

    r262005 r263295  
    521521static inline const NSBundle *webKit2Bundle()
    522522{
    523     const static NSBundle *bundle = [NSBundle bundleForClass:NSClassFromString(@"WKWebView")];
     523    const static NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit"];
    524524    return bundle;
    525525}
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r263287 r263295  
    186186    }
    187187
    188 #if !LOG_DISABLED || !RELEASE_LOG_DISABLED
    189     WebCore::initializeLogChannelsIfNecessary(parameters.webCoreLoggingChannels);
    190     WebKit::initializeLogChannelsIfNecessary(parameters.webKitLoggingChannels);
    191 #endif
    192 
    193188    WebCore::setApplicationBundleIdentifier(parameters.uiProcessBundleIdentifier);
    194189    setApplicationSDKVersion(parameters.uiProcessSDKVersion);
     
    232227
    233228#if USE(APPKIT)
     229    // We don't need to talk to the Dock.
     230    [NSApplication _preventDockConnections];
     231
    234232    [[NSUserDefaults standardUserDefaults] registerDefaults:@{ @"NSApplicationCrashOnExceptions" : @YES }];
    235233
     
    239237    method_setImplementation(methodToPatch, (IMP)NSApplicationAccessibilityFocusedUIElement);
    240238#endif
    241    
     239
    242240#if PLATFORM(MAC) && ENABLE(WEBPROCESS_NSRUNLOOP)
    243241    // Need to initialize accessibility for VoiceOver to work when the WebContent process is using NSRunLoop.
     
    583581#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
    584582    // Need to override the default, because service has a different bundle ID.
    585     NSBundle *webKit2Bundle = [NSBundle bundleForClass:NSClassFromString(@"WKWebView")];
    586 
    587     sandboxParameters.setOverrideSandboxProfilePath([webKit2Bundle pathForResource:@"com.apple.WebProcess" ofType:@"sb"]);
     583    auto webKitBundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit"];
     584
     585    sandboxParameters.setOverrideSandboxProfilePath(makeString(String([webKitBundle resourcePath]), "/com.apple.WebProcess.sb"));
    588586
    589587    AuxiliaryProcess::initializeSandbox(parameters, sandboxParameters);
  • trunk/Source/WebKit/WebProcess/com.apple.WebProcess.sb.in

    r263287 r263295  
    11011101#endif
    11021102        (syscall-number SYS_fstat64_extended) ;; <rdar://problem/61310019>
     1103        (syscall-number SYS_gethostuuid)
    11031104    )
    11041105
Note: See TracChangeset for help on using the changeset viewer.