DisARMing the Samsung S6E boot loader
Jonathan Levin, http://NewAndroidBook.com, 06/11/16
A while ago someone asked me for help with pointers on disassembling the Samsung 6E bootloader. I told him I'd get back to him, but with all my attention drawn into MOX*I for the big upcoming release, I didn't have much time to. Recently, however, while working on disassembling iOS's iBoot 64, I realized the same tool can be used for pretty much any ARM64 - including Samsung's sboot. So here is a writeup which shows the approach to disassembling pretty much any AArch64 boot loader, but Samsung's in particular. I'll also release a slide set on this after my MOSec talk on bootloaders at the beginning of July.
disarm
is an instruction I have read the full ARM documentation about. Maybe that's why still relatively few are :-P
Prereqs
- You'd want to follow along with The Samsung bootloader file (which you can get from their software image, or from your device, normally in
/dev/sdb or somewhere). - The
disarm
tool
Booting AArch64, in a nutshell
There are surprisingly little reference on the web to ARM's 64-bit boot process, though ARM themselves have superior documentation in the infocenter website. The architecture is quite different from the 32-bit architecture, which I've also covered in the reversing Aboot article on this website and in the book.
The first difference is that the processor boots into the most privileged exception level - EL3. This is somewhat akin to Intel's Ring 0, though in some ways more accurately following the ring model*. Think of it this way:
- EL3 is the most privileged level - reserved for the "Secure Monitor"
- EL2 is slighly less privileged, and runs Hypervisors (virtualization software), if any
- EL1 is where kernel mode is
- EL0 is plain old user mode
As with the Intel model, every ring has the abilities of its lesser rings, meaning EL0 ⊆ EL1 ⊆ EL2 ⊆ EL3. And, likewise, some instructions are only allowed at some exception levels. Moving in between the exception levels is performed by .. well.. exceptions! When an exception occurs, it automatically gets trapped by an exception vector of the higher level, which performs it and then returns back to the (less-privileged) origin level by means of a specialized instruction, ERET
.
The processor has distinct register sets for each exception levels, which are separate from the normal set (i.e. not part of X0..X29,LR,SP,PC). As a general rule, when in Exception Level x, you have full power over your own ELx registers, as those of ELx-1, but not those of ELx+1 (if any), which are entirely invisible to you. It is this level of physical separation that forms the basis for all of ARM's security architecture.
sboot
Looking at the file with disarm
we see:
I'm sure IDA has a way to display this in branching view, but the version of IDA64 I used was so #@%#@$% I couldn't even get it to just perform the simple disassembly disarm
does.