You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
with <str<strong>on</strong>g>the</str<strong>on</strong>g> platform/<strong>iOS</strong> combinati<strong>on</strong>. The developers <str<strong>on</strong>g>of</str<strong>on</strong>g> Stage 2 have mapped out each<br />
combinati<strong>on</strong> <str<strong>on</strong>g>of</str<strong>on</strong>g> platform/<strong>iOS</strong> to determine what positi<strong>on</strong> within <str<strong>on</strong>g>the</str<strong>on</strong>g> dataBuffer array a valid<br />
kernel locati<strong>on</strong> is present.<br />
If Stage 2 is unable to find <str<strong>on</strong>g>the</str<strong>on</strong>g> base address for <str<strong>on</strong>g>the</str<strong>on</strong>g> kernel using <str<strong>on</strong>g>the</str<strong>on</strong>g> above described method or<br />
if Stage 2 finds that it is operating under a versi<strong>on</strong> <str<strong>on</strong>g>of</str<strong>on</strong>g> <strong>iOS</strong> o<str<strong>on</strong>g>the</str<strong>on</strong>g>r than 9, <str<strong>on</strong>g>the</str<strong>on</strong>g> assert callback is<br />
called and <str<strong>on</strong>g>the</str<strong>on</strong>g> applicati<strong>on</strong> terminates.<br />
Establishing Read/Write/Execute Primitives <strong>on</strong> Previously Rooted<br />
Devices (32-Bit)<br />
After finding <str<strong>on</strong>g>the</str<strong>on</strong>g> kernel’s base address, 32Stage2 generates an IPC pipe set via <str<strong>on</strong>g>the</str<strong>on</strong>g> pipe<br />
functi<strong>on</strong>. If <str<strong>on</strong>g>the</str<strong>on</strong>g> pipe command fails, 32Stage2 calls <str<strong>on</strong>g>the</str<strong>on</strong>g> assert callback functi<strong>on</strong> and exits.<br />
Following <str<strong>on</strong>g>the</str<strong>on</strong>g> generati<strong>on</strong> <str<strong>on</strong>g>of</str<strong>on</strong>g> <str<strong>on</strong>g>the</str<strong>on</strong>g> pipe set, 32Stage2 uses a kernel port to obtain <str<strong>on</strong>g>the</str<strong>on</strong>g> clock<br />
services for <str<strong>on</strong>g>the</str<strong>on</strong>g> battery clock (also known as <str<strong>on</strong>g>the</str<strong>on</strong>g> calendar clock) and real-time clock via two<br />
calls to host_get_clock_service. If ei<str<strong>on</strong>g>the</str<strong>on</strong>g>r <str<strong>on</strong>g>of</str<strong>on</strong>g> <str<strong>on</strong>g>the</str<strong>on</strong>g> clocks are inaccessible, <str<strong>on</strong>g>the</str<strong>on</strong>g> asserti<strong>on</strong><br />
callback is called and 32Stage2 exits. The pipe set and <str<strong>on</strong>g>the</str<strong>on</strong>g> clock ports are critical to<br />
establishing a beachhead for gaining access to <str<strong>on</strong>g>the</str<strong>on</strong>g> kernel memory space as <str<strong>on</strong>g>the</str<strong>on</strong>g> combinati<strong>on</strong> <str<strong>on</strong>g>of</str<strong>on</strong>g><br />
<str<strong>on</strong>g>the</str<strong>on</strong>g> three objects (<str<strong>on</strong>g>the</str<strong>on</strong>g> pipe set and <str<strong>on</strong>g>the</str<strong>on</strong>g> two clocks) are later used for kernel memory read and<br />
write access as well as kernel process space executi<strong>on</strong> access.<br />
Immediately following <str<strong>on</strong>g>the</str<strong>on</strong>g> pipe and host_get_clock_service calls, 32Stage2 checks <str<strong>on</strong>g>the</str<strong>on</strong>g><br />
value <str<strong>on</strong>g>of</str<strong>on</strong>g> <str<strong>on</strong>g>the</str<strong>on</strong>g> port to <str<strong>on</strong>g>the</str<strong>on</strong>g> kernel that was generated previously by calling task_from_pid. If<br />
task_from_pid returned a valid (n<strong>on</strong>-NULL) port, 32Stage2 modifies <str<strong>on</strong>g>the</str<strong>on</strong>g> kernel’s memory by<br />
writing a 20-byte data structure using vm_write. The 20-byte data structure overwrites parts <str<strong>on</strong>g>of</str<strong>on</strong>g><br />
<str<strong>on</strong>g>the</str<strong>on</strong>g> clock_ops structures for calend_ops and rtclock_ops 3 .<br />
The 20-byte data structures c<strong>on</strong>tain pointers to handler functi<strong>on</strong>s for <str<strong>on</strong>g>the</str<strong>on</strong>g> battery clock and realtime<br />
clock that <str<strong>on</strong>g>the</str<strong>on</strong>g> kernel will call when functi<strong>on</strong>s such as clock_get_attributes are called<br />
(callback functi<strong>on</strong>s). The 20-byte data structure replaces <str<strong>on</strong>g>the</str<strong>on</strong>g> getattr handler for both <str<strong>on</strong>g>of</str<strong>on</strong>g> <str<strong>on</strong>g>the</str<strong>on</strong>g><br />
clock types with existing kernel functi<strong>on</strong>s. Specifically, <str<strong>on</strong>g>the</str<strong>on</strong>g> real-time clock’s getattr is modified<br />
to point to OSSerializer::serialize, and <str<strong>on</strong>g>the</str<strong>on</strong>g> battery clock’s getattr is modified to point<br />
to _bufattr_cpx.<br />
The choice <str<strong>on</strong>g>of</str<strong>on</strong>g> <str<strong>on</strong>g>the</str<strong>on</strong>g> replacement functi<strong>on</strong>s changes <str<strong>on</strong>g>the</str<strong>on</strong>g> nature <str<strong>on</strong>g>of</str<strong>on</strong>g> <str<strong>on</strong>g>the</str<strong>on</strong>g> clock_get_attributes<br />
call made to <str<strong>on</strong>g>the</str<strong>on</strong>g> two clock types. For calls to clock_get_attributes for <str<strong>on</strong>g>the</str<strong>on</strong>g> battery clock,<br />
<str<strong>on</strong>g>the</str<strong>on</strong>g> functi<strong>on</strong> now operates as a kernel memory read interface. The _bufattr_cpx functi<strong>on</strong><br />
c<strong>on</strong>tains <strong>on</strong>ly two instructi<strong>on</strong>s:<br />
_bufattr_cpx:<br />
LDR<br />
BX<br />
R0, [R0]<br />
LR<br />
3 http://opensource.apple.com/source/xnu/xnu-3248.20.55/osfmk/kern/clock_oldops.c<br />
Page 19