Changeset 230045 in webkit


Ignore:
Timestamp:
Mar 28, 2018 1:43:10 PM (6 years ago)
Author:
Brent Fulgham
Message:

Protect against invalid mach ports returned by mach_port_request_notification
https://bugs.webkit.org/show_bug.cgi?id=184106
<rdar://problem/37865316>

Reviewed by Chris Dumez.

Source/WebKit:

  • Platform/IPC/Connection.h:

(IPC::Connection::Identifier::Identifier): Use default initializer syntax.

  • Platform/IPC/mac/ConnectionMac.mm:

(IPC::Connection::open): Drive-by-fix: Include formatted mach error message in logging.
(IPC::Connection::receiveSourceEventHandler): Check return value from 'mach_port_request_notification'
and clean up if it experienced an error.

  • UIProcess/Launcher/mac/ProcessLauncherMac.mm:

(WebKit::ProcessLauncher::launchProcess): Ditto.

Source/WebKitLegacy/mac:

  • Plugins/Hosted/NetscapePluginHostProxy.mm:

(WebKit::NetscapePluginHostProxy::NetscapePluginHostProxy): Check return value from 'mach_port_request_notification'
and clean up if it experienced an error.
(WebKit::NetscapePluginHostProxy::processRequests): Drive-by-fix: Include formatted mach error message in logging.

