Changeset 248832 in webkit


Ignore:
Timestamp:
Aug 18, 2019 12:38:08 PM (5 years ago)
Author:
pvollan@apple.com
Message:

[Mac] Use the PID of the WebContent process when issuing local file read sandbox extensions
https://bugs.webkit.org/show_bug.cgi?id=200543
<rdar://problem/49394015>
Source/WebKit:

Reviewed by Brent Fulgham.

Adopt SPI to issue a process-specific sandbox extension for local file read, passing it the process
identifier of the WebContent process.

  • Shared/Cocoa/SandboxExtensionCocoa.mm:

(WebKit::SandboxExtensionImpl::sandboxExtensionForType):
(WebKit::SandboxExtension::createHandleForReadByPid):

  • Shared/SandboxExtension.h:
  • UIProcess/Cocoa/WebPageProxyCocoa.mm:

(WebKit::WebPageProxy::createSandboxExtensionsIfNeeded):

  • UIProcess/WebPageProxy.cpp:

(WebKit::WebPageProxy::maybeInitializeSandboxExtensionHandle):
(WebKit::WebPageProxy::loadFile):

Source/WTF:

Reviewed by Brent Fulgham.

Add new SPI.

  • wtf/Platform.h:
  • wtf/spi/darwin/SandboxSPI.h:
Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r248831 r248832  
     12019-08-18  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [Mac] Use the PID of the WebContent process when issuing local file read sandbox extensions
     4        https://bugs.webkit.org/show_bug.cgi?id=200543
     5        <rdar://problem/49394015>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        Add new SPI.
     10       
     11        * wtf/Platform.h:
     12        * wtf/spi/darwin/SandboxSPI.h:
     13
    1142019-08-17  Darin Adler  <darin@apple.com>
    215
  • trunk/Source/WTF/wtf/Platform.h

    r248823 r248832  
    15351535#endif
    15361536
     1537#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400)
     1538#define HAVE_SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID 1
     1539#endif
     1540
    15371541#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 130000)
    15381542#define HAVE_MDNS_FAST_REGISTRATION 1
  • trunk/Source/WTF/wtf/spi/darwin/SandboxSPI.h

    r248731 r248832  
    5959extern const enum sandbox_filter_type SANDBOX_CHECK_NO_REPORT;
    6060
     61extern const uint32_t SANDBOX_EXTENSION_USER_INTENT;
     62
    6163char *sandbox_extension_issue_file(const char *extension_class, const char *path, uint32_t flags);
    6264char *sandbox_extension_issue_generic(const char *extension_class, uint32_t flags);
    6365char *sandbox_extension_issue_mach_to_process_by_pid(const char *extension_class, const char *name, uint32_t flags, pid_t);
     66char *sandbox_extension_issue_file_to_process_by_pid(const char *extension_class, const char *path, uint32_t flags, pid_t);
    6467int sandbox_check(pid_t, const char *operation, enum sandbox_filter_type, ...);
    6568int sandbox_check_by_audit_token(audit_token_t, const char *operation, enum sandbox_filter_type, ...);
  • trunk/Source/WebKit/ChangeLog

    r248828 r248832  
     12019-08-18  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [Mac] Use the PID of the WebContent process when issuing local file read sandbox extensions
     4        https://bugs.webkit.org/show_bug.cgi?id=200543
     5        <rdar://problem/49394015>
     6       
     7        Reviewed by Brent Fulgham.
     8
     9        Adopt SPI to issue a process-specific sandbox extension for local file read, passing it the process
     10        identifier of the WebContent process.
     11       
     12        * Shared/Cocoa/SandboxExtensionCocoa.mm:
     13        (WebKit::SandboxExtensionImpl::sandboxExtensionForType):
     14        (WebKit::SandboxExtension::createHandleForReadByPid):
     15        * Shared/SandboxExtension.h:
     16        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
     17        (WebKit::WebPageProxy::createSandboxExtensionsIfNeeded):
     18        * UIProcess/WebPageProxy.cpp:
     19        (WebKit::WebPageProxy::maybeInitializeSandboxExtensionHandle):
     20        (WebKit::WebPageProxy::loadFile):
     21
    1222019-08-17  Tim Horton  <timothy_horton@apple.com>
    223
  • trunk/Source/WebKit/Shared/Cocoa/SandboxExtensionCocoa.mm

    r248762 r248832  
    102102        case SandboxExtension::Type::Generic:
    103103            return sandbox_extension_issue_generic(path, 0);
     104        case SandboxExtension::Type::ReadByPid:
     105#if HAVE(SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID)
     106            return sandbox_extension_issue_file_to_process_by_pid(APP_SANDBOX_READ, path, SANDBOX_EXTENSION_USER_INTENT, pid.value());
     107#else
     108            UNUSED_PARAM(pid);
     109            ASSERT_NOT_REACHED();
     110            return nullptr;
     111#endif
    104112        }
    105113    }
     
    338346}
    339347
     348bool SandboxExtension::createHandleForReadByPid(const String& path, ProcessID pid, Handle& handle)
     349{
     350    ASSERT(!handle.m_sandboxExtension);
     351   
     352    if (!pid)
     353        return false;
     354
     355    handle.m_sandboxExtension = SandboxExtensionImpl::create(path.utf8().data(), Type::ReadByPid, pid);
     356    if (!handle.m_sandboxExtension) {
     357        WTFLogAlways("Could not create sandbox extension");
     358        return false;
     359    }
     360   
     361    return true;
     362}
     363
    340364SandboxExtension::SandboxExtension(const Handle& handle)
    341365    : m_sandboxExtension(WTFMove(handle.m_sandboxExtension))
  • trunk/Source/WebKit/Shared/SandboxExtension.h

    r248731 r248832  
    5050        Mach,
    5151        Generic,
     52        ReadByPid
    5253    };
    5354
     
    105106    static bool createHandleForGenericExtension(const String& extensionClass, Handle&);
    106107    static bool createHandleForMachLookupByPid(const String& service, ProcessID, Handle&);
     108    static bool createHandleForReadByPid(const String& path, ProcessID, Handle&);
    107109    ~SandboxExtension();
    108110
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r248713 r248832  
    127127        BOOL isDirectory;
    128128        if ([[NSFileManager defaultManager] fileExistsAtPath:files[0] isDirectory:&isDirectory] && !isDirectory) {
     129#if HAVE(SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID)
     130            if (!SandboxExtension::createHandleForReadByPid("/", processIdentifier(), fileReadHandle))
     131#endif
    129132            SandboxExtension::createHandle("/", SandboxExtension::Type::ReadOnly, fileReadHandle);
    130133            willAcquireUniversalFileReadSandboxExtension(m_process);
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r248731 r248832  
    10771077    ASSERT_WITH_SECURITY_IMPLICATION(!WebKit::isInspectorPage(*this));
    10781078
     1079#if HAVE(SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID)
     1080    if (SandboxExtension::createHandleForReadByPid("/", process.processIdentifier(), sandboxExtensionHandle)) {
     1081        willAcquireUniversalFileReadSandboxExtension(process);
     1082        return;
     1083    }
     1084#endif
    10791085    if (SandboxExtension::createHandle("/", SandboxExtension::Type::ReadOnly, sandboxExtensionHandle)) {
    10801086        willAcquireUniversalFileReadSandboxExtension(process);
     
    11951201    loadParameters.shouldOpenExternalURLsPolicy = ShouldOpenExternalURLsPolicy::ShouldNotAllow;
    11961202    loadParameters.userData = UserData(process().transformObjectsToHandles(userData).get());
     1203#if HAVE(SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID)
     1204    if (!SandboxExtension::createHandleForReadByPid(resourceDirectoryPath, processIdentifier(), loadParameters.sandboxExtensionHandle))
     1205#endif
    11971206    SandboxExtension::createHandle(resourceDirectoryPath, SandboxExtension::Type::ReadOnly, loadParameters.sandboxExtensionHandle);
    11981207    addPlatformLoadParameters(loadParameters);
Note: See TracChangeset for help on using the changeset viewer.