Meltdown - How modern CPUs leak sensitive data by side channel attacks
Last updated
Last updated
Modern hardwares usually implements lots of features to achieve better performance. However, such techniques can be used to leak sensitive data or even . Most of these attacking method is considered as side channel attacks, since they are using information outside of the information system.
The definition of side channel attack is as follows, referencing Wikipedia:
In , a side-channel attack is any attack based on extra information that can be gathered because of the fundamental way a or is , rather than flaws in the design of the protocol or algorithm itself (e.g. flaws found in a of a ) or minor, but potentially devastating, . (Cryptanalysis also includes searching for side-channel attacks.) Timing information, power consumption, leaks, and are examples of extra information which could be exploited to facilitate side-channel attacks.
From , we can see what a hardware side channel attack looks like, which I will be used as an example as follows.
Take a case that a password verification system used the code below.
Inside of the for loop, it compared each bytes to see if it is identical. So if we input 'a' instead of 'h', the loop will break on the first try. However, when we input 'h', which is the correct character, the loop will continue to compare the second byte. Tricking the system with an oscilloscope attached at the power source of CPU, we can see the difference between each input.
Hence, we can guess each character, and by observing the voltage changes we can get the password. This attacking method is completely outside of the programming system, as it has nothing related with the code and algorithms apart from the energy consumption of its physical implementation.
So the TLB is introduced, when the program needs to access one page of data seveal times, such as an array, it can shorten the time of each access. Let's say we need to read an array of data for 10 times. The first reading cost 300ns, after which the physical address of the page is stored in TLB cache, so the CPU don't needs to read another 2 times to locate the address where the data contains. That is what cache means - to increase the performance and reducing the repeating operations.
Out-of order execution is another technique to optimize the performance of CPU. In most cases, CPU run instructions in a parallel on different cores. Each core has its own caches and it will run the code instruction by instruction continuously by adding its own IP (Instruction Pointer), until is hits the conditional branching(jump) instruction, where the IP register will be set to a specific location. However, in practical system, the CPU would run as more instructions as it could, regardless of the previous instruction is finished.
This means, when a memory accessing instruction has been reached, the CPU would wait the memory returns and run instructions after it simultaneously. And when the memory returned value, the CPU would check the value to judge if the result of Out-of-order execution is correct or not.
During such process, the cache is also used. So the Meltdown attack used the properties of out-of-order execution and extract the data using cache attacks. However, when an exception is raised during the instruction, the CPU would not clear/flush the cache of the out-of-order execution produced. And to gain best performance, privileges of memory page will not be checked during the out-of-order execution. As a result, a potential vulnerability has been introduced.
Even if a memory location is only accessed during out-of-order execution, it remains cached. Iterating over the 256 pages of probe array shows one cache hit, exactly on the page that was accessed during the outof-order execution.
When a cache kicked in, all data will go through it. So if the program accessed the address, the address and value of it will be stored in cache. Then an attack could use such technique to extract the data from cache.
First thing the attacker would do is flush all cache, to make sure only target accessing be cached. Then, when target "touch" the memory region with certain operations, the region would be cached. Hence, the attacker could read every byte to learn which region the victim accessed by measuring the time of reading.
That is because reading from cache is significantly faster than reading from memory, as it shown in the paper of it.
As the background section discussed, we can use Flush+Reload technique with the out-of-order execution to make the attack possible. To use Flush+Reload, we need an array to receive the data sent by covert channel.
First is using clflush
instruction to flush the cache of array. Then making an exception so that the program will never reach the instructions below the exception, but the CPU executed it out of order. These out-of-order instructions need to load target address data and send it to the attacker by accessing the array which the attacker flushed.
Then, we measure the time of each byte inside the array, to extract the data from covert channel. The attack is successful. So an example of the attack is as follows.
For example, the Skylake platform is vulnerable. So we can just disable the protection by clicking the button below.
DISCLAIMER: THIS ARTICLE IS EDUCATIONAL PURPOSE ONLY! THE OPERATION IS DANGEROUS TO YOUR SYSTEM. DO NOT DISABLE THE PROTECTION UNLESS YOU KNOW WHAT ARE YOU DOING. YOU ARE DOING THIS AT YOUR OWN RISK.
We need a driver to put our data into the system address space. Anyway, any data from kernel space can be leaked with or without the driver.
On driver sides, a system thread will loop through the secret data infinitely to cache the data into the process unit, which I set to be Core 1.
To make it easier for us to extract the data, we need to set the thread to run at Core 1, which is the same with the Driver thread. Then using SEH to handle the access violation exception, to continue the program flow.
In the exploit function, we trigger the meltdown to leak secret data into our cache.
In the code above, we tried 99999 times until it hits 0. That is because the chance of hitting 0 is pretty high and need to be examined more often, according to the paper of meltdown. And the performance is vary from different processors. In some cases such as 6700k, the exploit can read non-cached data. But most cases it is difficult to contribute precise result without retrying.
I didn't make it happen because of the exception handler doesn't allow me to modify the rsp/ebp value and I don't have much time to do more research since I am currently in a dangerous situation in my study. However, I will try to implement that in the future.
To security researcher that are reading this article, if you are interested in this topic and want to do more research, please consider to add me as your collaborator. Thank you.
Meltdown, an attack using cache, published in 2018 with ID of , considered as catastrophic because it breaks the isolation between user and kernel address space and the permission of memory protection which the "" designed for.
As all hardware vendors caring about performance, the cache had been introduced on modern CPUs, such as TLB() in x86 architecture. For example, let's say accessing a 4-byte memory data need 100ns.
But when is enabled, the CPU needs to read at least 3 times to actually get the data it needed which can cost 300ns, because the CPU needs to translate the virtual address into physical, and the physical address of each page (A page is like a const-sized memory region) is located in another memory region.
Just as of Meltdown says.
Firstly, the attack has been patched long times ago, by both OS and CPU Microcode perspective, and (also known as KAISER) has been introduced to most systems, here is . So we needs to disable these security features first to achieve the attack. Here we need a freeware named InSpectre, and most importantly, we need a vulnerable processor.
For me, the result of testing shows my Laptop is vulnerable to Meltdown. However, according to Intel , my processor is not vulnerable to meltdown. So the demonstration is currently not avaliable.
The solution can be found at
During the process of writing this post, I found that this attack is available even if the processor is not affected by the meltdown . Then I did some research after finding that it can be exploited. Turns out that address around the stack can be cached and will not be flushed during out-of-order execution, so I guess maybe by migrating the stack or just changing rsp/rbp, it would leak information on any address.
Side-channel attack:
[原创]初探侧信道攻击:功耗分析爆破密码
CVE-2017-5754:
Protected Mode:
TLB - Transition Lookaside Buffer:
Memory Paging:
KPTI(previously KAISER):
GLEIXNER, T. x86/kpti: Kernel Page Table Isolation (was KAISER), Dec 2017.
Meltdown: Reading Kernel Memory from User Space
Spectre Attacks: Exploiting Speculative Execution
YAROM, Y., AND FALKNER, K. Flush+Reload: a High Reso- lution, Low Noise, L3 Cache Side-Channel Attack. In USENIX Security Symposium (2014)
Affected Processors: Guidance for Security Issues on Intel® Processors: