Replace UEFI With Linux
Replace UEFI With Linux
X86 CPU you know about X86 CPU(s) you don’t know about
What’s in ring -2 and ring -3?
● IP stacks (4 and 6)
● File systems
● Drivers (disk, net, USB, mouse)
● Web servers
● Passwords (yours)
● Can reimage your workstation even if it’s
powered off
Ring -3 OS: ME (Management Engine)
● Full Network manageability ● ICC Over Clocking
● Regular Network manageability ● Protected Audio Video Path
● Manageability (PAVP)
● Small business technology ● IPV6
● Level III manageability ● KVM Remote Control (KVM)
● IntelR Anti-Theft (AT) ● Outbreak Containment Heuristic
● IntelR Capability Licensing (OCH)
Service (CLS) ● Virtual LAN (VLAN)
● IntelR Power Sharing ● TLS
Technology (MPC) ● Wireless LAN (WLAN)
Vassilios Ververis: https://goo.gl/j7Jmx5
● Great overview of many early ME flaws
● Summary: just about every part of the ME
software can be attacked
● Only some of the bugs get fixed ...
‘Intel ME exploit’: 50M hits
● “Wired” headline: “HACK BRIEF: INTEL
FIXES A CRITICAL BUG THAT LINGERED
FOR 7 DANG YEARS”
● How many is that? One billion systems?
● Bug was in the built-in web server in the ME
○ Yep: the hidden CPU had a web server
○ That evidently you can’t turn off
○ Even though docs said you could
Ring -2 “½ OS”: System
Management Mode (SMM)
● Originally used for power management
● No time for full details but …
○ Vectors to 8086 16-bit mode code
■ I.e. great place for an attack
○ All kinds of interrupts can go here, e.g. USB
○ Nowadays almost all of these go out again to ACPI
● That said, it’s a very nasty bit of code
● Vendors use it as secret way to “value-add”
Are there SMI exploits?
● “system management interrupt exploit” --
630K hits
● So, yes.
● Chipsets guarantee that once SMM is
installed, can’t change it, see it, turn it off
○ SMM “hidden” memory at top 8 MiB of DRAM.
● SMM maintains vendor control over … you
Ring -2 OS: UEFI
● UEFI runs on the main CPU
● Extremely complex kernel
● Millions of lines of code
● UEFI applications are active after boot
● Security model is obscurity
Are there UEFI exploits?
● Absolutely
● Since UEFI (and only UEFI) can rewrite itself
○ These exploits can be made persistent
● You might even have UEFI fake the process
of removing an exploit
● The only fix? A shredder
(Some) UEFI components
CsmVideo ArpDxe Udp6Dxe UsbKbDxe
Terminal SnpDxe IpSecDxe UsbMouseDxe
SBAHCI MnpDxe UNDI UsbBusDxe
AHCI UefiPxeBcDxe IsaBusDxe XhciDxe
AhciSmm NetworkStackSetupScreen IsaIoDxe USB/XHCI/etc
BIOSBLKIO TcpDxe IsaSerialDxe Legacy8259
IdeSecurity Dhcp4Dxe DiskIoDxe DigitalTermometerSensor (sic)
IDESMM Ip4ConfigDxe ScsiBus
CSMCORE Ip4Dxe Scsidisk
HeciSMM Mtftp4Dxe GraphicsConsoleDxe
AINT13 Udp4Dxe CgaClassDxe
HECIDXE Dhcp6Dxe SetupBrowser
AMITSE Ip6Dxe EhciDxe
DpcDxe Mtftp6Dxe UhciDxe
UsbMassStorageDxe
Summary
● 2 ½ hidden OSes in your Intel x86 system
● They have many capabilities
● They have network stacks and web servers
● They implement self-modifying code that can
persist across power cycles and reinstalls
● They hide, have bugs, and control Linux
● Exploits have happened
● Scared yet? We sure are!
Can we fix this mess?
● Partially ...
○ Moving to AMD is not a solution, they’re closed too
○ Don’t believe all you read about Ryzen
● We focus on Intel x86 for now
● Reduce the scope of the 2 ½ OSes
● Overall project is called NERF
● Non-Extensible Reduced Firmware
○ Extensibility Considered Harmful
Non-Extensible Reduce Firmware
● Make firmware less capable of doing harm
● Make its actions more visible
● Remove all runtime components
○ Well, almost all: the ME is very hard to kill
○ But we took away its web server and IP stack
● Remove UEFI IP stack and other drivers
● Remove ME/UEFI self-reflash capability
● Linux manages flash updates
NERF components
● De-blobbed ME ROM
● UEFI ROM reduced to its most basic parts
● SMM disabled or vectored to Linux
● Linux kernel
● Userland written in Go (http://u-root.tk)
Removing the ME
● We don’t want ME at all; not an option
● If you remove ME firmware, your node
○ May never work again
○ May not power on (as in OCP nodes)
○ May power on, but will turn off in thirty minutes
● Good news: ME firmware has components
● And most are removable
○ Thanks Trammell Hudson
Removing most of the ME code
● me_cleaner can remove ME blobs
● https://github.com/corna/me_cleaner
● On minnowmax, 5M of 8M FLASH is ME
● me_cleaner.py reduces it to 300K
● Removes web server, IP stack, pretty much
all the things you don’t want “Ring -3” doing
● Server (SPS) is not yet solved
Me_cleaner on the minnowmax
BUP (Uncomp., 0x045000 - 0x05a000): NOT removed, essential
KERNEL (Uncomp., 0x05a000 - 0x08d000): removed
POLICY (Uncomp., 0x08d000 - 0x0a8000): removed
HOSTCOMM (Uncomp., 0x0a8000 - 0x0c0000): removed
FPF (Uncomp., 0x0c0000 - 0x0c6000): removed
RSA (LZMA , 0x0c6000 - 0x0cc385): removed
fTPM (LZMA , 0x0cd000 - 0x0dc305): removed
ClsPriv (Uncomp., 0x0dd000 - 0x0df000): removed
CLS (Uncomp., 0x0df000 - 0x0e8000): removed
SessMgr (LZMA , 0x0e8000 - 0x0f3906): removed
TDT (LZMA , 0x0f4000 - 0x0f9452): removed
It’s an eye test on OCP ...
BUP b2c2962872f9efb7fc905c53a56c6e47565406eefe350de7bd5ea52c4c3ef264 plain
BUP 1a24f58f9b04499cb7dcbd48155294494660f484912738cfe6bcb9a1dbfe589f plain
KERNEL 5b419f959814a4dbda06fdcaba4b84ed1a2488a2acb2de1ca2234807bba6d4fa [MATCH]
POLICY c84a79ee14d7231bd8e967fc8660228bb4f5d75a6c516247d1435cf5d266f46f [MATCH]
HOSTCOMM 5e54d9f081aecb3957ff83ea7b6b34e5209e9ed14252457cbf751019932ea92f [MATCH]
ICCMOD ee1a0bb460d2ea9c7e1669e85a54701c50f33013ae4c10f8dbc25fadddf82bfb [MATCH]
BASEEXT 84074ba8ba4b6dca24e086be37d8c768468b63e18d1ac5909ba1f8e1d0544f9b [MATCH]
SC 5b22b84a4ac67751a55c280ce6b69c2c9d6d649a9710031db43a14f39e4a337d [MATCH]
NM ba2ff3a68035174080a50da2fffab21c6de16b84838c9f7159ce3ec99e0c5261 [MATCH]
DM 91cbb5777bb5c5a3c2776edf15dc35b65b6ebda2ae83d0b7ea03cb080e95ea83 [MATCH]
BUP 1a24f58f9b04499cb7dcbd48155294494660f484912738cfe6bcb9a1dbfe589f plain
KERNEL 5b419f959814a4dbda06fdcaba4b84ed1a2488a2acb2de1ca2234807bba6d4fa [MATCH]
POLICY c84a79ee14d7231bd8e967fc8660228bb4f5d75a6c516247d1435cf5d266f46f [MATCH]
HOSTCOMM 5e54d9f081aecb3957ff83ea7b6b34e5209e9ed14252457cbf751019932ea92f [MATCH]
ICCMOD ee1a0bb460d2ea9c7e1669e85a54701c50f33013ae4c10f8dbc25fadddf82bfb [MATCH]
BASEEXT 84074ba8ba4b6dca24e086be37d8c768468b63e18d1ac5909ba1f8e1d0544f9b [MATCH]
SC 5b22b84a4ac67751a55c280ce6b69c2c9d6d649a9710031db43a14f39e4a337d [MATCH]
NM ba2ff3a68035174080a50da2fffab21c6de16b84838c9f7159ce3ec99e0c5261 [MATCH]
DM 91cbb5777bb5c5a3c2776edf15dc35b65b6ebda2ae83d0b7ea03cb080e95ea83 [MATCH]
Ring -2: Dealing with SMM
● We have experimental work that directs
SMM interrupts to kernel handler
● Requires that kernel run before SMM is
installed
● Or that SMM never be installed
● Most preferred: kill SMM
● Second: vector SMI# to kernel
Ring -2: On to UEFI ...
● There’s a huge amount of capability in UEFI
○ I.e. a great place to put exploits
● Some interrupts still go there
○ SECDED
● We want to remove those opportunities
● Unified Extensible Firmware Interface
○ Becomes NON-extensible
(Some) UEFI components
CsmVideo ArpDxe Udp6Dxe UsbKbDxe
Terminal SnpDxe IpSecDxe UsbMouseDxe
SBAHCI MnpDxe UNDI UsbBusDxe
AHCI UefiPxeBcDxe IsaBusDxe XhciDxe
AhciSmm NetworkStackSetupScreen IsaIoDxe USB/XHCI/etc
BIOSBLKIO TcpDxe IsaSerialDxe Legacy8259
IdeSecurity Dhcp4Dxe DiskIoDxe DigitalTermometerSensor
IDESMM Ip4ConfigDxe ScsiBus
CSMCORE Ip4Dxe Scsidisk
HeciSMM Mtftp4Dxe GraphicsConsoleDxe
AINT13 Udp4Dxe CgaClassDxe
HECIDXE Dhcp6Dxe SetupBrowser
AMITSE Ip6Dxe EhciDxe
DpcDxe Mtftp6Dxe UhciDxe
UsbMassStorageDxe
UEFI Components
Standard UEFI boot steps
OS-present
App, a.k.a.
exploit home
Step 1: Replace boot with Linux
“Boot Go-based
Manager” -> userland
Linux kernel (u-root.tk)
“Boot Go-based
Manager” -> userland
Linux kernel (u-root.tk)
DxeCore
import "fmt"
More than 4 binaries per architecture: Post-boot model where faster boot is
some/all commands precompiled, required
dynamic compilation, multiple
architectures in one root image
4 binaries, all commands in source form, Pre- or Post- boot model: u-root
dynamic compilation, one architecture installed in firmware or local device
All commands built into one binary which Usually firmware but also netboot of MIN
forks and execs each time “kexec” image
A deeper look at u-root “MAX”
● Standard kernel
● four Go binaries per architecture*
○ init/build binary (part of u-root, written in Go)
■ Merged-in minimized go build tool
○ Compile, asm, link
● All required Go package source
● u-root source for basic commands
● in 5.9M (compressed of course! :-)
Root structure at boot
linux_amd64/ init Only one required
and it can be called U-root init
/ linux_arm/ init binaries (only
/init if desired
one required)
linux_ppc64le/ init
src/
github.com/ U-root source
addrs, _ := v.Addrs()
fmt.Printf("%v has %v", v, addrs)
}
}
Taking rewriting further
● Request for single-binary version of u-root
for Cubieboard
○ Allwinner A10 --> not very fast
● Wanted to compile all u-root programs into
one program
Taking rewriting further
● With the ast package, we can rewrite
programs as packages, e.g. ls.go
package main package ls