text stringlengths 0 1.99k |
|---|
the problems that they fixate on. When you think about it - "weird |
machines" in the sense of modern binary exploitation, are a kind of miracle. |
If we reflect back on Turing's vision of a machine that processes an |
infinite tape using a set of fixed instructions, there's a hard distinction |
between the concept of "data" and "instructions" - the data being the tape, |
and the instructions (or "code") being integral to the machine. |
However, it wasn't long before Turing proposed the idea of the "universal |
Turing machine" which could effectively be "programmed" by the tape - in |
effect incorporating new instructions from the data that were a part of the |
machine's input. With this stroke, the lines between code and data were |
blurred - and we're still paying for it all these years later. There were |
attempts to make the situation more rigorous, and we ended up with the |
notions of "von Neumann" and "Harvard" architectures; the former being what |
most of us are used to in our day-to-day lives where code and data all live |
in the same memory, as opposed to the latter where code and data are |
fundamentally different and don't as easily intermingle. |
If you are writing a binary exploit for *almost* any target today then |
you're most likely, either directly or indirectly, dealing with *pointers*. |
This may seem like a rather obvious thing to point out (pun intended), but |
its crucial to the motivation for CHERI. If we're not leaking pointers to |
bypass ASLR, we might be overflowing an index that will be added to one to |
achieve an out-of-bounds read/write, or maybe we're even bringing our own |
pointers to the table as part of the exploit. What if we could re-design |
the architecture that our ISAs are built upon to firm up the notion of a |
pointer into something more concrete, or (dare we say) *safer*? Can we do |
pointers, but better? The major upside of moving protections from the |
language and into the ISA is that we can continue to use our existing C/C++ |
codebases without having to rewrite 40+ years of software in a memory-safe |
language. |
One thing that might come to mind is that we could demand that a pointer |
only being valid within a certain bound. Imagine if, encoded into the |
pointer itself, was a range for which that pointer could be used. If we |
could do that, could we also tack on some permissions bits? "This pointer |
can be used to read/write data from 0x80000000 to 0x80001000, but not to |
fetch instructions". Fundamentally, this is what the CHERI project refers |
to as a "capability" and is responsible for the "C" in the acronym. All the |
security guarantees espoused by the project centre around capabilities and |
how their use is enforced and abuse is prevented. |
The idea of the capability is actually a fairly old one in the history of |
computing. As far back as 1978, IBM had the System/38 minicomputer which |
supported a kind of capability addressing termed "authorized pointers". |
These pointers could only be created by privileged instructions and encoded |
their permissions into themselves. Unfortunately, there wasn't a way to |
modify these objects once they were created which led to some unfortunate |
issues where permissions couldn't be revoked once given. The System/38 was |
retired in 1988. |
Despite this, and a few other attempts over the years, capabilities |
haven't really taken off. The difference with CHERI is that instead of |
creating a bespoke new architecture, the team at Cambridge is attempting to |
"enhance" existing ISAs with capability addressing. |
At this point, you may well be thinking that turning pointers into pointer/ |
metadata hybrids isn't that much of a big deal if you can still "bring your |
own pointers" to an exploit. Surely you could just overwrite some |
capability in memory with a capability of your own that says "This pointer |
can be used to read/write/fetch to and from anywhere"? In order for this |
idea to have any legs, we need to also prevent capabilities from being |
forged. To explain this further, lets solidify our notion of capabilities a |
bit so that we know what it is that we're trying to prevent from being |
forged or manipulated. |
Let's assume we have a 64-bit system, say Aarch64. All our registers (where |
pointers must go to be dereferenced) are 64-bits wide, so we'll need to |
widen them a bit to support the extra metadata that we want to cram in. |
CHERI does this by simply doubling the register width so now our registers |
are 128-bits instead. Note that the ALU is untouched, so you don't get |
128-bit integers and can't do 128-bit logical or arithmetical operations |
natively with this change. We can make our lives a little easier by also |
demanding that every capability is 128-bit aligned in memory. This is |
important because it means that *every contiguous 128-bit region of memory |
could be a capability*. Then again, it might not be so we need to devise a |
way to keep track of which of these regions are capabilities and which |
aren't. |
The simplest (for some definition of "simple") solution is to offload this |
responsibility to the memory controller. We make the demand that the memory |
controller maintain a state which governs where all the valid capabilities |
currently are in memory. When the CPU reads from memory into a register, it |
will also be told whether that read was a capability or not. If an attempt |
is made to dereference a value stored in a register, and this "tag" bit |
isn't set, then the CPU will trigger an exception. Also - and this is very |
important - whenever a write to memory is performed, the memory controller |
*must* clear the associated tag bit for that region, unless the CPU |
explicitly asks the memory controller to set the tag bit again afterwards, |
for instance when a legitimate capability is created. |
This means that any attempt to modify a capability in memory will clear the |
tag bit so that a CPU exception will trigger if the program tries to later |
dereference that capability. |
Woah, woah, woah slow down. There's a lot to unpack here and several |
questions should hopefully be raised in your head. First of all, how on |
Earth is the CPU supposed to tell the memory controller what is a |
legitimate capability modification? There are plenty of programs that will |
perform pointer arithmetic, and wasn't the whole point of this thought |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.