The Spectre vulnerability affects Intel, AMD, and ARM processor chips (each to various degrees) and can allow unprivileged access to memory in the kernel and other processes. Canonical has committed to kernel patches to address this issue by January 9, 2018.
If you need to check your system, or perhaps have already patched your systems but want to verify that the issue truly is resolved, there is a simple proof of concept that exercises the bounds check bypass within the same process (Variant 1, CVE-2017-5753).
In this article I will show you how to compile and run this small, non-destructive C program that is included as Appendix A in the Spectre whitepaper.
I’ve tested this on Ubuntu 14.04 running gcc 4.8.4 as well as Ubuntu 16.04 running gcc 5.4.0.
Note that you should be extremely diligent when running any executable on your system, especially one that exercises a known vulnerability. If you see logic in the code that cannot be trusted, then do not compile it.
The first step is to download the simple C program that will exercise the vulnerability. You can look at it on github from your browser:
Or use wget as shown below to download.
Once downloaded, open the local spectre.c file to make sure it is exactly what you expect.
Source code fix
You need to make one modification before the source code will compile correctly. If you don’t change this, the gcc compiler will throw an error.
On line #50, insert a space after the word THRESHOLD and the left parentheses as shown below.
#define CACHE_HIT_THRESHOLD (80)
Assuming you have gcc installed, then you need to compile, which will create an executable named ‘spectre’ in the current directory.
$ apt-get install git make build-essential $ gcc spectre.c -o spectre -std=c99 -w -O0
This disables any non-fatal compiler warnings (-w), does not optimize the generated code (-O0), and uses the c99 standard which allows variable creation directly in the ‘for’ loop initialization which is not default on older gcc versions.
Run vulnerability check
This vulnerability is centered around out-of-bounds reads allowed by branch prediction and speculative execution. The secret as defined on line #37
char * secret = "The Magic Words are Squeamish Ossifrage.";
Is retrievable if you run the POC using the command:
You will get output similar to below, which shows the secret was retrievable using vulnerable speculative execution capabilities.
https://spectreattack.com/spectre.pdf (paper, with source code POC in Appendix)
https://www.exploit-db.com/raw/43427/ (POC code)