Location:
trunk/Source
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r230041 r230045  
     12018-03-28  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Protect against invalid mach ports returned by mach_port_request_notification
     4        https://bugs.webkit.org/show_bug.cgi?id=184106
     5        <rdar://problem/37865316>
     6
     7        Reviewed by Chris Dumez.
     8
     9        * Platform/IPC/Connection.h:
     10        (IPC::Connection::Identifier::Identifier): Use default initializer syntax.
     11        * Platform/IPC/mac/ConnectionMac.mm:
     12        (IPC::Connection::open): Drive-by-fix: Include formatted mach error message in logging.
     13        (IPC::Connection::receiveSourceEventHandler): Check return value from 'mach_port_request_notification'
     14        and clean up if it experienced an error.
     15        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
     16        (WebKit::ProcessLauncher::launchProcess): Ditto.
     17
    1182018-03-28  Dean Jackson  <dino@apple.com>
    219
  • trunk/Source/WebKit/Platform/IPC/Connection.h

    r230035 r230045  
    11/*
    2  * Copyright (C) 2010-2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2018 Apple Inc. All rights reserved.
    33 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
    44 * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
     
    117117    struct Identifier {
    118118        Identifier()
    119             : port(MACH_PORT_NULL)
    120119        {
    121120        }
     
    132131        }
    133132
    134         mach_port_t port;
     133        mach_port_t port { MACH_PORT_NULL };
    135134        OSObjectPtr<xpc_connection_t> xpcConnection;
    136135    };
  • trunk/Source/WebKit/Platform/IPC/mac/ConnectionMac.mm

    r230035 r230045  
    187187        auto kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &m_receivePort);
    188188        if (kr != KERN_SUCCESS) {
    189             LOG_ERROR("Could not allocate mach port, error %x", kr);
     189            LOG_ERROR("Could not allocate mach port, error %x: %s", kr, mach_error_string(kr));
    190190            CRASH();
    191191        }
     
    534534        if (m_sendPort) {
    535535            mach_port_t previousNotificationPort = MACH_PORT_NULL;
    536             mach_port_request_notification(mach_task_self(), m_receivePort, MACH_NOTIFY_NO_SENDERS, 0, MACH_PORT_NULL, MACH_MSG_TYPE_MOVE_SEND_ONCE, &previousNotificationPort);
     536            auto kr = mach_port_request_notification(mach_task_self(), m_receivePort, MACH_NOTIFY_NO_SENDERS, 0, MACH_PORT_NULL, MACH_MSG_TYPE_MOVE_SEND_ONCE, &previousNotificationPort);
     537            ASSERT(kr == KERN_SUCCESS);
     538            if (kr != KERN_SUCCESS) {
     539                // If mach_port_request_notification fails, 'previousNotificationPort' will be uninitialized.
     540                LOG_ERROR("mach_port_request_notification failed: (%x) %s", kr, mach_error_string(kr));
     541                previousNotificationPort = MACH_PORT_NULL;
     542            }
    537543
    538544            if (previousNotificationPort != MACH_PORT_NULL)
  • trunk/Source/WebKit/UIProcess/Launcher/mac/ProcessLauncherMac.mm

    r230035 r230045  
    154154    auto kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &listeningPort);
    155155    if (kr != KERN_SUCCESS) {
    156         LOG_ERROR("Could not allocate mach port, error %x", kr);
     156        LOG_ERROR("Could not allocate mach port, error %x: %s", kr, mach_error_string(kr));
    157157        CRASH();
    158158    }
     
    161161    mach_port_insert_right(mach_task_self(), listeningPort, listeningPort, MACH_MSG_TYPE_MAKE_SEND);
    162162
    163     mach_port_t previousNotificationPort;
    164     mach_port_request_notification(mach_task_self(), listeningPort, MACH_NOTIFY_NO_SENDERS, 0, listeningPort, MACH_MSG_TYPE_MAKE_SEND_ONCE, &previousNotificationPort);
     163    mach_port_t previousNotificationPort = MACH_PORT_NULL;
     164    auto mc = mach_port_request_notification(mach_task_self(), listeningPort, MACH_NOTIFY_NO_SENDERS, 0, listeningPort, MACH_MSG_TYPE_MAKE_SEND_ONCE, &previousNotificationPort);
    165165    ASSERT(!previousNotificationPort);
     166    ASSERT(mc == KERN_SUCCESS);
     167    if (mc != KERN_SUCCESS) {
     168        // If mach_port_request_notification fails, 'previousNotificationPort' will be uninitialized.
     169        LOG_ERROR("mach_port_request_notification failed: (%x) %s", mc, mach_error_string(mc));
     170    }
    166171
    167172    String clientIdentifier;
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r230035 r230045  
     12018-03-28  Brent Fulgham  <bfulgham@apple.com>
     2
     3        Protect against invalid mach ports returned by mach_port_request_notification
     4        https://bugs.webkit.org/show_bug.cgi?id=184106
     5        <rdar://problem/37865316>
     6
     7        Reviewed by Chris Dumez.
     8
     9        * Plugins/Hosted/NetscapePluginHostProxy.mm:
     10        (WebKit::NetscapePluginHostProxy::NetscapePluginHostProxy): Check return value from 'mach_port_request_notification'
     11        and clean up if it experienced an error.
     12        (WebKit::NetscapePluginHostProxy::processRequests): Drive-by-fix: Include formatted mach error message in logging.
     13
    1142018-03-28  Brent Fulgham  <bfulgham@apple.com>
    215
  • trunk/Source/WebKitLegacy/mac/Plugins/Hosted/NetscapePluginHostProxy.mm

    r230035 r230045  
    112112
    113113    mach_port_t previous = MACH_PORT_NULL;
    114     mach_port_request_notification(mach_task_self(), pluginHostPort, MACH_NOTIFY_DEAD_NAME, 0,
    115                                    CFMachPortGetPort(m_deadNameNotificationPort.get()), MACH_MSG_TYPE_MAKE_SEND_ONCE, &previous);
     114    auto kr = mach_port_request_notification(mach_task_self(), pluginHostPort, MACH_NOTIFY_DEAD_NAME, 0,
     115        CFMachPortGetPort(m_deadNameNotificationPort.get()), MACH_MSG_TYPE_MAKE_SEND_ONCE, &previous);
    116116    ASSERT(previous == MACH_PORT_NULL);
    117    
     117    ASSERT(kr == KERN_SUCCESS);
     118    if (kr != KERN_SUCCESS) {
     119        // If mach_port_request_notification fails, 'previous' will be uninitialized.
     120        LOG_ERROR("mach_port_request_notification failed: (%x) %s", kr, mach_error_string(kr));
     121        previous = MACH_PORT_NULL;
     122    }
     123
    118124    RetainPtr<CFRunLoopSourceRef> deathPortSource = adoptCF(CFMachPortCreateRunLoopSource(0, m_deadNameNotificationPort.get(), 0));
    119125   
     
    285291        auto kr = mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_PORT_SET, &m_portSet);
    286292        if (kr != KERN_SUCCESS) {
    287             LOG_ERROR("Could not allocate mach port, error %x", kr);
     293            LOG_ERROR("Could not allocate mach port, error %x: %s", kr, mach_error_string(kr));
    288294            CRASH();
    289295        }
     
    299305   
    300306    if (kr != KERN_SUCCESS) {
    301         LOG_ERROR("Could not receive mach message, error %x", kr);
     307        LOG_ERROR("Could not receive mach message, error %x: %s", kr, mach_error_string(kr));
    302308        s_processingRequests--;
    303309        return false;
     
    312318           
    313319            if (kr != KERN_SUCCESS) {
    314                 LOG_ERROR("Could not send mach message, error %x", kr);
     320                LOG_ERROR("Could not send mach message, error %x: %s", kr, mach_error_string(kr));
    315321                s_processingRequests--;
    316322                return false;
Note: See TracChangeset for help on using the changeset viewer.