Changeset 275486 in webkit


Ignore:
Timestamp:
Apr 5, 2021 9:02:40 PM (3 years ago)
Author:
commit-queue@webkit.org
Message:

Reduce crash inside getAuditToken
https://bugs.webkit.org/show_bug.cgi?id=224196
<rdar://74536285>

Patch by Alex Christensen <achristensen@webkit.org> on 2021-04-05
Reviewed by David Kilzer.

Something is crashing inside the call to getAuditToken, and I believe it is happening during teardown of the network process.
After many days of head scratching and many previous attempts at fixing this problem, it persists.
Since direct strategies at fixing this problem have failed, I now try something different.
Instead of calling getAuditToken at the beginning of every resource load to ask if the parent process has an entitlement,
I now call it only once per process. That should make things faster and less crashy. Otherwise no change in behavior.

  • NetworkProcess/cocoa/NetworkSessionCocoa.mm:

(WebKit::activateSessionCleanup):
(WebKit::NetworkSessionCocoa::sessionWrapperForTask):

  • Shared/Cocoa/DefaultWebBrowserChecks.h:
  • Shared/Cocoa/DefaultWebBrowserChecks.mm:

(WebKit::doesParentProcessHaveITPEnabled):
(WebKit::isParentProcessAFullWebBrowser):

  • WebProcess/WebAuthentication/WebAuthenticatorCoordinator.cpp:

(WebKit::WebCore::isWebBrowser):

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::isParentProcessAWebBrowser const):

