ZENHAMMER: Rowhammer Attacks on �AMD Zen-based Platforms
Patrick Jattke* Max Wipfli* Flavien Solt �Michele Marazzi Matej Bölcskei Kaveh Razavi
* Joint first authors
August 14–16, 2024�Philadelphia, PA, USA
Track 2 – Side Channel II:�Rowhammer
Executive Summary
2
Are current AMD Zen-based platforms vulnerable to Rowhammer?
63.9%
33.4%
We built ZENHAMMER to answer this!
AMD Zen introduced
No Rowhammer attacks on AMD Zen*
Background
DIMM Organization
DRAM addressing
3
DRAM Address
Physical address
CPU
Virtual address
Processor
Memory �Controller
Rowhammer
Application
Two bits flipped!
Double-sided pattern
Zen*
C1 Recovering DRAM address mappings
4
Function output of f(x) = 0x64440100 for same-cluster addresses.
Function output of f(x) after applying an offset of 768 MiB.
Recovery of correct function �g(x) = 0x44440100 with offset 768 MiB.
O1. DRAM functions are non-linear and require an address offset.
O2. Memory blocks >1 GiB need to be accessed for mapping recovery.
DRAMA [1] could not recover mappings.�⇨ Functions only worked on limited memory regions.
C0
C1
..
C#bk
1. Building timing clusters
2b Functions
00..0011
00..0101
…
10..0001
…
11..0000
C0
f( ) = f(a0…aN) = 0
f( ) = 1
…
f( ) = 0
C1
C#bk
Expected:
50%: 0
50%: 1
2. Brute-forcing DRAM functions
[1] P. Pessl, D. Gruss, C. Maurice, M. Schwarz, and S. Mangard, “DRAMA: Exploiting DRAM Addressing for Cross-CPU Attacks,” in USENIX Security ’16.
a0
a1
…
aN
DRAM3
DRAM2
PCI
DRAM1
DRAM1
DRAM2
DRAM3
CPU�(phy. address space)
AMD
0 GiB
4 GiB
TOM
C1 Recovering DRAM address mappings
Visualization of <1 RK, 4 BG, 4 BK, 216 rows> functions.
5
See our paper for more �DRAM configurations!
Physical Address Bit | | | 32 | | | | 28 | | | | 24 | | | | 20 | | | | 16 | | | | 12 | | | | 8 | | | | 4 | | | | 0 |
AMD Zen 3 | |||||||||||||||||||||||||||||||||||
BG 0x0022220100 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
BG 0x0044440200 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
BA 0x0088880400 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
BA 0x0111100800 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
ROW 0x01fffe0000 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
AMD Zen+/Zen 2 | |||||||||||||||||||||||||||||||||||
BG 0x0088883fc0 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
BG 0x0111104000 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
BA 0x0022228000 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
BA 0x0044450000 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
ROW 0x01fffe0000 | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Testing for Rowhammer
6
DIMM | | Zen 2 | | Zen 3 | | Coffee Lake | |||
| #Patt. | #Bit Flips | | #Patt. | #Bit Flips | | #Patt. | #Bit Flips | |
S0 | | 14 | 19 | | 0 | 0 | | 122 | 3’502 |
S1 | | 4 | 4 | | 0 | 0 | | 102 | 1’374 |
S2 | | 14 | 28 | | 0 | 0 | | 782 | 22’339 |
S3 | | 0 | 0 | | 0 | 0 | | 3 | 3 |
S4 | | 4 | 5 | | 0 | 0 | | 47 | 654 |
S5 | | 6 | 7 | | 0 | 0 | | 155 | 4’131 |
H0 | | 0 | 0 | | 0 | 0 | | 24 | 35 |
M0 | | 0 | 0 | | 0 | 0 | | 16 | 23 |
5/10 devices
0/10 devices
8/10 devices
⇨ Porting the DRAM address functions is insufficient to do Rowhammer on AMD Zen-based systems.
[2] P. Jattke, V. van der Veen, P. Frigo, S. Gunter, and K. Razavi, “BLACKSMITH: Scalable Rowhammering in the Frequency Domain,” in IEEE S&P ’22.
6x
2x
2x
In-DRAM TRR: REF synchronization
7
…
Rowhammer pattern of length 4 tREFI
time
REF
REF
TRR
REF
REF
REF
TRR
REF
REF
REF
TRR
Non-synchronized
…
…
Memory access
Synchronized
SMASH [3],�Blacksmith [4]
…
…
…
REF synchronization
Requirement for doing Rowhammer:
⇨ proper synchronization with REFs ( C2 )
[3] F. de Ridder, P. Frigo, E. Vannacci, H. Bos, C. Giuffrida, and K. Razavi, “SMASH: Synchronized Many-sided Rowhammer Attacks From JavaScript,” in USENIX Security ’21
[4] P. Jattke, V. van der Veen, P. Frigo, S. Gunter, and K. Razavi, “BLACKSMITH: Scalable Rowhammering in the Frequency Domain,” in IEEE S&P ’22.
C2 Adapting timing-based� REF synchronization
8
Zen 3
Zen 3
Zen+
Correct detection
No clear signal
t0
t1
A1
A2
F1
F2
REF
…
REF detected
REF
…
REF detected
REF
REF undetected
…
…
REF
t1
t1
t2
t0
REF
REF
…
REF sync.
= Mem. access
= Flush
⇨ Synchronization does not work on Zen 3.
t0
t1
t2
C2 Adapting timing-based REF synchronization
9
tREFI (7.8μs)
7.81
7.77
#Rows used for synchronization
Original
Improved
7.62
5.37
In-DRAM TRR: activation count
10
time
REF
REF
TRR
REF
REF
REF
TRR
REF
REF
REF
…
Synchronized hammering
…
…
…
Requirements for doing Rowhammer:
⇨ sufficient activation count to the aggressors ( C3 )
Decoy rows
To bypass mitigations
REF
TRR
refresh window (64 ms)
≜ 8192 refresh intervals
C3 Increasing the ACT rate and preserving order
11
Access �Type | Flushing�Strategy | Fence�Type | #Rows | ||||||
1 | 2 | 4 | 8 | 16 | 32 | 256 | |||
MOV (load) | gather | mfence | 24 | 49 | 71 | 91 | 100 | 110 | 114 |
MOV (load) | gather | lfence | 24 | 49 | 80 | 113 | 134 | 147 | 121 |
MOV (load) | gather | sfence | 24 | 49 | 80 | 113 | 133 | 146 | 125 |
MOV (load) | gather | – | 24 | 49 | 80 | 113 | 133 | 146 | 125 |
MOV (load) | scatter | mfence | 24 | 49 | 79 | 107 | 126 | 143 | 157 |
MOV (load) | scatter | lfence | 24 | 49 | 95 | 137 | 149 | 153 | 159 |
MOV (load) | scatter | sfence | 24 | 48 | 97 | 154 | 159 | 159 | 159 |
MOV (load) | scatter | – | 24 | 49 | 97 | 154 | 159 | 159 | 159 |
PREFETCHNTA | scatter | – | 80 | 132 | 191 | 208 | 243 | 309 | 273 |
PREFETCHNTA | scatter | mfence | 24 | 49 | 80 | 108 | 141 | 170 | 284 |
BEST
Cache
hits
Zen 3
Max.�ACTs
40 ACTs/tREFI gives 36K ACTs with 18 aggs.
⇨ too low for many devices
Z+
Z3
CL
Gathered flushes
Scattered flushes
A1
A2
A3
A4
A5
A6
…
F1
F2
F3
F4
F5
F6
A1
A2
A3
A4
A5
A6
…
F1
F2
F3
F4
F5
F6
Evaluation: Best Rowhammer pattern
12
DIMM | | Zen 2 | | Zen 3 | | Coffee Lake | |||
| #Patt. | #Bit Flips | | #Patt. | #Bit Flips | | #Patt. | #Bit Flips | |
S0 | | 51 | 6’945 | | 31 | 17’775 | | 122 | 6’782 |
S1 | | 26 | 1’758 | | 25 | 15’613 | | 102 | 10’106 |
S2 | | 97 | 12’893 | | 45 | 79’306 | | 782 | 1’708 |
S3 | | 8 | 2’020 | | 1 | 667 | | 3 | 0 |
S4 | | 60 | 1’183 | | 43 | 13 | | 47 | 18’357 |
S5 | | 25 | 1’911 | | 26 | 10’741 | | 155 | 5’860 |
H0 | | 6 | 182 | | 0 | 0 | | 0 | 0 |
H1 | | 0 | 0 | | 0 | 0 | | 24 | 0 |
M0 | | 0 | 0 | | 0 | 0 | | 0 | 0 |
M1 | | 0 | 0 | | 0 | 0 | | 16 | 2 |
7/10 devices
6/10 devices
8/10 devices
5/10 devices
0/10 devices
Demo: PTE Attack on AMD Zen 3
13
Evaluation: ZENHAMMER on DDR5
14
Microarch. | Release Date | CPU |
Zen 4 | September 2022 | Ryzen 7 7700X |
Zen 3 | November 2020 | Ryzen 5 5600G |
Zen 2 | July 2019 | Ryzen 5 3600X |
Zen+ | April 2018 | Ryzen 5 2600X |
Reviewer A: Do you have any early results/thoughts on Zen4 applicability?
Reviewer C: However, the newest microarchitecture that is evaluated is Zen 3 from 2020. Since then, there have been […] Zen 4 (2022) […]
Check out our paper�for more information!
pjattke@ethz.ch
pjattke
linkedin.com/in/pjattke
Conclusion
Current AMD Zen-based systems are equally vulnerable to Rowhammer as Intel systems.
DRAM addr. mappings
for Zen 2/3/4 incl. offsets.
Up to 46x more bit flips
on Zen 3 compared to Coffee Lake.
Exploitation
in the best case (PTE) in just 6s (Zen 2) and 2s (Zen 3).
End-to-end�PTE exploit on Zen 3.
ZenHammer bit flips
Zen 2: 7/10 DIMMs
Zen 3: 6/10 DIMMs
Zen 4: 1/10 DIMMs
First ever reported DDR5 bit flips!
DDR4
DDR5
Patrick Jattke
Are current AMD Zen-based platforms vulnerable to Rowhammer attacks?
Our test systems
16
Microarchitecture | Release Date | CPU |
Zen 3 | November 2020 | Ryzen 5 5600G |
Zen 2 | July 2019 | Ryzen 5 3600X |
Zen+ | April 2018 | Ryzen 5 2600X |
Executive Summary
17
Are current AMD Zen* platforms vulnerable to Rowhammer?
63.9%
33.4%
Intel
AMD
19x
1x
(C1) DRAM addr. mapping
(C2) Timing-based REF synchronization
(C3) ACT rate and memory access order
DRAM �Address
Phy.�Address
…
…
vs.
ACTs/tREFI
a
b
b
a
a
b
a
b
C3 Increasing the ACT rate and preserving order
We designed and evaluated six fence scheduling policies during 6h fuzzing runs on all devices/platforms.
18
SPNONE
SPBP
SPBP/2
SPPAIR
SPREP
SPFULL
A1
A2
A1
A2
A3
A4
A3
A4
A3
A4
A1
A2
A1
A2
A5
A6
A5
A6
A5
A6
A1
A2
A1
A2
A3
A4
A4
A4
A3
A3
…
A1
A2
A1
A2
A3
A4
A3
A4
A3
A4
A1
A2
A1
A2
A5
A6
A5
A6
A5
A6
A1
A2
A1
A2
A3
A4
A4
A4
A3
A3
…
A1
A2
A1
A2
A3
A4
A3
A4
A3
A4
A1
A2
A1
A2
A5
A6
A5
A6
A5
A6
A1
A2
A1
A2
A3
A4
A4
A4
A3
A3
…
A1
A2
A1
A2
A3
A4
A3
A4
A3
A4
A1
A2
A1
A2
A5
A6
A5
A6
A5
A6
A1
A2
A1
A2
A3
A4
A4
A4
A3
A3
…
A1
A2
A1
A2
A3
A4
A3
A4
A3
A4
A1
A2
A1
A2
A5
A6
A5
A6
A5
A6
A1
A2
A1
A2
A3
A4
A4
A4
A3
A3
…
A1
A2
A1
A2
A3
A4
A3
A4
A3
A4
A1
A2
A1
A2
A5
A6
A5
A6
A5
A6
A1
A2
A1
A2
A3
A4
A4
A4
A3
A3
…
Base �period
Memory barrier (fence)
Double-sided�aggressor pair
Evaluation: Best Rowhammer pattern
19
3
256 MiB
. . .
Large sweep of the best pattern ⇨ # Bit flips
2
4 MiB
..
Quick sweep of each �effective pattern ⇨ best pattern
Effective patterns
Best pattern
1
Short fuzzing with each fence �scheduling policy ⇨ SPOPT
SPOPT
SP
SP
SP
SPPAIR
x
ZENHAMMER
x
C3 Increasing the ACT rate and preserving order
20
Zen+
Z3
CL
R1
R2
Recommendations
R3
O4. Memory loads following a CLFLUSH(OPT) never incur cache hits on Zen 3 but on Zen+/2.
C2 Adapting timing-based REF � synchronization
21
Correct detection
Zen 3
Zen 3
Zen+
No clear signal
O3. Continuous, non-repeating time measurements strongly improve REF synchronization.
t0
t1
t2
t3
t4
t5
t6
t7
t0
t1
t2
t3
t4
t5
t6
t7
Issue: REF<t5,t6> not detected
⇨ measure continuously
Issue: Measurement imprecise
ACTs/tREFI = 8 x + 8 x
⇨ eliminate flushes
A1
A2
F1
F2
REF
REF
REF
REF
t0
t1
t1
t2
t2
t3
t3
t4
t4
t5
t5
t6
t6
t7
t7
t8
t8
t9
t10
t11
C3 Increasing the ACT rate and preserving order
22
Policy | Fencing Frequency | Pattern-Aware | Cache-Avoiding |
SPNONE | No fences | ✘ | ✘ |
SPBP | Every base period | ✓ | ✘ |
SPBP/2 | Every half base period | ✓ | ✘ |
SPPAIR | Between different aggressor pairs | ✓ | ✘ |
SPREP | Between aggressor pair repetitions | ✓ | ✓ |
SPFULL | Every access (Blacksmith default) | ✘ | ✓ |
Optimal Policy SPOPT
⇨ Zen 2 (75%), Zen 3 (43%)
⇨ Coffee Lake (100%)
Stronger ordering
Evaluation: Exploitation
23
Check out our paper�for details on the PoC!
DIMM | | PTE | | RSA-2048 | | sudo | |||||||||||||||
| Zen 2 | Zen3 | Coffee Lake | | Zen 2 | Zen3 | Coffee Lake | | Zen 2 | Zen3 | Coffee Lake | ||||||||||
| #Ex. | Time | #Ex. | Time | #Ex. | Time | | #Ex. | Time | #Ex. | Time | #Ex. | Time | | #Ex. | Time | #Ex. | Time | #Ex. | Time | |
S0 | | 7 | 6m 4s | 7 | 2m 55s | 3 | 15s | | 17 | 2m 47s | 37 | 46s | 14 | 1m 36s | | – | – | 4 | 3m 13s | 1 | 23m 49s |
S1 | | 90 | 9s | 1’474 | 2s | 846 | 2s | | 6 | 2m 2s | 27 | 30s | 21 | 26s | | – | – | 1 | 6m 50s | 1 | 1m 20s |
S2 | | 641 | 21s | 5’326 | 1s | 126 | 11s | | 30 | 2m 16s | 170 | 6s | 6 | 1m 59s | | – | – | 12 | 1m 17s | – | – |
S3 | | 142 | 9s | 61 | 32s | – | – | | 7 | 2m 21s | – | – | – | – | | – | – | – | – | – | – |
S4 | | 220 | 28s | 3 | 23m 52s | 2’658 | 1s | | 7 | 12m 29s | 1 | 23m 52s | 53 | 26s | | – | – | – | – | 4 | 5m 16s |
S5 | | 102 | 6s | 625 | 2s | 330 | 4s | | 6 | 1m 14s | 28 | 33s | 11 | 5s | | – | – | 2 | 5m 58s | 3 | 2m 34s |
H0 | | 11 | 53s | – | – | – | – | | – | – | – | – | – | – | | – | – | – | – | – | – |
Median | | | 21s | | 17s | | 4s | | | 2m 19s | | 33s | | 1m 5s | | | | | 4m 36s | | 3m 55s |
In-DRAM TRR: Order of accesses and ACT rate
24
refresh window (64 ms)
≜ 8192 refresh intervals
refresh interval (7.8 µs)
REF�+TRR
REF
REF
REF�
REF�+TRR
REF
REF
REF�+TRR
REF
REF
time
memory access�(hammer)
A1
A2
A1
A2
A3
A4
A1
A2
A3
A4
Program:
A1
A2
A1
A2
A3
A4
A1
A2
A3
A4
Execution (after optimization):
Check out our paper�for more information!
pjattke@ethz.ch
pjattke
linkedin.com/in/pjattke
Conclusion
C3 Increasing the ACT rate and preserving order
26
O6. For SK Hynix devices, SPPAIR works best across all devices.
O7. For Micron devices, preserving the access order is essential.
O5. For Samsung devices, SPPAIR is most widely applicable and most effective.