Morpheus Turns a CPU into a Rubik’s Cube to Defeat Hackers
&gt;&quot;IEEE Spectrum: So you can detect an attack just by looking at what’s being looked at?<p>Todd Austin: Yeah. Let me give you a classic example—the return stack. [When a program “calls” a subroutine into action, it stores the address the program should return to when the subroutine is over in the return stack.] This is a real popular place for attackers to manipulate to do what’s called a buffer overflow or a code injection. There’s only one part of the program that writes and reads from the return address, and that’s the beginning of a function and the end of a function. That’s really the semantics of the return address. But when you see a program attacking the return address to do code injection, for example, you’ll see writes from many different places in the program. So, these sort of unexpected, undefined accesses, normal programs never do. That’s a tell-tale sign that there is an attack going on. Now, some systems might try to detect that. And when they detect that, then they can kill the program.&quot;<p>PDS: Observation: An x86 emulator, such as Bochs, could be programmed such that it &quot;knew&quot; about where any given program&#x2F;processes&#x27; stack is -- and explicitly looked for&#x2F;flagged&#x2F;logged&#x2F;warned&#x2F;alerted and possibly stopped (and dumped for further analysis) -- programs&#x2F;processes whose stacks were accessed&#x2F;changed in questionable ways...<p>Also, this leads to my next thought...<p><i>Why couldn&#x27;t all processes&#x27; stacks -- have some form of hardware&#x2F;CPU protection?</i><p>I mean, we have Ring 0 for OS code, and Ring 3 for user program code -- this leaves Rings 1 and 2 free for other purposes... well, why not put program&#x2F;process stacks there,  and guard access to them via the OS?<p>(Now, a better idea would be a custom CPU designed to know about and explicitly protect each process&#x27;s stack memory -- but short of that, x86 has those extra rings...)<p>Yes, it would make programs slower.<p>Possibly much slower, depending on what&#x27;s being done.  And of course, the program wouldn&#x27;t have immediate access to its stack variables, without OS intervention...<p>Maybe part of the solution would be in what Forth did a long time ago -- separate the call&#x2F;return (control) stack from the local variables stack...<p>Like, maybe if the call&#x2F;return stack -- is placed in a Ring that the OS controls (requiring an OS syscall -- which could also log&#x2F;alert in the case of an anomaly), but the data (local variable) stack is still kept in a common area...<p>Yes, compilers would have to be modified to support that scheme, and yes, it would be slower... but could it work?<p>I don&#x27;t think it would prevent all kinds of attacks (I don&#x27;t think anything could) -- but it might help mitigate some of the more common stack-based attacks...<p>Also, the idea of encrypted pointers -- both on the stack and not -- is a good idea.<p>It would be slow if not implemented in hardware, unless the encryption was a simple XOR with some known-only-at-runtime value (which would be a bit slower than without it) -- but that would be the fastest thing that could implement an approximation of that scheme in software...<p>Anyway, a lot of interesting ideas in this paper...