Skip to content

Commit 9bd9424

Browse files
committed
init commit
0 parents  commit 9bd9424

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+7496
-0
lines changed

.gitignore

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Object files
5+
*.o
6+
*.ko
7+
*.obj
8+
*.elf
9+
10+
# Linker output
11+
*.ilk
12+
*.map
13+
*.exp
14+
15+
# Precompiled Headers
16+
*.gch
17+
*.pch
18+
19+
# Libraries
20+
*.lib
21+
*.a
22+
*.la
23+
*.lo
24+
25+
# Shared objects (inc. Windows DLLs)
26+
*.dll
27+
*.so
28+
*.so.*
29+
*.dylib
30+
31+
# Executables
32+
*.exe
33+
*.out
34+
*.app
35+
*.i*86
36+
*.x86_64
37+
*.hex
38+
39+
# Debug files
40+
*.dSYM/
41+
*.su
42+
*.idb
43+
*.pdb
44+
45+
# Kernel Module Compile Results
46+
*.mod*
47+
*.cmd
48+
.tmp_versions/
49+
modules.order
50+
Module.symvers
51+
Mkfile.old
52+
dkms.conf
53+
54+
# output
55+
build/
56+
build*/
57+
bin/
58+
59+
# data
60+
*.png
61+
*.pdf
62+
*.jpg
63+
*.jpeg
64+
*.log
65+
*.tex
66+
*.csv
67+
*.tsv
68+
*.json
69+
*.pickle
70+
*.numpy
71+
*.host
72+
73+
# compilation db
74+
compile_commands.json

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "extern/PTEditor"]
2+
path = extern/PTEditor
3+
url = https://github.com/misc0110/PTEditor.git

CMakeExtern.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set(HAS_PTEDITOR FALSE)
2+
3+
function(check_pteditor HAS_PTEDITOR)
4+
if(EXISTS "${CMAKE_EXTERNAL_LIB_DIR}/PTEditor")
5+
message(STATUS "External library PTEditor detected")
6+
7+
set(${HAS_PTEDITOR} TRUE PARENT_SCOPE)
8+
add_definitions(-DPTEDITOR)
9+
10+
# link the header
11+
set(src_header "${CMAKE_EXTERNAL_LIB_DIR}/PTEditor/ptedit_header.h")
12+
set(sym_header "${CMAKE_CURRENT_SOURCE_DIR}/include/ptedit_header.h")
13+
if(NOT EXISTS ${sym_header})
14+
execute_process(COMMAND ln -s ${src_header} ${sym_header})
15+
endif()
16+
endif()
17+
endfunction()
18+
19+
function(check_external)
20+
check_pteditor(HAS_PTEDITOR)
21+
endfunction()
22+

