January 06, 2018
Welcome to 2018! A Meltdown and Spectre Run-Through
Written by
Kevin Clark,
Scott Nusbaum and
Justin Elze
Penetration Testing
Security Testing & Analysis
Welcome to 2018! It’s only been a few days into the new year and we already have newly named bugs, thanks to the Google Project Zero, Cyberus Technology, and the Graz University of Technology.
Jann Horn, Werner Haas, Thomas Prescher, Daniel Gruss, Moritz Lipp, Stefan Mangard, Michael Schwarz, Paul Kocher, Daniel Genkin, Mike Hamburg, Moritz Lipp, and Yuval Yarom all contributed to the discovery and disclosure of the Meltdown and/or Spectre. These three teams have identified a flaw in processor design, allowing a low-privilege process to read memory, which could mean anything from breaking ASLR (Address Space Layout Randomization) to recovering passwords from memory. The attacks are made possible by "speculative execution", a technology that allows increased processor speed.
There have been some estimates that the latest patches for Meltdown specifically can have anywhere from a five to thirty percent reduction of performance. This estimate appears to be high as most are not reporting substantial impact to system performance. Google additionally has released different techniques that may mitigate the speed reduction even further.
The bugs have large implications for attackers, who are already positioned to run code on a compromised machine or within VM environments. Drive-by attacks are also possible, using JavaScript to launch the attack and then read protected memory. The primary concern is the ability to reach protected memory and potentially steal sensitive data such as passwords and other components of sensitivity on the system.
Let’s break down the two bugs as they are separate. First, let’s discuss Meltdown.
The Meltdown attack is used to read memory written to by the kernel and other user protected memory space. This would allow the attacker to potentially read passwords and other sensitive data. It has been shown to read up to 503 KB/s. In the case of a cloud or virtualized environment, this allows the attacker to read the data from the host system, as well as any other guest VM running on the host. Docker, LXC, and OpenVZ are also affected, since they utilize the host’s CPU.
CVE NumberCVE-2017-5754Affected Hardware
Figure 1 - Before Patching
Figure 2 - After Patching Next, lets discuss Spectre. The Spectre attack is a CPU vulnerability that allows a process to read data. CPU data can read from the current process, or the kernel using speculative execution and the cache to recover sensitive data from a process by leveraging the branch predictor to train it to know that the branch being used will be true. This allows the process to read private data that would otherwise not be readable.
CVE NumbersCVE-2017-5753, CVE-2017-5715Hardware Affected
Intel, AMD, and ARM.
Details and Breakdown
The first step is training the branch predictor to be true. Once the branch predictor is trained, it then invokes the branch with a false value after flushing the cache, then reads from it. If the difference in time from before and after the cache is read is less than the CACHE_HIT_THRESHOLD, then the value saved in the address is from the false speculative execution and it then stores the value.
Review of Code
The code included in the paper (see Appendix A) shows an example of reading a "secret" value from your process space with the following method.
This code has a "victim_function" that checks to make sure that the passed-in value (x) is less than the size of array1, and if it is, then stores the value of array1[x] * 512 into array2, which is 255*512 bytes long. It then trains the branch predictor by calling the function with several calls that train the branch predictor to allow the function to branch to True. The code then calls the function with an invalid offset, which points to the secret data and the training allows the value to be stored in the cache. It then loops over array2, timing the delay while reading the values, and if the delay is less than the max threshold set, it then increments the counter for the results.
Possibility of the Attack
This one specifically is an arbitrary read, so it can be used to read sensitive memory in the current process, a separate process, or be used as a kernel ASLR defeat.
To be able to read memory from another process, it seems you will need some way to have the target process execute a gadget with attacker controlled data.
Theoretical Examples
- Intel Microprocessors
- ARM and AMD (theoretical, not proven)
- JavaScript that tries to read passwords in the JIT process space
- Dumping the kernel memory of a host system when running in a VM as root
- Using eBPF filters to bypass kernel ASLR