New issue
Advanced search Search tips
Starred by 2 users
Status: Fixed
Owner:
Closed: Mar 2017
Cc:



Sign in to add a comment
MacOS/iOS kernel memory corruption due to bad bounds checking in SIOCSIFORDER socket ioctl
Project Member Reported by ianbeer@google.com, Feb 2 2017 Back to list
SIOCSIFORDER is a new ioctl added in iOS 10. It can be called on a regular tcp socket, so from pretty much any sandbox.

it falls through to calling:
  ifnet_reset_order(ordered_indices, ifo->ifo_count)
where ordered_indicies points to attacker-controlled bytes.

ifnet_reset_order contains this code:

  for (u_int32_t order_index = 0; order_index < count; order_index++) {
    u_int32_t interface_index = ordered_indices[order_index];  <---------------- (a)
    if (interface_index == IFSCOPE_NONE ||
        (int)interface_index > if_index) {           <-------------------------- (b)
      break;
    }
    ifp = ifindex2ifnet[interface_index];            <-------------------------- (c)
    if (ifp == NULL) {
      continue;
    }
    ifnet_lock_exclusive(ifp);
    TAILQ_INSERT_TAIL(&ifnet_ordered_head, ifp, if_ordered_link);    <---------- (d)
    ifnet_lock_done(ifp);
    if_ordered_count++;
  }

at (a) a controlled 32-bit value is read into an unsigned 32-bit variable.
at (b) this value is cast to a signed type for a bounds check
at (c) this value is used as an unsigned index

by providing a value with the most-significant bit set making it negative when cast to a signed type
we can pass the bounds check at (b) and lead to reading an interface pointer out-of-bounds
below the ifindex2ifnet array.

This leads very directly to memory corruption at (d) which will add the value read out of bounds to a list structure.

tested on MacOS 10.12.3 (16D32) on MacbookAir5,2
 
sioctl.c
2.1 KB View Download
Project Member Comment 1 by ianbeer@google.com, Feb 2 2017
Labels: Id-658437898 Reported-2017-Feb-02
Summary: MacOS/iOS kernel memory corruption due to bad bounds checking in SIOCSIFORDER socket ioctl (was: MacOS/iOS kernel memory corruption due to Bad bounds checking in SIOCSIFORDER socket ioctl)
Project Member Comment 2 by ianbeer@google.com, Feb 2 2017
(on 64-bit platforms the array index wouldn't wrap around so the read would actually occur > 2GB above the array, not below)
Project Member Comment 3 by ianbeer@google.com, Mar 31 2017
Labels: Fixed-2017-Mar-27 CVE-2017-2473
Status: Fixed
Fixed in MacOS 10.12.4: https://support.apple.com/en-us/HT207615
Fixed in iOS 10.3: https://support.apple.com/en-us/HT207617
Project Member Comment 4 by ianbeer@google.com, Apr 3 2017
Cc: ianbeer@google.com
 Issue 1115  has been merged into this issue.
Project Member Comment 5 by ianbeer@google.com, Apr 3 2017
Labels: -Restrict-View-Commit
Sign in to add a comment