# Mac OS X Mavericks IOBluetoothHCIUserClient Privilege Escalation
### 漏洞概述
简而言之,漏洞存在于IOBluetoothHCIUserClient::SimpleDispatchWL()这个函数中,这个函数需要用户提供一个32位带符号的整数值,然后把它指向一个包含函数指针的全局结构数组,这个函数指针最终被调用。不难看出,SimpleDispatchWL()没有正确处理用户提供的索引,如果用户能够控制这个函数指针,悲剧就发生了。
更多的细节我们用下面的伪代码来表述,在第14行,用户提供的一个32位整数值被转为64位。在第20行method_index参数带入了_sRoutines数组,在第23行被回调。
```
typedef struct { void (*function_pointer)();
uint64 num_arguments;
} BluetoothMethod;
BluetoothMethod _sRoutines[] = {
...
};
uint64 _sRoutineCount = sizeof(_sRoutines)/sizeof(BluetoothMethod);
IOReturn IOBluetoothHCIUserClient::SimpleDispatchWL(IOBluetoothHCIDispatchParams *params) { // Here "user_param" is a signed 32-bit integer parameter
int64 method_index = (int64) user_param; if (method_index >= _sRoutineCount) { return kIOReturnUnsupported;
}
BluetoothMethod method = _sRoutines[method_index];
... if (method.num_arguments < 8) {
method.function_pointer(...);
}
...
}
```
利用细节
详情请见下面的汇编代码
```
; r12+70h points to the user-supplied index value
mov ecx, [r12+70h]
mov r13d, kIOReturnUnsupported
lea rdx, _sRoutineCount
cmp ecx, [rdx]
jge fail
; Go on and fetch _sRoutine[method_index]
...
movsxd rax, ecx ; Sign extension to 64-bit value
shl rax, 4 ; method_index *= sizeof(BluetoothMethod)
lea rdx, _sRoutines
mov esi, [rdx+rax+8] ; esi = _sRoutines[method_index].num_arguments
cmp esi, 7 ; Check method.num_arguments < 8
ja loc_289BA
...
```
漏洞利用截图

### 漏洞修复
目前证实存在问题的系统包括
OS X Mavericks 10.9.4 和10.9.5,但是在新系统OS X Yosemite (10.10)上,这个漏洞被悄悄的修复了,苹果官方也没有任何安全公告提及这个漏洞。
