can the spectre security vulnerability be in a virtual machine?

13

3

Is it possible that a virtual machine like VirtualBox has the security vulnerability "spectre"? I think the VM maybe does out-of-order execution, but in my opinion it is not possible to peek at the cache to read the result.

Is there any explanation how it is possible to read the cache of a virtual cpu?

user521153

Posted 2018-03-03T10:39:00.497

Reputation:

4Yes, A little research would have confirmed VMWare has released patches to address Spectre and Meltdown. The guest OS must be patched, in addition, to the actual hypervisor (both types) – Ramhound – 2018-03-03T13:41:20.073

Depends on the level of virtualisation, I'd say. If you are simulating a virtual CPU, then you're probably safe. But that's not what modern VMs do. – Bergi – 2018-03-03T17:08:53.353

Is there any explanation how it is possible to read the cache of a virtual cpu? – None – 2018-03-03T17:15:35.293

1@jms details are in the canonical post I linked in my answer: Spectre works on a different level ... In this attack, the attacker tricks the speculative execution to predictively execute instructions erroneously. In a nutshell, the predictor is coerced to predict a specific branch result that results in asking for an out-of-bound memory access that the victim process would not normally have requested resulting in incorrect speculative execution. Then by the side-channel, retrieves the value of this memory. In this way memory belonging to the victim process is leaked to the malicious process. – Mokubai – 2018-03-03T18:33:20.860

@jms When it is running, a virtual CPU has the same cache as the physical CPU it is running on. – David Schwartz – 2018-03-03T19:31:46.077

@DavidSchwartz really? this is surprising. I was assuming that a VM is more abstracted from the real hardware. – None – 2018-03-04T10:03:44.750

1@jms Virtualization is only fast because it uses the physical CPU with as little abstraction as possible and relies on CPU hardware to provide isolation and abstraction. Things like qemu can do emulation which would be safer as it is not a hardware CPU, but it is much slower and is different from virtualization. – Mokubai – 2018-03-04T16:43:49.343

@jms added a bunch of info to my answer. – Mokubai – 2018-03-05T08:10:04.157

Answers

14

Yes Spectre can cross host/guest, guest/host and guest/guest boundaries because this is a CPU level flaw that means that potentially sensitive information can be leaked across anything that runs on a CPU core.

Most of the news stories on the internet speak about the cloud providers being worst hit by this as they have massive clusters of systems that are virtualised and could potentially be abused to leak sensitive information.

Most of the large providers should have been patched against the flaws by now, as best they can be, but this is going to be a problem that lives with us for some time.

Security.SE has a canonical Q & A regarding this and it mentions VM's:

I am running a Virtual Machine/Containers, to what extent am I vulnerable?

As per Steffen Ullrich's answer

  • Meltdown attacks do not cross VMs, only leaks kernel memory to local processes.
  • Spectre can work across VMs.

Also, from Steffen again, Meltdown and Spectre works with containers, as containers relies on the host kernel.

VMs use the actual CPU in your system with some privileged instructions trapped and able to be redirected. It uses the same caches and instructions as the host does. It is essentially just another layer within the physical CPU in your system.

Virtualization is only fast because it uses the physical CPU with as little abstraction as possible and relies on CPU hardware to provide isolation. Things like qemu can do emulation which would be safer as it is not a hardware CPU, but it is much slower and is different from virtualization.

From the Security.se canonical post again:

Spectre works on a different level and does not allow access to kernel-space data from user-space. In this attack, the attacker tricks the speculative execution to predictively execute instructions erroneously. In a nutshell, the predictor is coerced to predict a specific branch result (if -> true), that results in asking for an out-of-bound memory access that the victim process would not normally have requested, resulting in incorrect speculative execution. Then by the side-channel, retrieves the value of this memory. In this way, memory belonging to the victim process is leaked to the malicious process.

So, because the VM runs in actual CPU hardware and all it needs to do is run a particular loop to "train" the speculative execution engine. Then it can use precise timing to watch the caches for particular patterns of access indicative of the host or guest (or other VM) process that it is looking to exploit.

In this way it means that a machine is exploitable in every direction. From host to VM, from VM to host, and from VM to VM.

Yes, it is by no means easy and is a difficult thing to pull off as the VM CPU core could change at whim of the host and the host could happily schedule tasks on different cores as well, but over a long period of time enough information could be leaked to give up a secret key to some important system or account. Given enough time and some suitably stealthy software everything is potentially open.

If you wanted a "secure" VM then you have to guarantee that it's cores are isolated. The only real ways to block this attack would be to "force" the host and VMs to only use certain cores so that they are never running on the same hardware but this would lead to an effective increase in cost as you would not be able to have as many VMs on a given host. You would never be able to get away with running more VMs than you have cores available, which is something I would expect to be done on "low load" servers as many systems sit idle for 90% of their life.

Mokubai

Posted 2018-03-03T10:39:00.497

Reputation: 64 434

2I think you interpreted the question as "if the host CPU is affected, will the VM be affected, too?" As I understand the question, it asks "if the host CPU is not affected, can the VM still be affected?" Could you clear that up? – AndreKR – 2018-03-03T22:04:49.913

1@AndreKR: currently all out-of-order execution CPUs are affected by Spectre; only with software workarounds can you make a system sort of safe (and thus the VM would have to care about this, although a hypervisor can isolate the guests from each other if the CPU provides the facilities, e.g. Intel's IBRS stuff). But on an in-order CPU with no speculative execution, no Spectre vulnerabilities of any sort can exist between any two pieces of software. The essence of Spectre is provoking speculative execution of something that puts secret data into microarchitectural state; in-order CPUs don't. – Peter Cordes – 2018-03-03T23:31:37.903

The most interesting thing is not the speculative execution. The most interesting thing is how a process can find out what is in the cache - even in an VM. – None – 2018-03-07T21:11:01.517

@jms the side channel attacks available are facilitated and made useful by the speculative execution. The process may not be able to directly read cache lines, but the speculative execution can leak information by doing calculations that put values into the cache that can be detected or inferred by timing attacks. Section 4 of the spectre white paper has a good explanation: https://spectreattack.com/spectre.pdf

– Mokubai – 2018-03-07T21:24:18.740

0

gem5

If you are interested in studying / reproducing vulnerabilities purely with emulation, without using the host CPU, I don't think QEMU is detailed enough to observe them as it does not simulate the CPU pipeline.

gem5 however, is used to estimate system performance in research and development, and does simulate enough CPU internals for you to observe Spectre in a fully clean and controlled environment.

A cool x86_64 demo with visualization has been published at: http://www.lowepower.com/jason/visualizing-spectre-with-gem5.html

The downside of gem5 is that it is much slower than QEMU the simulation is more detailed.

Ciro Santilli 新疆改造中心法轮功六四事件

Posted 2018-03-03T10:39:00.497

Reputation: 5 621