CMakeHelper.cmake

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
function(detect_arch)
2+
execute_process(COMMAND bash -c "gcc -march=native -Q --help=target | grep march | \
3+
head -n 1 | tr -d '[:space:]' | cut -d'=' -f2"
4+
OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
5+
6+
message(STATUS "Native arch=${ARCH}")
7+
if(ARCH MATCHES "^haswell.*")
8+
message(STATUS "Haswell detected")
9+
add_definitions(-DHASWELL)
10+
set(UARCH_FOUND TRUE)
11+
endif()
12+
13+
if(ARCH MATCHES "^broadwell.*")
14+
message(STATUS "Broadwell detected")
15+
add_definitions(-DHASWELL)
16+
set(UARCH_FOUND TRUE)
17+
endif()
18+
19+
if(ARCH MATCHES "^skylake.*")
20+
message(STATUS "Skylake detected")
21+
add_definitions(-DSKYLAKE)
22+
set(UARCH_FOUND TRUE)
23+
endif()
24+
25+
if(ARCH MATCHES "^cascadelake.*")
26+
message(STATUS "Cascade Lake detected")
27+
add_definitions(-DCASCADE)
28+
set(UARCH_FOUND TRUE)
29+
endif()
30+
31+
if(ARCH MATCHES "^icelake.*")
32+
message(STATUS "Icelake detected")
33+
add_definitions(-DICELAKE)
34+
set(UARCH_FOUND TRUE)
35+
endif()
36+
37+
if(ARCH MATCHES "^alderlake.*")
38+
message(STATUS "Alderlake detected")
39+
add_definitions(-DALDERLAKE)
40+
set(UARCH_FOUND TRUE)
41+
endif()
42+
43+
if(NOT DEFINED UARCH_FOUND)
44+
message(FATAL_ERROR "Unsupported micro-architecture: ${ARCH}")
45+
endif()
46+
endfunction()
47+
48+
function(detect_pti)
49+
execute_process(COMMAND cat /sys/devices/system/cpu/vulnerabilities/meltdown
50+
OUTPUT_VARIABLE PTI OUTPUT_STRIP_TRAILING_WHITESPACE)
51+
message(STATUS "Meltdown mitigation: ${PTI}")
52+
if(PTI MATCHES ".*PTI")
53+
message(STATUS "KPTI detected")
54+
else()
55+
message(STATUS "KPTI not detected")
56+
add_definitions(-DNOPTI)
57+
endif()
58+
endfunction()

CMakeLists.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
3+
project(uarch-toolkit VERSION 2.0)
4+
5+
include("CMakeHelper.cmake")
6+
include("CMakeExtern.cmake")
7+
8+
if(NOT ${CMAKE_BUILD_TYPE} STREQUAL "Debug")
9+
message(FATAL_ERROR "Unsupportted build type ${CMAKE_BUILD_TYPE}, "
10+
"only \"Debug\" is allowed")
11+
endif()
12+
13+
if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
14+
message(FATAL_ERROR "Unsupported platform ${CMAKE_SYSTEM_NAME}, "
15+
"only \"Linux\" is supported")
16+
endif()
17+
18+
set(CMAKE_EXPORT_COMPILE_COMMANDS true) # always export compile db
19+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
20+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
21+
set(CMAKE_EXTERNAL_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/extern")
22+
23+
set(CMAKE_C_FLAGS "-std=gnu99 -g -Wall -O1 -Wno-unknown-pragmas -Wno-unused-function")
24+
add_definitions(-D_GNU_SOURCE) # make our life easier with Linux
25+
26+
detect_arch()
27+
check_external()
28+
29+
# finally, include and add things
30+
include_directories(include)
31+
32+
add_subdirectory(libs)
33+
add_subdirectory(src)
34+
add_subdirectory(tests)

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Last-Level Cache Side-Channel Attacks Are Feasible in the Modern Public Cloud
2+
3+
This repo contains implementations of the paper: **Last-Level Cache Side-Channel Attacks Are Feasible in the Modern Public Cloud**.
4+
In this paper, we demonstrated various techniques to perform an end-to-end, cross-tenant LLC Prime+Probe attack on Google Cloud Run.
5+
These techniques include:
6+
- Faster and noise-resilient eviction-set construction algorithms
7+
- A high-resolution primitive that monitors victim's memory accesses
8+
- Detecting the target cache set of interest in the frequency domain
9+
10+
You can clone the repo by running:
11+
```bash
12+
git clone --recursive https://github.com/zzrcxb/LLCFeasible.git
13+
```
14+
15+
## Dependences
16+
17+
### Common C Toolchain
18+
This repo requires `CMake`, `gcc`, and `GNU make` or `ninja-build`.
19+
Your system likely has them already.
20+
21+
### Hardware
22+
We tested our implementations mostly on Intel Skylake-SP and Ice Lake-SP microarchitectures.
23+
Therefore, we recommend trying our implementations on these two microarchitectures.
24+
Porting our implementation to other microarchitectures may require
25+
changing the source code.
26+
27+
### Kernel Module (Optional)
28+
Some programs depend on [PTEditor](https://github.com/misc0110/PTEditor),
29+
which is a kernel module that helps page-table manipulation in user space.
30+
Therefore, a kernel module build environment is required.
31+
Note that those programs only use PTEditor to output debug information,
32+
you don't need to install PTEditor for their core functionalities.
33+
34+
## Build
35+
### This Repo
36+
Under the project's root directory,
37+
execute:
38+
```bash
39+
mkdir build && cd build && cmake ..
40+
```
41+
After that, under the build directory, execute command:
42+
`make` or `ninja` depending on your build system.
43+
44+
Please refer to this [README](src/README.md) for more details
45+
on each program.
46+
47+
48+
### PTEditor (Optional)
49+
Under the `extern/PTEditor` directory, execute
50+
`make`
51+
to build the kernel module.
52+
Then load the module by executing:
53+
```bash
54+
sudo insmod module/pteditor.ko
55+
```

extern/PTEditor

Submodule PTEditor added at 9800a23

include/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# exclude some 3rd party headers from modules
2+
3+
ptedit_header.h

include/attribs.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#define UNUSED __attribute__((unused))
4+
5+
#ifdef __clang__
6+
#define OPTNONE __attribute__((optnone))
7+
#else
8+
#define OPTNONE __attribute__((optimize("O0")))
9+
#endif
10+
11+
#define ALWAYS_INLINE inline __attribute__((__always_inline__))
12+
13+
#ifdef __KERNEL__
14+
#define ALWAYS_INLINE_HEADER static ALWAYS_INLINE
15+
#else
16+
#define ALWAYS_INLINE_HEADER ALWAYS_INLINE
17+
#endif

include/bitwise.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#pragma once
2+
3+
#include "attribs.h"
4+
#include "num_types.h"
5+
6+
#define _SET_BIT(data, bit) ((data) | (1ull << (bit)))
7+
#define _CLEAR_BIT(data, bit) ((data) & ~(1ull << (bit)))
8+
#define _TOGGLE_BIT(data, bit) ((data) ^ (1ull << (bit)))
9+
#define _WRITE_BIT(data, bit, val) \
10+
(((data) & (~(1ull << (bit)))) | ((!!(val)) << (bit)))
11+
#define _TEST_BIT(data, bit) (!!((data) & (1ull << (bit))))
12+
#define _SEL_NOSPEC(MASK, T, F) \
13+
(((MASK) & (typeof((MASK)))(T)) | (~(MASK) & (typeof((MASK)))(F)))
14+
15+
#define _SHIFT_MASK(shift) ((1ull << shift) - 1)
16+
#define _ALIGNED(data, shift) (!((u64)(data) & _SHIFT_MASK(shift)))
17+
#define __ALIGN_UP(data, shift) ((((u64)(data) >> (shift)) + 1) << (shift))
18+
#define _ALIGN_UP(data, shift) \
19+
((typeof(data))(_ALIGNED(data, shift) ? (u64)(data) \
20+
: __ALIGN_UP(data, shift)))
21+
#define _ALIGN_DOWN(data, shift) \
22+
((typeof(data))((u64)(data) & (~_SHIFT_MASK(shift))))
23+
24+
/** |-end |- start
25+
* Set data 0000000000000000111111111110000
26+
Count from right to left, starting from 0, range EXCLUDES end
27+
i.e., [start, end). Then, it assigns data[start:end] = new_val[0:end-start]
28+
*/
29+
static __always_inline uint64_t _write_bit_range(uint64_t data, uint16_t end,
30+
uint16_t start,
31+
uint64_t new_val) {
32+
uint16_t width = end - start;
33+
uint64_t mask = (1ull << width) - 1;
34+
if (end <= start)
35+
return data; // invalid range
36+
37+
new_val = (new_val & mask) << start;
38+
mask = ~(mask << start);
39+
data = (data & mask) | new_val;
40+
41+
return data;
42+
}
43+
44+
static __always_inline uint64_t _read_bit_range(uint64_t data, uint16_t end,
45+
uint16_t start) {
46+
// end is excluded
47+
uint16_t width = end - start;
48+
uint64_t mask = (1ull << width) - 1;
49+
50+
if (end <= start)
51+
return 0;
52+
else
53+
return (data >> start) & mask;
54+
}

0 commit comments

Comments
 (0)