Insecure Boot: Andrea Barisani - Head of Hardware Security
Insecure Boot: Andrea Barisani - Head of Hardware Security
I am a
https://andrea.bio | @andreabarisani
HARDWARE SECURITY
An hardware anchor (e.g. SoC boot ROM) authenticates the first user provisioned code,
such as the bootloader.
The bootloader must then maintain the chain of trust with cryptographic verification of
signed kernel images (e.g. public key verification).
The booted Operating System must also maintain the chain of trust by validating all
executed code and ensuring proper lockdown.
System
On Boot Operating
Chip Loader System
Implementing Secure Boot
https://github.com/inversepath/usbarmory/wiki/Secure-boot-(Mk-I)
Implementing Secure Boot
https://github.com/inversepath/usbarmory/wiki/Secure-boot-(Mk-II)
AUTOMOTIVE | AVIATION | INDUSTRIAL
U-Boot 2019.07
U-Boot 2019.07
ARM® TrustZone®
NXP - Secure Non-Volatile Storage (SNVS)
The SNVS feature relies on the OTPMK, a unique per-device hardware key, which cannot be
read directly as it can only be used via the SoC internal Cryptographic Accelerator and Assurance
Module (CAAM), when secure booted.
The blob encryption key is used to encrypt the desired data via the CAAM
AES-CCM function, providing confidentiality and integrity protection.
The blob encryption key is AES-ECB encrypted with a key derived from the OTPMK (BKEK),
using a Single-step Key-Derivation Function, resulting in the blob.
The HAB secure boot sequence, or runtime environment, can directly support
authenticated decryption of arbitrary data blobs (including the bootloader image).
NXP CAAM + SNVS driver
https://github.com/inversepath/caam-keyblob
$ sudo modprobe caam_keyblob
Go userspace implementation:
$ caam_tool enc dek.bin dek_blob.bin
caam_tool: encrypting 32 bytes from dek.bin
caam_tool: caam_kb_data &{Text:0x49c000 TextLen:32 Blob:0x4a0000 BlobLen:80 Keymod:0x48c010 KeymodLen:16}
caam_tool: encrypted 80 bytes to dek.bin
6 4,5
stored LUKS
Linux zImage decryption procedure
key material encrypted partition
key material
► SoC authenticates U-Boot authenticated + encrypted
► U-Boot authenticates Linux
► Linux uses SVNS decrypted key material to unlock the encrypted partition
Rollback protection + external keyring
SoC
Firmware
key material
1 authenticated + encrypted
The SoC can establish a secure session with the ATECC608A, using safely
stored read and write keys, certificates or data.
This allows secure key/certificate access or use, additionally two High Endurance
Monotonic Counters can be used for rollback protection.
Provides an additional hardware keyring for (partial) mitigation of further HAB issues.
ARM® TrustZone®
DRM purposes
● Secured user interaction (e.g. PIN) Slide from ACM CCS 2013 TEE Tutorial
Case Study:
ARM® TrustZone®
DMA bypass
Memory separation: DMA
Case Study:
HABv4
HABv4 bypass
In 2017 Quarkslab discovered critical security vulnerabilities that affect HABv4 on the
entire NXP i.MX series.
The issue was reported for the i.MX6, Inverse Path immediately investigated applicability
to the i.MX53.
A X.509 parsing error (ERR010873 | CVE-2017-7932) and an SDP protection bypass
(ERR01872 | CVE-2017-7936) allow arbitrary code execution on SoC in Closed
configuration.
The findings prevent the secure operation of unattended setups while attended setups
remain protected in case of device loss (but not tampering).
NXP did not release any P/N updates for the i.MX53.
https://github.com/inversepath/usbarmory/blob/master/software/secure_boot/Security_Advisory-Ref_QBVR2017-0001.txt
HABv4 bypass
Timeline
========
F-Secure prioritized announcing the existence of the issue before the full advisory
release, additionally developed and released a full PoC.
The usbarmory_csftool is the only Open Source implementation for HABv4 signing as
well as the first and only exploitation tool ;-)
“Break your own product, and break it hard”
https://labsblog.f-secure.com/2017/07/19/break-your-own-product-and-break-it-hard/
HABv4 bypass
$ usbarmory_csftool -h
Usage: usbarmory_csftool [OPTIONS]
-A | --csf_key <private key path> CSF private key in PEM format
-a | --csf_crt <public key path> CSF public key in PEM format
-B | --img_key <private key path> IMG private key in PEM format
-b | --img_crt <public key path> IMG public key in PEM format
-I | --table <SRK table path> Input SRK table (see usbarmory_srktool -O)
-x | --index <SRK key index> Index for SRK key (1-4)
-i | --image <filename> Image file w/ IVT header (e.g. u-boot.imx)
-o | --output <filename> Write CSF to file
-s | --serial Serial download mode
-S | --dcd <address> Serial download DCD OCRAM address
| (depends on mfg tool, default: 0x00910000)
|
-d | --debug Show additional debugging information
-T | --hab_poc Apply HAB bypass PoC (CVE-2017-7932)
|
-h | --help Show this help
Publishing PoC code encourages further investigation and testing of issues among vendors or other affected
parties; it promotes security research; and it empowers other skilled parties to further verify the scope and
impact of vulnerabilities.
The most important and compelling reason to take this approach, however, is this: In scenarios where
detailed technical information has already been made public, the lack of a working PoC does not, and should
not, constitute any form of “protection.”
One-Time-Programmable (OTP) fuses
https://github.com/inversepath/crucible
...
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 OCOTP_CFG0
┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓ Bank:0 Word:1
┃LOT_NO_ENC[31:0] ┃ R: 0x00000004
┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛ W: 0x00000004
31 ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ 00 UNIQUE_ID[31:0]
31 ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ 00 UNIQUE_ID
31 ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ 00 SJC_CHALLENGE
31 ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ 00 LOT_NO_ENC[31:0]
31 ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ 00 LOT_NO_ENC
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 OCOTP_CFG1
┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓ Bank:0 Word:2
┃DIE-X-CORDINATE ┃DIE-Y-CORDINATE ┃WAFER_NO ┃LOT_NO_ENC[42:32] ┃ R: 0x00000008
┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛ W: 0x00000008
31 ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ 00 UNIQUE_ID[63:32]
31 ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ 24 ─────────────────────────────────────────────────────────────────────── DIE-X-CORDINATE
23 ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ 16 ─────────────────────────────────────────────── DIE-Y-CORDINATE
15 ┄┄ ┄┄ ┄┄ 11 ──────────────────────────────── WAFER_NO
10 ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ ┄┄ 00 LOT_NO_ENC[42:32]
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00 OCOTP_CFG2
┏━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┳━━┓ Bank:0 Word:3
┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃TAMPE┃SI_REV ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ R: 0x0000000c
┗━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━╋━━┻━━┻━━┻━━┻━━┻━━┻━━┻━━┛ W: 0x0000000c
21 20 ─────────────────────────────────────────────────────────── TAMPER_PIN_DISABLE
19 ┄┄ ┄┄ 16 ─────────────────────────────────────────────── SI_REV
...
crucible - i.MX6UL example
registers:
OCOTP_LOCK:
bank: 0
Blow a fuse word: 0
fuses:
$ sudo crucible -m IMX6UL -r 1 -b 16 blow MAC1_ADDR 0x001f7b1007e3 TESTER_LOCK:
IMX6UL ref:1 op:blow addr:0x88 off:0 len:48 val:0xe307107b1f000000
offset: 0
len: 2
BOOT_CFG_LOCK:
Read a fuse offset: 2
Len: 2
...
$ sudo crucible -m IMX6UL -r 1 -b 16 read MAC1_ADDR OCOTP_MAC0:
IMX6UL ref:1 op:read addr:0x88 off:0 len:48 val:0x001f7b1007e3 bank: 4
word: 2
fuses:
Read a fuse (minimal output for batch operations) MAC1_ADDR:
offset: 0
len: 48
$ sudo crucible -s -m IMX6UL -r 1 -b 16 read MAC1_ADDR OCOTP_MAC1:
001f7b1007e3 bank: 4
word: 3
OCOTP_MAC:
bank: 4
word: 4
crucible - i.MX6UL lock down
It is vital to reduce the low-level SoC attack surface as much as possible and
ensure lock down of all relevant fuses.
# set device in Closed Configuration (IMX6ULRM Table 8-2, p245)
crucible -m IMX6UL -r 1 -b 2 -e big blow SEC_CONFIG 0b11
Against Silicon Revision 1.2 and HAB 4.1 or greater, meaning P/Ns “AB” or greater, with
patched HABv4.
Completed as an internal + third party security audit for HABv4 as well as our buildroot
chain of trust implementation.
Conclusions
Freescale/NXP kernel module issues (invalid error values, NULL pointer exceptions,
various operational errors), all resolved in our own driver ports.
Case Study:
U-Boot
U-Boot Verified Boot bypass
CVE-2018-18440
Lack of boundary checks in filesystem image load.
CVE-2018-18439
Lack of boundary checks in network image boot.
https://github.com/inversepath/usbarmory/blob/master/software/secure_boot/Security_Advisory-Ref_IPVR2018-0001.txt
CVE-2018-18440
CVE-2018-18440
The optional bytes argument can be passed to all
load commands to restrict the maximum size of
retrieved data. A value consistent with memory
regions mapping can be passed.
CVE-2018-18439
Disable all network loading commands.
https://github.com/inversepath/usbarmory/blob/master/software/secure_boot/Security_Advisory-Ref_IPVR2018-0001.txt
Breaking Secure Boot
Case Study:
https://github.com/inversepath/advisories/blob/master/Security_Advisory-Ref_FSC-HWSEC-VR2019-0001-Xilinx_ZU%2B-Encrypt_Only_Secure_Boot_bypass.txt
Xilinx Zynq UltraScale+ Secure Boot bypass
Before:
After:
https://github.com/inversepath/advisories/blob/master/Security_Advisory-Ref_FSC-HWSEC-VR2019-0001-Xilinx_ZU%2B-Encrypt_Only_Secure_Boot_bypass.txt
KEY TAKEWAYS
It is vital to account for all phases of the chain of trust for design and implementation flaws.
The strongest hardware anchor can be compromised by the smallest mistake, whether
hardware or software, throughout the chain of trust.
Low level boot ROM issues have critical impact due to their lack of mitigation in most cases,
requiring P/N replacement (if available)...there are no remote hardware upgrades!
Most SoC boot ROMs are either vulnerable or likely to suffer from critical Secure Boot findings.
6 4,5
stored LUKS
Linux zImage decryption procedure
key material encrypted partition
When building single purpose firmware images the attack surface, and maintenance
burden, of the Linux kernel and runtime is considerable.
We introduce a development project that ultimately aims to reduce it as much as
possible.
Reducing the attack surface with TamaGo
vec_start 0x81000000
vec_size 0x40
bootstack start 0x9ff00000
exception stack_start 0x9ff20000
exception stack_size 0x10000
g0.stackguard0 0x9fef0000
g0.stackguard1 0x9fef0000
g0.stack.lo 0x9fef0000
SoC
g0.stack.hi 0x9ff00000
mmu_map: 0x80000000 0x20000000
----------------------------------------------------------------------
imx6_rng: self-test...done
imx6_rng: seeding...done
imx6_soc: i.MX6ULL (0x65, 0.1) @ freq:900 MHz - native:true
Hello from tamago/arm! (epoch 3038767125)
launched 6 test goroutines
-- i.mx6 dcp ---------------------------------------------------------
imx6_dcp: derived SNVS key 7d5fec1ee57ab31e4ca75a59c568ffb6
-- file --------------------------------------------------------------
read /tamago-test/tamago.txt (22 bytes)
-- sleep ------------------------------------------------------------- U-Boot image
sleeping 100ms @ 72238750
slept 100ms @ 174514000
-- rng ---------------------------------------------------------------
51682759bfbeee914df905b69d37a3504f94ab2d40dbdd3f5a51e1c7c061a285
-- ecdsa -------------------------------------------------------------
ECDSA sign and verify with p224 ... done (114.507375ms)
ECDSA sign and verify with p256 ... done (47.94475ms)
-- btc ---------------------------------------------------------------
Script Hex: 76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac
Script Disassembly: OP_DUP OP_HASH160 128004ff2fcaf13b2b91eb654b1dc2b674f7ec61 OP_EQUALVERIFY OP_CHECKSIG
Script Class: pubkeyhash
Addresses: [12gpXQVcCL2qhTNQgyLVdCFG2Qs2px98nV]
Required Signatures: 1
Transaction successfully signed
Go
----------------------------------------------------------------------
completed 6 goroutines
Goodbye from tamago/arm (5.7927555s)
exit with code 0 halting
OS
drivers
peripherals
TamaGo
drivers
Go tamago
peripherals runtime Go pkg Go pkg
imx6 usbarmory
system calls
Go runtime
system calls
bootloader
Go pkg: main
TamaGo
package main
import (
"imx6"
// required to initialize board
_ "usbarmory/mark-two"
)
func main() {
key, err := imx6.DCP.DeriveKey(diversifier, iv)
// do stuff...
...
}
https://github.com/inversepath/tamago/wiki
どうもありがとうございます
Questions?
Andrea Barisani
Head of Hardware Security
[email protected]
https://github.com/inversepath/advisories
https://www.f-secure.com/documents/10192/2157381/fsecure-hardware-security-services-overview.pdf