Changeset 249649 in webkit


Ignore:
Timestamp:
Sep 9, 2019 10:44:33 AM (5 years ago)
Author:
pvollan@apple.com
Message:

[macOS] Pid is sometimes invalid when creating sandbox extensions by pid.
https://bugs.webkit.org/show_bug.cgi?id=201543
<rdar://problem/54733465>

Reviewed by Brent Fulgham.

There is a race condition when starting a load of a local file, where the WebContent process has not finished
launching yet, and its pid is not available. When we try to create a sandbox extension by using the pid of the
WebContent process, it is not available in the cases where the WebContent process has just launched and has not
finished launching yet. This patch creates a new dummy Web page message, 'LoadRequestWaitingForPID', which will
be sent instead of a normal 'LoadRequest' message, and only when the WebContent process has not finished
launching. When the WebContent process has finished launching, and we are about to actually send the pending
messages, we can detect that a 'LoadRequestWaitingForPID' has been appended for sending, and replace it with a
normal 'LoadReqest' message where we have created the sandbox extension issue with a valid pid. The message
'LoadRequestWaitingForPID' is never intended to reach the WebContent process, it is just there to replace with
a normal 'LoadRequest' message with a new sandbox extension. In the implementation of the message handler on
the WebContent process side, we assert that the method is never called. This patch makes sure the ordering of
the Web page messages are the same, even when we modify the message.

  • UIProcess/AuxiliaryProcessProxy.cpp:

