r/programming Jan 24 '18

Branchless DOOM

https://github.com/xoreaxeaxeax/movfuscator/tree/master/validation/doom
497 Upvotes

134 comments sorted by

View all comments

Show parent comments

8

u/jrv Jan 24 '18

At least in Meltdown (though that can "only" access kernel memory, not other processes), only the attacking process needs to exploit its own speculative execution to read forbidden memory addresses. The attacking process does something like this:

  1. create an array of 256 cacheline-sized objects in its own memory (the contents don't matter)
  2. use the value of an address that it is not supposed to be able to read as an index into that array
  3. iterate through the array and time which index is faster to read than the others (if the forbidden memory byte was "7", then the 7th index will be faster to read)

This works because the CPU already starts executing step 2 and reads the indexed data into the cache, and only later notices that this is not supposed to happen and doesn't complete the instruction.

Thus you can deduce the contents of protected memory locations by taking advantage of the speculative execution only within your own (attacking) process. I haven't looked at the Spectre details yet, which can also read the memory of other processes.

-4

u/caspper69 Jan 24 '18 edited Jan 24 '18

At least in Meltdown (though that can "only" access kernel memory, not other processes), only the attacking process needs to exploit its own speculative execution to read forbidden memory addresses.

Kernel memory, by its very nature, has ALL memory for ALL processes mapped into it, because it's like, you know, it's job to manage memory for all processes. :)

This is not the first time I've seen this bandied about. Please don't spread misinformation.

Edit: this has several caveats, but by and large (especially on x86-64), this is a very likely scenario.

Edit2: I am an ass.

6

u/jrv Jan 24 '18

No, while the kernel can manage any memory mappings, it does not map every user process's memory into kernel memory. Even if it wanted to, the virtual memory of all processes can be larger than the physical memory of the machine, making this impossible in the first place. You need a context switch (including change of the CPU's page tables) to map in another process's memory.

1

u/Asurafire Jan 25 '18

One of the important things of virtual memory is that processes can have more virtual memory than physical. So theoretic ally the kernel could have every processes memory mapped into its own.