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

Changeset 268796 in webkit


Ignore:
Timestamp:
Oct 21, 2020, 9:01:31 AM (6 years ago)
Author:
commit-queue@webkit.org
Message:

Don't crash when deallocating WKWebView during TLS handshake
https://bugs.webkit.org/show_bug.cgi?id=218025
<rdar://problem/70225969>

Patch by Alex Christensen <achristensen@webkit.org> on 2020-10-21
Reviewed by Tim Horton.

Source/WebKit:

NetworkProcessProxy::didReceiveAuthenticationChallenge would sometimes dereference an unchecked
Optional<SecurityOriginData> which would result in a null dereference crash. Also, sometimes
Connection::initializeSendSource would assert because it was trying to set up a cancel handler for
a send port that had not been successfully set up yet. I added a test that reproduces both of these
issues most of the time.

  • Platform/IPC/cocoa/ConnectionCocoa.mm:

(IPC::Connection::initializeSendSource):

  • UIProcess/Network/NetworkProcessProxy.cpp:

(WebKit::NetworkProcessProxy::didReceiveAuthenticationChallenge):

Tools:

  • TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:

(TEST):

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r268793 r268796  
     12020-10-21  Alex Christensen  <achristensen@webkit.org>
     2
     3        Don't crash when deallocating WKWebView during TLS handshake
     4        https://bugs.webkit.org/show_bug.cgi?id=218025
     5        <rdar://problem/70225969>
     6
     7        Reviewed by Tim Horton.
     8
     9        NetworkProcessProxy::didReceiveAuthenticationChallenge would sometimes dereference an unchecked
     10        Optional<SecurityOriginData> which would result in a null dereference crash.  Also, sometimes
     11        Connection::initializeSendSource would assert because it was trying to set up a cancel handler for
     12        a send port that had not been successfully set up yet.  I added a test that reproduces both of these
     13        issues most of the time.
     14
     15        * Platform/IPC/cocoa/ConnectionCocoa.mm:
     16        (IPC::Connection::initializeSendSource):
     17        * UIProcess/Network/NetworkProcessProxy.cpp:
     18        (WebKit::NetworkProcessProxy::didReceiveAuthenticationChallenge):
     19
    1202020-10-21  Carlos Garcia Campos  <cgarcia@igalia.com>
    221
  • trunk/Source/WebKit/Platform/IPC/cocoa/ConnectionCocoa.mm

    r265344 r268796  
    395395    });
    396396
    397     ASSERT(MACH_PORT_VALID(m_sendPort));
    398     mach_port_t sendPort = m_sendPort;
    399     dispatch_source_set_cancel_handler(m_sendSource, ^{
    400         // Release our send right.
    401         deallocateSendRightSafely(sendPort);
    402     });
     397    if (MACH_PORT_VALID(m_sendPort)) {
     398        mach_port_t sendPort = m_sendPort;
     399        dispatch_source_set_cancel_handler(m_sendSource, ^{
     400            // Release our send right.
     401            deallocateSendRightSafely(sendPort);
     402        });
     403    }
    403404}
    404405
  • trunk/Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp

    r268458 r268796  
    433433    }
    434434
     435    if (!topOrigin) {
     436        authenticationChallenge->listener().completeChallenge(AuthenticationChallengeDisposition::RejectProtectionSpaceAndContinue);
     437        return;
     438    }
     439
    435440    WebPageProxy::forMostVisibleWebPageIfAny(sessionID, *topOrigin, [this, weakThis = makeWeakPtr(this), sessionID, authenticationChallenge = WTFMove(authenticationChallenge), negotiatedLegacyTLS](auto* page) mutable {
    436441        if (!weakThis)
  • trunk/Tools/ChangeLog

    r268795 r268796  
     12020-10-21  Alex Christensen  <achristensen@webkit.org>
     2
     3        Don't crash when deallocating WKWebView during TLS handshake
     4        https://bugs.webkit.org/show_bug.cgi?id=218025
     5        <rdar://problem/70225969>
     6
     7        Reviewed by Tim Horton.
     8
     9        * TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm:
     10        (TEST):
     11
    1122020-10-20  Sam Weinig  <weinig@apple.com>
    213
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Challenge.mm

    r266150 r268796  
    239239
    240240    Util::run(&navigationFinished);
     241}
     242
     243TEST(Challenge, DeallocateDuringChallenge)
     244{
     245    using namespace TestWebKitAPI;
     246    HTTPServer server({{ "/", { "hi" }}}, HTTPServer::Protocol::Https);
     247
     248    auto delegate = [[TestNavigationDelegate new] autorelease];
     249    delegate.didReceiveAuthenticationChallenge = ^(WKWebView *, NSURLAuthenticationChallenge *challenge, void (^completionHandler)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)) {
     250        completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
     251    };
     252
     253    @autoreleasepool {
     254        Vector<RetainPtr<WKWebView>> views;
     255        for (size_t i = 0; i < 100; i++)
     256            views.append(adoptNS([WKWebView new]));
     257        for (auto& view : views) {
     258            [view setNavigationDelegate:delegate];
     259            [view loadRequest:server.request()];
     260        }
     261        Util::spinRunLoop(10);
     262    }
     263    Util::spinRunLoop(1000);
    241264}
    242265
Note: See TracChangeset for help on using the changeset viewer.