New issue
Advanced search Search tips
Starred by 1 user
Status: Fixed
Owner:
Closed: Jan 2017
Cc:



Sign in to add a comment
MacOS/iOS kernel use after free due to failure to take reference in IOService::matchPassive
Project Member Reported by ianbeer@google.com, Oct 25 2016 Back to list
IOService::matchPassive is called when trying to match a request dictionary against a candidate IOService.
We can call this function on a controlled IOService with a controlled matching table OSDictionary via the
io_service_match_property_table_* kernel MIG APIs wrapped by IOServiceMatchPropertyTable.

If a candidate IOService does match against the dictionary but the dictionary also specifies an
"IOParentMatch" key then we reach the following code (in IOService.cpp:)

  OSNumber* alternateRegistryID = OSDynamicCast(OSNumber, where->getProperty(kIOServiceLegacyMatchingRegistryIDKey));
  if(alternateRegistryID != NULL) {
    if(aliasServiceRegIds == NULL)
    {
      aliasServiceRegIds = OSArray::withCapacity(sizeof(alternateRegistryID));
    }
    aliasServiceRegIds->setObject(alternateRegistryID);
  }

("where" is the controlled IOService.)
getProperty is an IORegistryEntry API which directly calls the getObject method
of the OSDictionary holding the entry's properties. getProperty, unlike copyProperty, doesn't take a reference on
the value of the property which means that there is a short window between

  where->getProperty(kIOServiceLegacyMatchingRegistryIDKey)
and
  aliasServiceRegIds->setObject(alternateRegistryID)

when if another thread sets a new value for the IOService's "IOServiceLegacyMatchingRegistryID" registry property
the alternateRegistryID OSNumber can be freed. This race condition can be won quite easily and can lead to a virtual call
being performed on a free'd object.

On MacOS IOBluetoothHCIController is one of a number of IOServices which allow an unprivileged user to set the
IOServiceLegacyMatchingRegistryID property.

One approach to fixing this bug would be to call copyProperty instead and drop the ref on the property after adding it
to the aliasServiceRegIds array.

Tested on MacOS Sierra 10.12.1 (16B2555)
 
iorace.c
3.9 KB View Download
Project Member Comment 1 by ianbeer@google.com, Oct 25 2016
Labels: Id-651078322 Reported-2016-Oct-25
Project Member Comment 2 by ianbeer@google.com, Jan 25 2017
Labels: Fixed-2017-Jan-23 CVE-2017-2353
MacOS advisory: https://support.apple.com/en-us/HT207483
Project Member Comment 3 by ianbeer@google.com, Jan 25 2017
Status: Fixed
Project Member Comment 4 by ianbeer@google.com, Jan 25 2017
Cc: ianbeer@google.com
 Issue 975  has been merged into this issue.
Project Member Comment 5 by ianbeer@google.com, Jan 25 2017
Labels: -Restrict-View-Commit
Sign in to add a comment