Spectre and Meltdown
Spectre and Meltdown
Spectre and Meltdown
● Meltdown
○ Intel, ARM, IBM …
○ Desktop, Laptop, and Cloud computers
● Spectre
○ Intel, AMD, ARM, IBM …
○ Desktops, Laptops, Cloud Servers, as well as Smartphones
● Affects all operating systems
○ Linux, Windows, MacOS ...
What do they affect? (cont.)
● Meltdown:
○ Breaks the most fundamental isolation between user applications and the operating
system.
○ Allows a program to access the memory, and thus also the secrets, of other programs and
the operating system.
● Spectre:
○ Breaks the isolation between different applications.
○ Allows an attacker to trick error-free programs, which follow best practices, into leaking
their secrets.
What do they exploit?
● Exploit the three major designs in modern processors:
○ Out-of-order Execution
○ Speculative Execution
○ Caching
● Both attacks use side channels to obtain the information from the
accessed memory location.
What is Out-of-order Execution?
● It is an approach to processing that allows instructions for
high-performance microprocessors to begin execution as soon as their
operands are ready.
● Although instructions are issued in-order, they can proceed out-of- order
with respect to each other.
● The goal of OoO processing is to allow the processor to avoid a class of
stalls that occur when the data needed to perform an operation are
unavailable.
Out-of-order Execution steps
1. Instruction fetch.
2. Instruction dispatch to an instruction queue (also called instruction buffer or reservation
stations).
3. The instruction waits in the queue until its input operands are available. The instruction is then
allowed to leave the queue before earlier, older instructions.
4. The instruction is issued to the appropriate functional unit and executed by that unit.
5. The results are queued.
6. Only after all older instructions have their results written back to the register file, then this
result is written back to the register file. This is called the graduation or retire stage.
Life example of Out-of-order Execution: make tea
Life example of Out-of-order Execution: make tea
● wash tea cups -> boiling water -> make tea
● wash tea cups ---------------------------------------->-------|
|-->wait for use------>-----|---->make tea
boiling water -> boiled->|
● wash tea cups -------------------------------------->break cups-->--|
|-->wait for use-->----------------------|-->water not use
boiling water -> boiled->|
● Because the cups are broken when washing them (raise error), the boiled
water won’t be used in next steps.
● However, don’t use the boiled water doesn’t mean the boiled water will
disappear, it is still placed in the waitting area (caching).
What is Speculative Execution?
● It is a technique used by modern CPUs to speed up performance.
The CPU may execute certain tasks ahead of time, "speculating" that they
will be needed and complete them.
● If the tasks are required, a speed-up is achieved, because the work is
already complete.
● If the tasks are not required, changes made by the tasks are reverted and
the results are ignored.
Life example of Speculative Execution: order coffee
Life example of Speculative Execution: order coffee
● Barista: make Latte || speculate:need Latte ->make Latte->available Latte---|
Customer: need Latte || need Latte -|-> Got it !
Days: day 1 || day 2
● Barista: make Latte || speculate Latte || speculate Latte - make it -|-> make French Vanilla
Customer: need Latte || need Latte || need French Vanilla---------| & throw away Latte
Days: day 1 || day 2 || day 3
Caching
● The CPU requests data from memory which is stored in a cache
● Speeds up memory access
● Temporal locality: something which was accessed recently from memory
might be accessed again soon
○ Ex. a counter in a loop
● Spatial locality: something which is close to another thing which was
accessed recently might be accessed soon
○ Ex. elements in an array
What is side-channel attack?
● Attack which is enabled by the micro architectural design of the CPU and
based on information gained from the implementation of a computer
system.
○ Caches: attack which monitors how quickly data accesses take and
infer whether or not said data was in the cache
○ Timing: attack which monitors time it takes for machine to do various
computations
○ Power-monitoring: attack which monitors power consumption of
hardware on varius computations
○ …...
Cache side-channel attack
The side channel comes from monitoring how quickly data can be accessed
from the cache.
● When the x satisfy the loop condition and we execute this loop for
multiple times, the branch predictor will think the next loop also satisfies
the loop condition and execute this loop.
Spectre attack Variant 1
● If at this time we assigned the value A to the x, the branch predictor will
predict the loop for execution (actually should not execute), the CPU will
execute the loop body, and then load the password secret value in cache,
and use it as the address to access array2.
● But eventually, the CPU will found this loop should not be executed, so
the value got in this loop will become invalid.
Spectre attack Variant 1
● Finally, we can read array2, and if we read an address for a short amount
of time, that address is the one that is cached (our password value).
Spectre attack Variant 2
● Poisoning Indirect Branches
● Indirect Branch: jumping to code at some memory location
○ e.g. jmp [eax] => jump to instruction stored at memory address in
register EAX
● Variant 2 is much like variant 1, but instead of abusing the data lookup
portion of the CPU, it abuses the ability for a CPU to predict which way it
will go when a function pointer is called.
● The attacker needs to locate a “Spectre gadget”, i.e., a code fragment
whose speculative execution will transfer the victim’s sensitive
information into a covert channel.
Spectre attack Variant 2
● Attacker chooses a “Spectre gadget” from the victim’s address space and
trains the Branch Target Buffer (BTB) to mispredict a branch from an
indirect branch instruction to the address of the gadget, resulting in
speculative execution of the gadget.
○ Not reliant on the vulnerability of victims code.
○ Attacker has to find the virtual address of gadget
● Exploiting Branch Target Buffer (BTB)
Branch Target Buffer (BTB)
● The Branch Target Buffer (BTB) keeps a mapping from addresses of
recently executed branch instructions to destination addresses .
● Processors can use the BTB to predict future code addresses even before
decoding the branch instructions.
○ Using Speculative Execution to improve the performance
● Only the 31 least significant bits of the branch address are used to index
the BTB.
Branch Target Buffer (BTB)
● Allows the CPU to speculatively execute code at predicted indirect branch
target without actually having decoded the branch instructions
● Not all computer users will have the money, time or skills to change the
computer CPU.
● So, update your Operating System and Softwares to the newest version!
● Google also have posted a patch called Retpoline for mitigating Spectre
Variant 2
We can see there are still some Variants of Spectre are not solved.
Reference
https://meltdownattack.com/
https://meltdownattack.com/meltdown.pdf
https://spectreattack.com/spectre.pdf
https://searchdatacenter.techtarget.com/definition/out-of-order-execution
https://www.computerhope.com/jargon/s/spec-exec.htm
https://www.blackhat.com/docs/asia-17/materials/asia-17-Irazoqui-Cache-Side-Channel-Attack-Exploitability-And-Countermeasures.pdf
https://www.mikelangelo-project.eu/2016/09/cache-based-side-channel-attacks/
https://conference.hitb.org/hitbsecconf2016ams/materials/D2T1%20-%20Anders%20Fogh%20-%20Cache%20Side%20Channel%20At
tacks.pdf
https://hackernoon.com/a-simplified-explanation-of-the-meltdown-cpu-vulnerability-ad316cd0f0de
http://www.cs.toronto.edu/~arnold/427/18s/427_18S/indepth/spectre_meltdown/index.html
http://www.cs.toronto.edu/~arnold/427/19s/427_19S/indepth/sm/Meltdown-and-Spectre.pdf
https://events19.linuxfoundation.org/wp-content/uploads/2017/11/Spectre-Meltdown-Linux-Greg-Kroah-Hartman-The-Linux-Foundation
.pdf
https://lwn.net/Articles/738975/