Control Your AMD PSP Firmware
Control Your AMD PSP Firmware
undocumented,
proprietary firmware
Flash
1 – BIOS
Disk
1 – PSP FW
?
Flash
2 – BIOS
PSP
Disk
PSP
• Data is arranged
according to the UEFI CPU
image specification
--------------------------------------------------------------------------------
[...]
14405079 0xDBCDD7 `
Intel x86 instructions, nops
[...]
[Link] 11
FIRMWARE FILE SYSTEM
Magic Checksum Count ?
Type Size Address ?
Type …
…
Secondary
Directory
Directory
[Link] 12
FIRMWARE FILE SYSTEM File
Header optional
Secondary Body
Directory
Directory
Signature optional
Entry
13
FIRMWARE FILE SYSTEM
Firmware Entry Table
[Link] 14
$ psptool Supermicro_H11DSU9.715
+-----------+---------+---------+-------+---------------------+
| Directory | Addr | Type | Magic | Secondary Directory |
+-----------+---------+---------+-------+---------------------+
| 0 | 0x77000 | PSP_NEW | $PSP | 0x149000 |
+-----------+---------+---------+-------+---------------------+
+---+-------+----------+---------+---------------------------------+----------+-------------+------------------------------------+
| | Entry | Address | Size | Type | Magic/ID | Version | Info |
+---+-------+----------+---------+---------------------------------+----------+-------------+------------------------------------+
| | 0 | 0x77400 | 0x240 | AMD_PUBLIC_KEY~0x0 | 1BB9 | | |
| | 1 | 0x149400 | 0xe780 | PSP_FW_BOOT_LOADER~0x1 | $PS1 | [Link] | signed(1BB9), verified |
| | 2 | 0x77700 | 0xe780 | PSP_FW_RECOVERY_BOOT_LOADER~0x3 | $PS1 | FF.7.0.73 | signed(1BB9), verified |
| | 3 | 0x85f00 | 0x1e140 | SMU_OFFCHIP_FW~0x8 | | 4.19.7D.0 | compressed, signed(1BB9), verified |
| | 4 | 0xa4100 | 0x340 | OEM_PSP_FW_PUBLIC_KEY~0xa | 2793 | | |
| | 5 | 0xa4500 | 0x5640 | SMU_OFF_CHIP_FW_2~0x12 | | 4.19.7D.0 | compressed, signed(1BB9), verified |
| | 6 | 0xa9c00 | 0x10 | WRAPPED_IKEK~0x21 | | | |
| | 7 | 0xa9d00 | 0xc00 | SEC_GASKET~0x24 | $PS1 | [Link] | compressed, signed(1BB9), verified |
| | 8 | 0xaa900 | 0xc20 | ABL0~0x30 | 0BAR | [Link] | compressed, signed(2793), verified |
| | 9 | 0xab600 | 0xc020 | ABL1~0x31 | AR1B | [Link] | compressed, signed(2793), verified |
| | 10 | 0xb7700 | 0xb8f0 | ABL2~0x32 | AR2B | [Link] | compressed, signed(2793), verified |
| | 11 | 0xc3000 | 0xde70 | ABL3~0x33 | AR3B | [Link] | compressed, signed(2793), verified |
| | 12 | 0xd0f00 | 0xf1a0 | ABL4~0x34 | AR4B | [Link] | compressed, signed(2793), verified |
| | 13 | 0xe0100 | 0xf0a0 | ABL5~0x35 | AR5B | [Link] | compressed, signed(2793), verified |
| | 14 | 0xef200 | 0xc040 | ABL6~0x36 | AR6B | [Link] | compressed, signed(2793), verified |
| | 15 | 0x149000 | 0x0 | !PL2_SECONDARY_DIRECTORY~0x40 | | | |
+---+-------+----------+---------+---------------------------------+----------+-------------+------------------------------------+
+-----------+----------+-----------+-------+---------------------+
| Directory | Addr | Type | Magic | Secondary Directory |
+-----------+----------+-----------+-------+---------------------+
| 1 | 0x149000 | secondary | $PL2 | -- |
+-----------+----------+-----------+-------+---------------------+
+---+-------+----------+---------+-----------------------------+----------+-------------+------------------------------------+
| | Entry | Address | Size | Type | Magic/ID | Version | Info |
+---+-------+----------+---------+-----------------------------+----------+-------------+------------------------------------+
| | 0 | 0x149400 | 0xe780 | PSP_FW_BOOT_LOADER~0x1 | $PS1 | [Link] | signed(1BB9), verified |
| | 1 | 0x159400 | 0x1e140 | SMU_OFFCHIP_FW~0x8 | | 4.19.7D.0 | compressed, signed(1BB9), verified |
15
PSPTOOL
[Link] 16
The PSP runs code you
don’t know and don’t control.
SPI Programming
and Tracing
Logic Analyzer
Flash
SPI
Programmer
18
SPI Programming
and Tracing
Clock (CLK)
19
PSPTRACE $ psptrace -o Supermicro_SPI_trace.txt Supermicro_H11DSU9.715
+---------+---------------+----------+-----------------------------+
| No. | Lowest access | Range | Type |
+---------+---------------+----------+-----------------------------+
Python-based SPI command parsing | 0 | 0xE20000 | 0x000040 | Firmware Entry Table |
| 41 | 0x077000 | 0x00012a | PSP_DIRECTORY |
| 112 | 0x077400 | 0x000240 | AMD_PUBLIC_KEY |
Correlate file system information | 181 | 0x149400 | 0x00d780 | PSP_FW_BOOT_LOADER |
| | | | |
| | | | ~ 3415 µs delay ~ |
Aggregate duplicate reads GPLv3 | | | | |
| 7083 | 0x149000 | 0x000180 | PL2_SECONDARY_DIRECTORY |
| | | | |
Aggregate consecutive reads | | | | ~ 67 µs delay ~ |
| | | | |
| 7094 | 0x117000 | 0x000160 | BHD_DIRECTORY |
[...]
[Link] 20
More details on our hardware setups:
Watch our talk from CCCamp19
[Link] 21
Cryptographic protections on files
File
Header
• Files are protected by a signature
Body
• Header field determines the according
PublicKey1 Signature
1 [Link] 22
Early PSP Boot Procedure
On-Chip Off-Chip Bootloader
Bootloader (PSP_FW_BOOT_LOADER)
+---------+---------------+----------+-----------------------------+
2. Load AMD_PUBLIC_KEY
| No. | Lowest access | Range | Type |
+---------+---------------+----------+-----------------------------+
3. Verify AMD_PUBLIC_KEY
| 0 | 0xe20000 | 0x180007 | Firmware Entry Table |
| 41 | 0x077000 | 0x00012a | PSP_DIRECTORY | 4. Load PSP_FW_BOOT_LOADER
| 112 | 0x077400 | 0x000240 | AMD_PUBLIC_KEY |
| 181 | 0x149400 | 0x00d780 | PSP_FW_BOOT_LOADER |
5. Verify with AMD_PUBLIC_KEY
| | | | |
| | | | ~ 3415 µs delay ~ |
| | | | |
| 7083 | 0x149000 | 0x000180 | PL2_SECONDARY_DIRECTORY |
| | | | | 1. Initialize PSP
| | | | ~ 67 µs delay ~ |
| | | | |
2. Load more directories
| 7094 | 0x117000 | 0x000160 | BHD_DIRECTORY |
3. Load and verify applications
23
Understand
HOW DEEP DOES THE RABBIT HOLE GO?
x86 x86 x86 x86
Core Core Core Core
CCD CCD 0 CCD 1
x86 x86 x86 x86
Core Core Core Core CPU0
CCX CCX
CCD 2 CCD 3
0x01000000
MEMORY LAYOUT
• 256KB on chip SRAM MMIO mapping space
• Code separated in SVC and USR CCP
mode parts MMIO
SMN access
• USR mode parts loaded during X86 memory access
boot and later on demand (SEV) …
0xFFFFFFFF 26
On-Chip Bootloader Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
ABL0
DebugUnlock SecGasket ABL1 ABL2 ABL3 ABL4 ABL6 SEV
BOOT PROCESS
• On-Chip Bootloader loads Off-Chip bootloader from flash
• Off-Chip Bootloader loads and executes apps in specific order
• System is initialized by different ABL stages
• SEV app is loaded during runtime upon the request of the OS
Hardware
Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
76 Syscalls
18 completely unknown
28
| Region | Size | WP | MPsp | Offset | RegSz | Description | Register description |
|------------|------|----|------|--------|--------|----------------------------------------------------------------------------------------|----------------------------------|
| 0x0001c880 | 128 | + | - | | | Memory protection slots | |
| | | | | 0x00 | 32bit | Slot 0: Start address of protected region X86PADDR[47:20] + 4 flags | aaaaaaaaaaaaaaaaaaaaaaaaaaaa???? |
| | | | | 0x04 | 32bit | Slot 0: End address (inclusive) of protected region X86PADDR[47:20] + 4 flags | aaaaaaaaaaaaaaaaaaaaaaaaaaaa???? |
| | | | | 0x08 | 32bit | Slot 0: Control register (seen 0x600000a | 0x6000006) | ???????????????????????????????e |
| | | | | 0x0c | 32bit | Slot 0: Unused/Reserved (no access observed anywhere) | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| | | | | ... | ... | Slot 1 - 7 | ... |
SYSTEM
MANAGEMENT PSP UMC SMU
NETWORK (SMN)
• Hidden control network
System Management Network (SMN)
• Dedicated address space
• PSP maps regions into own ? ???????
address space to access device
registers x86
?
29
Off-Chip Bootloader
(PSP_FW_BOOT_LOADER) $ strings [Link]
[…]
ABL2 mixedWithNvdimmInSystem = %x
mixedWithNvdimmInSocket = %04x
----------------------------------------------------------------------
----------
ENABLE DEBUG Sync Speed Disabled - Gathering Speed Data for single die only
OUTPUT Master: Retrieve debug data from the slaves at debug sync
point %04x
[…]
• Lots of interesting debug strings $ arm-none-eabi-objdump -b binary --adjust-vma 0x16000 -D [Link] -m
armv5 -Mforce-thumb |grep -B 5 "svc\t6“
• SVC 0x6 uses string address as […]
the first argument 2191c: a0be add r0, pc, #760 ; (adr r0,
0x21c18)
• Not implemented in release 2191e: df06 svc 6
firmware L
30
Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
App
31
[…]
MEM PARAMS:
AGESA BL Heap Size : 7800
BottomIo : 0080
MemHoleRemap : 1
LimitBelow1TB : 1
UserTimingMode : 0
MemClockValue : 1200
MemRestoreCtl : 0
SaveMemContextCtl : 1
ExternalVrefCtl : 0
ForceTrainMode : 2
AMP : 0
0x00800F12 (32b)
0x00006031 (32b)
0x00800F12 (32b)
0x00006031 (32b)
ZP DDR4 DRAM Initialization - Phase 2
[…]
32
Master PSP
X86 Core Ring 0
Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
Ring 3
pypspproxy libpspproxy
EXPLORING THE SMN
DEVICES
import pypspproxy;
PSP:
[…]
for idCcd in xrange(8):
[Link](idCcd);
• Read/Write SMN address _, uR0 = [Link](0x28, 0x14, 0x1, 0x0, 0x0);
[Link](idCcd, 0x1c890, 4, (physAddr >> 20) |
• Execute syscall
5);
[Link](idCcd, 0x1c894, 4, physAddr >> 20);
[Link](idCcd, 0x1c898, 4, 0x600000a);
• Read/Write PSP memory _, uR0 = [Link](0x28, 0x14, 0x0, 0x0, 0x0);
33
Master PSP
X86 Core Ring 0
Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
/dev/sev
Ring 3
libpspproxy
PSP EMULATOR
• Emulate a PSP using
Unicorn engine PSPEmu
AMD sev-tool
• Current state can run SEV SEV App
app to a certain point
34
Master PSP
X86 Core Ring 0
Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
[…] /dev/sev
Mapping SMN address 0x1d700 on CCD 0
>>> SMN read at 0x0211d700 Ring 3
[…]
Syscall 0x33 happened at 0x19e24
R0 > 0x00021e2c | R1 > 0x000024b4 | R2 > 0x00000000 | R3 > 0x00000000
R4 > 0x00000000 | R5 > 0x00021e2c | R6 > 0x000024b4 | R7 > 0x00000007
R8 > 0x0001d4b8 | R9 > 0x0001ca98 | R10> 0x00000000 | R11> 0x00000000
[…] libpspproxy
R12> 0x00000000 | SP > 0x00061f00 | LR > 0x0001b727 | PC > 0x00019e26
PSP EMULATOR
Syscall 0x38 happened at 0x19ec0
CCP Request:
PspAddrBufUnk0: 0
cbBufUnk0: 0
dwUnk1: 0x2
Unicorn engine
dwUnk3: 0
dwUnk4: 0x1
PSPEmu
dwUnk5: 0
[…]
AMD sev-tool
• Current state can run SEV SEV App
app to a certain point
35
Master PSP
X86 Core Ring 0
Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
[…] libpspproxy
R12> 0x00000000 | SP > 0x00061f00 | LR > 0x0001b727 | PC > 0x00019e26
PSP EMULATOR
Syscall 0x38 happened at 0x19ec0
36
INTERESTED? HERE IS THE CODE
37
Own
PART 1:
BOUNDS CHECKING IS HARD
Attacker Capabilities
Directory File Secondary directory
Header
Header Header
Body
ID | Address
Entry | Size ID | Address | Size
39
Attacker Capabilities
Directory File Secondary directory
Header
Header Header
Body
ID | Address
Entry | Size ID | Address | Size
ID | Address | Size
• We can:
• Add Entries
• Remove Entries
• Change Entries
40
On-Chip Bootloader Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
Header
AMD_PUBLIC_KEY
… …
AMD_PUBLIC_KEY
Second. Directory
Header
ID | Address | Size
ID | Address | Size
41
On-Chip Bootloader Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
Header Header
AMD_PUBLIC_KEY AMD_PUBLIC_KEY
… …
AMD_PUBLIC_KEY
Second. Directory Second. Directory
ID | Address | Size
Header
ID | Address | Size
ID | Address | Size
ID | Address | Size
AMD_PUBLIC_KEY
42
43
On-Chip Bootloader Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
Header
Header
AMD_PUBLIC_KEY AMD_PUBLIC_KEY
… …
AMD_PUBLIC_KEY 64
Second. Directory Second. Directory Entries
ID | Address | Size
Header
ID | Address | Size
ID | Address | Size
Header
Header
int append_second(void) {
AMD_PUBLIC_KEY ... AMD_PUBLIC_KEY
… if (nr_entries > 64u) …
return -1;
AMD_PUBLIC_KEY
Second. Directory ... Second. Directory
return 0;
}
ID | Address | Size
Header
ID | Address | Size
ID | Address | Size 64
Entries
ID | Address | Size Max. 64 AMD_PUBLIC_KEY
PUBLIC KEY
45
PUBLIC KEY
On-Chip Bootloader Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
ABL0
ABL0
DebugUnlock SecGasket ABL1 ABL2 ABL3 ABL4 ABL6 SEV
BOOT PROCESS
• Directory parsing takes place
before loading any application.
-> We control the user mode
beginning from the first application.
Own
PART 2:
INPUT VALIDATION IS HARD
On-Chip Bootloader Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
ABL0
ABL0
DebugUnlock SecGasket ABL1 ABL2 ABL3 ABL4 ABL6 SEV
BOOT PROCESS
• Directory parsing takes place
before loading any application. How can we take over
We control the user mode beginning the kernel mode?
from the first application.
Virtual memory
0x0
Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
Kernel Mode PSP_FW_BOOT_LOADER
ID | Address | Size
PSP_FW_BOOT_LOADER
DATA
…
ID | Address | Size
? ? ?
?PAGE TABLES
Application
Header
ID | Address | Size
ID | Address | Size …
PAGE TABLES
50
int copy_from_flash(void* dst, void* src,int size);
Flash
Virtual memory
BIOS Directory
Header CODE
ID | Address | Size
Copy operation into privileged memory.
… Attacker controlled data.
PSP_FW_BOOT_LOADER
DATA
Application
Header
ID | Address | Size
ID | Address | Size …
PAGE TABLES
51
int copy_from_flash(void* dst, void* src,int size);
Flash
Virtual memory
BIOS Directory
Header CODE
ID | Address | Size
Copy operation into privileged memory.
… Attacker controlled data.
PSP_FW_BOOT_LOADER
DATA
Application
Header
ID | Address | Size
ID | Address | Size …
PAGE TABLES
52
Virtual memory
0x0
Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
Kernel Mode v PSP_FW_BOOT_LOADER
User-writable
VIRTUAL ADDRESS SPACE Application
Overwriting the page tables
allows us to declare all User Mode
memory as user-writable.
…
0xFFF….
53
On-Chip Bootloader Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
ABL0
ABL0
DebugUnlock SecGasket ABL1 ABL2 ABL3 ABL4 ABL6 SEV
BOOT PROCESS
• Directory parsing takes place before
loading any application.
AMD has fixed these issues!
-> We control the user mode beginning
from the first application.
-> We control the kernel mode
beginning from the first application.
On-Chip Bootloader Off-Chip Bootloader
(PSP_FW_BOOT_LOADER)
ABL0
ABL0
DebugUnlock SecGasket ABL1 ABL2 ABL3 ABL4 ABL6 SEV
Header
Epyc Naples
Issue for:
• Secure boot.
• Trusted Execution Environment.
• Secure Encrypted Virtualization (SEV)
• Paper: Insecure Until Proven Updated
Buhren, Robert, Christian Werling, and Jean-Pierre Seifert. "Insecure Until Proven
Updated: Analyzing AMD SEV's Remote Attestation." Proceedings of the 2019 ACM
SIGSAC Conference on Computer and Communications Security. ACM, 2019.
57
This is an opportunity!
Gain more insight into the PSP!
58
Idea
By Adrien Coquet, FR
magnifier
By Desainer Kanan, ID
UNCOVER, UNDERSTAND, OWN
Regaining Control Over Your AMD CPU
THANK YOU
Christian Werling Alexander Eichner Robert Buhren
Security Research Labs Technische Universität Berlin Technische Universität Berlin
Security in Telecommunications
59
Further details
• Github repository [Link]
60