(WebKit::AuxiliaryProcessProxy::didFinishLaunching):

  • UIProcess/WebPageProxy.cpp:

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

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::fileLoadRequest):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
Location:
trunk/Source/WebKit
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r249647 r249649  
     12019-09-09  Per Arne Vollan  <pvollan@apple.com>
     2
     3        [macOS] Pid is sometimes invalid when creating sandbox extensions by pid.
     4        https://bugs.webkit.org/show_bug.cgi?id=201543
     5        <rdar://problem/54733465>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        There is a race condition when starting a load of a local file, where the WebContent process has not finished
     10        launching yet, and its pid is not available. When we try to create a sandbox extension by using the pid of the
     11        WebContent process, it is not available in the cases where the WebContent process has just launched and has not
     12        finished launching yet. This patch creates a new dummy Web page message, 'LoadRequestWaitingForPID', which will
     13        be sent instead of a normal 'LoadRequest' message, and only when the WebContent process has not finished
     14        launching. When the WebContent process has finished launching, and we are about to actually send the pending
     15        messages, we can detect that a 'LoadRequestWaitingForPID' has been appended for sending, and replace it with a
     16        normal 'LoadReqest' message where we have created the sandbox extension issue with a valid pid. The message
     17        'LoadRequestWaitingForPID' is never intended to reach the WebContent process, it is just there to replace with
     18        a normal 'LoadRequest' message with a new sandbox extension. In the implementation of the message handler on
     19        the WebContent process side, we assert that the method is never called. This patch makes sure the ordering of
     20        the Web page messages are the same, even when we modify the message.
     21
     22        * UIProcess/AuxiliaryProcessProxy.cpp:
     23        (WebKit::AuxiliaryProcessProxy::didFinishLaunching):
     24        * UIProcess/WebPageProxy.cpp:
     25        (WebKit::WebPageProxy::maybeInitializeSandboxExtensionHandle):
     26        (WebKit::WebPageProxy::loadRequestWithNavigationShared):
     27        (WebKit::WebPageProxy::loadFile):
     28        * WebProcess/WebPage/WebPage.cpp:
     29        (WebKit::WebPage::fileLoadRequest):
     30        * WebProcess/WebPage/WebPage.h:
     31        * WebProcess/WebPage/WebPage.messages.in:
     32
    1332019-09-09  Youenn Fablet  <youenn@apple.com>
    234
  • trunk/Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp

    r247828 r249649  
    2828
    2929#include "AuxiliaryProcessMessages.h"
     30#include "LoadParameters.h"
     31#include "WebPageMessages.h"
    3032#include <wtf/RunLoop.h>
    3133
     
    176178        std::unique_ptr<IPC::Encoder> message = WTFMove(m_pendingMessages[i].first);
    177179        OptionSet<IPC::SendOption> sendOptions = m_pendingMessages[i].second;
     180#if HAVE(SANDBOX_ISSUE_MACH_EXTENSION_TO_PROCESS_BY_PID)
     181        if (message->messageName() == "LoadRequestWaitingForPID") {
     182            auto buffer = message->buffer();
     183            auto bufferSize = message->bufferSize();
     184            std::unique_ptr<IPC::Decoder> decoder = makeUnique<IPC::Decoder>(buffer, bufferSize, nullptr, Vector<IPC::Attachment> { });
     185            LoadParameters loadParameters;
     186            String sandboxExtensionPath;
     187            if (decoder->decode(loadParameters) && decoder->decode(sandboxExtensionPath)) {
     188                SandboxExtension::createHandleForReadByPid(sandboxExtensionPath, processIdentifier(), loadParameters.sandboxExtensionHandle);
     189                send(Messages::WebPage::LoadRequest(loadParameters), decoder->destinationID());
     190                continue;
     191            }
     192        }
     193#endif
    178194        m_connection->sendMessage(WTFMove(message), sendOptions);
    179195    }
  • trunk/Source/WebKit/UIProcess/WebPageProxy.cpp

    r249501 r249649  
    10721072#if HAVE(SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID)
    10731073        if (SandboxExtension::createHandleForReadByPid(resourceDirectoryURL.fileSystemPath(), process.processIdentifier(), sandboxExtensionHandle)) {
    1074             m_process->assumeReadAccessToBaseURL(*this, resourceDirectoryURL);
     1074            process.assumeReadAccessToBaseURL(*this, resourceDirectoryURL);
    10751075            return;
    10761076        }
    1077 #endif
     1077#else
    10781078        if (SandboxExtension::createHandle(resourceDirectoryURL.fileSystemPath(), SandboxExtension::Type::ReadOnly, sandboxExtensionHandle)) {
    1079             m_process->assumeReadAccessToBaseURL(*this, resourceDirectoryURL);
     1079            process.assumeReadAccessToBaseURL(*this, resourceDirectoryURL);
    10801080            return;
    10811081        }
     1082#endif
    10821083    }
    10831084
     
    10931094        return;
    10941095    }
    1095 #endif
     1096#else
    10961097    if (SandboxExtension::createHandle("/", SandboxExtension::Type::ReadOnly, sandboxExtensionHandle)) {
    10971098        willAcquireUniversalFileReadSandboxExtension(process);
    10981099        return;
    10991100    }
     1101#endif
    11001102
    11011103#if PLATFORM(COCOA)
     
    11071109    auto baseURL = URL(URL(), url.baseAsString());
    11081110    auto basePath = baseURL.fileSystemPath();
    1109     if (!basePath.isNull() && SandboxExtension::createHandle(basePath, SandboxExtension::Type::ReadOnly, sandboxExtensionHandle))
    1110         m_process->assumeReadAccessToBaseURL(*this, baseURL);
     1111    if (basePath.isNull())
     1112        return;
     1113#if HAVE(SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID)
     1114    if (SandboxExtension::createHandleForReadByPid(basePath, process.processIdentifier(), sandboxExtensionHandle))
     1115        process.assumeReadAccessToBaseURL(*this, baseURL);
     1116#else
     1117    if (SandboxExtension::createHandle(basePath, SandboxExtension::Type::ReadOnly, sandboxExtensionHandle))
     1118        process.assumeReadAccessToBaseURL(*this, baseURL);
     1119#endif
    11111120}
    11121121
     
    11661175    addPlatformLoadParameters(loadParameters);
    11671176
     1177#if HAVE(SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID)
     1178    if (processIdentifier() || !url.isLocalFile())
     1179        process->send(Messages::WebPage::LoadRequest(loadParameters), webPageID);
     1180    else {
     1181        String sandboxExtensionPath;
     1182        if (!m_pageLoadState.resourceDirectoryURL().isEmpty()) {
     1183            sandboxExtensionPath = m_pageLoadState.resourceDirectoryURL().fileSystemPath();
     1184            process->assumeReadAccessToBaseURL(*this, m_pageLoadState.resourceDirectoryURL());
     1185        } else {
     1186            sandboxExtensionPath = "/";
     1187            willAcquireUniversalFileReadSandboxExtension(process);
     1188        }
     1189        process->send(Messages::WebPage::LoadRequestWaitingForPID(loadParameters, sandboxExtensionPath), webPageID);
     1190    }
     1191#else
    11681192    process->send(Messages::WebPage::LoadRequest(loadParameters), webPageID);
     1193#endif
    11691194    process->responsivenessTimer().start();
    11701195}
     
    12131238    loadParameters.userData = UserData(process().transformObjectsToHandles(userData).get());
    12141239#if HAVE(SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID)
    1215     if (!SandboxExtension::createHandleForReadByPid(resourceDirectoryPath, processIdentifier(), loadParameters.sandboxExtensionHandle))
    1216 #endif
     1240    SandboxExtension::createHandleForReadByPid(resourceDirectoryPath, processIdentifier(), loadParameters.sandboxExtensionHandle);
     1241#else
    12171242    SandboxExtension::createHandle(resourceDirectoryPath, SandboxExtension::Type::ReadOnly, loadParameters.sandboxExtensionHandle);
     1243#endif
    12181244    addPlatformLoadParameters(loadParameters);
    12191245
    12201246    m_process->assumeReadAccessToBaseURL(*this, resourceDirectoryURL);
     1247#if HAVE(SANDBOX_ISSUE_READ_EXTENSION_TO_PROCESS_BY_PID)
     1248    if (processIdentifier())
     1249        m_process->send(Messages::WebPage::LoadRequest(loadParameters), m_webPageID);
     1250    else
     1251        m_process->send(Messages::WebPage::LoadRequestWaitingForPID(loadParameters, resourceDirectoryPath), m_webPageID);
     1252#else
    12211253    m_process->send(Messages::WebPage::LoadRequest(loadParameters), m_webPageID);
     1254#endif
    12221255    m_process->responsivenessTimer().start();
    12231256
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r249501 r249649  
    15541554}
    15551555
     1556// LoadRequestWaitingForPID should never be sent to the WebProcess. It must always be converted to a LoadRequest message.
     1557NO_RETURN void WebPage::loadRequestWaitingForPID(LoadParameters&&, const String&)
     1558{
     1559    RELEASE_ASSERT_NOT_REACHED();
     1560}
     1561
    15561562void WebPage::loadDataImpl(uint64_t navigationID, bool shouldTreatAsContinuingLoad, Optional<WebsitePoliciesData>&& websitePolicies, Ref<SharedBuffer>&& sharedBuffer, const String& MIMEType, const String& encodingName, const URL& baseURL, const URL& unreachableURL, const UserData& userData, ShouldOpenExternalURLsPolicy shouldOpenExternalURLsPolicy)
    15571563{
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r249435 r249649  
    13181318    void platformDidReceiveLoadParameters(const LoadParameters&);
    13191319    void loadRequest(LoadParameters&&);
     1320    void loadRequestWaitingForPID(LoadParameters&&, const String&);
    13201321    void loadData(LoadParameters&&);
    13211322    void loadAlternateHTML(LoadParameters&&);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r249093 r249649  
    166166    LoadDataInFrame(IPC::DataReference data, String MIMEType, String encodingName, URL baseURL, WebCore::FrameIdentifier frameID)
    167167    LoadRequest(struct WebKit::LoadParameters loadParameters)
     168    LoadRequestWaitingForPID(struct WebKit::LoadParameters loadParameters, String sandboxExtensionPath)
    168169    LoadData(struct WebKit::LoadParameters loadParameters)
    169170    LoadAlternateHTML(struct WebKit::LoadParameters loadParameters)
Note: See TracChangeset for help on using the changeset viewer.