Location:
trunk/Source/WebKit
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r275485 r275486  
     12021-04-05  Alex Christensen  <achristensen@webkit.org>
     2
     3        Reduce crash inside getAuditToken
     4        https://bugs.webkit.org/show_bug.cgi?id=224196
     5        <rdar://74536285>
     6
     7        Reviewed by David Kilzer.
     8
     9        Something is crashing inside the call to getAuditToken, and I believe it is happening during teardown of the network process.
     10        After many days of head scratching and many previous attempts at fixing this problem, it persists.
     11        Since direct strategies at fixing this problem have failed, I now try something different.
     12        Instead of calling getAuditToken at the beginning of every resource load to ask if the parent process has an entitlement,
     13        I now call it only once per process.  That should make things faster and less crashy.  Otherwise no change in behavior.
     14
     15        * NetworkProcess/cocoa/NetworkSessionCocoa.mm:
     16        (WebKit::activateSessionCleanup):
     17        (WebKit::NetworkSessionCocoa::sessionWrapperForTask):
     18        * Shared/Cocoa/DefaultWebBrowserChecks.h:
     19        * Shared/Cocoa/DefaultWebBrowserChecks.mm:
     20        (WebKit::doesParentProcessHaveITPEnabled):
     21        (WebKit::isParentProcessAFullWebBrowser):
     22        * WebProcess/WebAuthentication/WebAuthenticatorCoordinator.cpp:
     23        (WebKit::WebCore::isWebBrowser):
     24        * WebProcess/WebPage/WebPage.cpp:
     25        (WebKit::WebPage::isParentProcessAWebBrowser const):
     26
    1272021-04-05  Chris Dumez  <cdumez@apple.com>
    228
  • trunk/Source/WebKit/NetworkProcess/cocoa/NetworkSessionCocoa.mm

    r275415 r275486  
    11461146
    11471147#if !PLATFORM(IOS_FAMILY_SIMULATOR)
    1148     auto parentAuditToken = session.networkProcess().parentProcessConnection()->getAuditToken();
    1149     RELEASE_ASSERT(parentAuditToken); // This should be impossible.
    1150 
    1151     bool itpEnabled = doesParentProcessHaveITPEnabled(parentAuditToken, parameters.appHasRequestedCrossWebsiteTrackingPermission);
     1148    bool itpEnabled = doesParentProcessHaveITPEnabled(session.networkProcess(), parameters.appHasRequestedCrossWebsiteTrackingPermission);
    11521149    bool passedEnabledState = session.isResourceLoadStatisticsEnabled();
    11531150
     
    13511348{
    13521349    auto shouldBeConsideredAppBound = isNavigatingToAppBoundDomain ? *isNavigatingToAppBoundDomain : NavigatingToAppBoundDomain::Yes;
    1353     if (RefPtr<IPC::Connection> connection = networkProcess().parentProcessConnection()) {
    1354         if (isParentProcessAFullWebBrowser(connection->getAuditToken()))
    1355             shouldBeConsideredAppBound = NavigatingToAppBoundDomain::No;
    1356     }
     1350    if (isParentProcessAFullWebBrowser(networkProcess()))
     1351        shouldBeConsideredAppBound = NavigatingToAppBoundDomain::No;
    13571352#if ENABLE(RESOURCE_LOAD_STATISTICS)
    13581353    if (auto* storageSession = networkStorageSession()) {
  • trunk/Source/WebKit/Shared/Cocoa/DefaultWebBrowserChecks.h

    r271283 r275486  
    3535namespace WebKit {
    3636
     37class AuxiliaryProcess;
     38
    3739bool hasRequestedCrossWebsiteTrackingPermission();
    3840bool hasProhibitedUsageStrings();
     
    4143void determineITPState();
    4244bool doesAppHaveITPEnabled();
    43 bool doesParentProcessHaveITPEnabled(Optional<audit_token_t>, bool);
     45bool doesParentProcessHaveITPEnabled(AuxiliaryProcess&, bool hasRequestedCrossWebsiteTrackingPermission);
    4446bool isFullWebBrowser();
    45 bool isParentProcessAFullWebBrowser(Optional<audit_token_t>);
     47bool isParentProcessAFullWebBrowser(AuxiliaryProcess&);
     48
     49#define WEBKIT_PARENT_PROCESS_FULL_WEB_BROWSER_PARAMETER_AUXILIARY_PROCESS 1
    4650
    4751} // namespace WebKit
  • trunk/Source/WebKit/Shared/Cocoa/DefaultWebBrowserChecks.mm

    r275410 r275486  
    2727#import "DefaultWebBrowserChecks.h"
    2828
     29#import "AuxiliaryProcess.h"
     30#import "Connection.h"
     31#import "Logging.h"
    2932#import "TCCSPI.h"
    3033#import <WebCore/RegistrableDomain.h>
     
    156159}
    157160
    158 bool doesParentProcessHaveITPEnabled(Optional<audit_token_t> auditToken, bool hasRequestedCrossWebsiteTrackingPermissionValue)
     161bool doesParentProcessHaveITPEnabled(AuxiliaryProcess& auxiliaryProcess, bool hasRequestedCrossWebsiteTrackingPermission)
    159162{
    160163    ASSERT(isInWebKitChildProcess());
    161164    ASSERT(RunLoop::isMain());
    162165
    163     if (!isParentProcessAFullWebBrowser(auditToken) && !hasRequestedCrossWebsiteTrackingPermissionValue)
    164         return true;
    165 
    166     TCCAccessPreflightResult result = kTCCAccessPreflightDenied;
     166    static bool itpEnabled { true };
     167    static dispatch_once_t once;
     168    dispatch_once(&once, ^{
     169        if (!isParentProcessAFullWebBrowser(auxiliaryProcess) && !hasRequestedCrossWebsiteTrackingPermission)
     170            return;
     171
     172        TCCAccessPreflightResult result = kTCCAccessPreflightDenied;
    167173#if (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000)
    168     if (auditToken)
     174        RefPtr<IPC::Connection> connection = auxiliaryProcess.parentProcessConnection();
     175        if (!connection) {
     176            ASSERT_NOT_REACHED();
     177            RELEASE_LOG_ERROR(IPC, "Unable to get parent process connection");
     178            return;
     179        }
     180
     181        auto auditToken = connection->getAuditToken();
     182        if (!auditToken) {
     183            ASSERT_NOT_REACHED();
     184            RELEASE_LOG_ERROR(IPC, "Unable to get parent process audit token");
     185            return;
     186        }
    169187        result = TCCAccessPreflightWithAuditToken(getkTCCServiceWebKitIntelligentTrackingPrevention(), auditToken.value(), nullptr);
    170188#endif
    171     return result != kTCCAccessPreflightDenied;
     189        itpEnabled = result != kTCCAccessPreflightDenied;
     190    });
     191    return itpEnabled;
    172192}
    173193
     
    208228}
    209229
    210 bool isParentProcessAFullWebBrowser(Optional<audit_token_t> auditToken)
     230bool isParentProcessAFullWebBrowser(AuxiliaryProcess& auxiliaryProcess)
    211231{
    212232    ASSERT(isInWebKitChildProcess());
    213     if (!auditToken)
    214         return false;
    215 
    216     static bool fullWebBrowser;
    217 
     233
     234    static bool fullWebBrowser { false };
    218235    static dispatch_once_t once;
    219236    dispatch_once(&once, ^{
    220         fullWebBrowser = WTF::hasEntitlement(auditToken.value(), "com.apple.developer.web-browser");
    221     });
    222 
    223     return fullWebBrowser || isRunningTest(WebCore::applicationBundleIdentifier());
     237        if (isRunningTest(WebCore::applicationBundleIdentifier())) {
     238            fullWebBrowser = true;
     239            return;
     240        }
     241
     242        RefPtr<IPC::Connection> connection = auxiliaryProcess.parentProcessConnection();
     243        if (!connection) {
     244            ASSERT_NOT_REACHED();
     245            RELEASE_LOG_ERROR(IPC, "Unable to get parent process connection");
     246            return;
     247        }
     248
     249        auto auditToken = connection->getAuditToken();
     250        if (!auditToken) {
     251            ASSERT_NOT_REACHED();
     252            RELEASE_LOG_ERROR(IPC, "Unable to get parent process audit token");
     253            return;
     254        }
     255
     256        fullWebBrowser = WTF::hasEntitlement(*auditToken, "com.apple.developer.web-browser");
     257    });
     258
     259    return fullWebBrowser;
    224260}
    225261
  • trunk/Source/WebKit/WebProcess/WebAuthentication/WebAuthenticatorCoordinator.cpp

    r272345 r275486  
    5151
    5252namespace {
    53 static bool isWebBrowser()
     53inline bool isWebBrowser()
    5454{
    55     if (auto* connection = WebProcess::singleton().parentProcessConnection())
    56         return isParentProcessAFullWebBrowser(connection->getAuditToken());
    57     return false;
     55    return isParentProcessAFullWebBrowser(WebProcess::singleton());
    5856}
    5957}
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r275485 r275486  
    38273827{
    38283828#if HAVE(AUDIT_TOKEN)
    3829     if (auto* connection = WebProcess::singleton().parentProcessConnection())
    3830         return isParentProcessAFullWebBrowser(connection->getAuditToken());
     3829    return isParentProcessAFullWebBrowser(WebProcess::singleton());
    38313830#endif
    38323831    return false;
Note: See TracChangeset for help on using the changeset viewer.