Skip to content

Lesson 8 of 13 · 16m

U-Boot and the Boot Environment

U-Boot is an interactive shell that decides what your kernel is; its environment, its countdown, and its parser bugs are the attack surface.

A shell that happens to boot

U-Boot is not a trampoline. It is a command interpreter with flash drivers, a network stack, a filesystem parser, and a scripting language, which at power-on happens to run whatever the bootcmd variable says. On ARM boards the chain runs mask ROM → SPL (Secondary Program Loader, small enough for SRAM) → U-Boot proper → kernel — on ARM64 the SPL is usually TF-A's BL2, with BL31 runtime services and sometimes OP-TEE between it and U-Boot. On each of those transitions there is a shell to land in.

The environment lives in its own raw flash region — an MTD partition, a fixed offset in SPI, or an eMMC boot area — serialized as name=value pairs under a CRC32. printenv dumps it; setenv edits the running copy; saveenv commits it. bootcmd is usually a chain of run commands; bootargs becomes the kernel cmdline; bootdelay is the countdown printed over UART as Hit any key to stop autoboot:. Designs that need persistence protection store the environment twice — a redundant copy that takes over if the primary's CRC fails — and Linux-side tooling (fw_printenv, fw_setenv from libubootenv/u-boot-tools) reads and writes the same region after boot, which makes it an attack surface from userspace too, not just the console — the userspace mapping comes from /etc/fw_env.config, whose offset and length must match the bootloader's compiled CONFIG_ENV_* layout or fw_setenv edits the wrong bytes, and mkenvimage builds a fresh env blob when factory provisioning needs one. Send a key, and the parser drops you into the shell with sf probe / sf read / sf erase for SPI, nand commands for raw NAND, fatload/ext4load for filesystems, md for memory, and tftpboot for pulling anything TFTP serves. From that shell, setenv bootargs ${bootargs} init=/bin/sh followed by boot is a root shell on the live rootfs. On a device you own this is recovery. On a device an attacker owns physically, it is everything.

The wrong mental model

"The bootloader runs before the OS, so it's small and safe." U-Boot parses untrusted input by design — filesystems on removable media, DHCP/BOOTP responses, NFS, TFTP payloads, USB mass storage. In May 2022 JFrog disclosed thirteen CVEs in exactly that code: memory corruption in the NFS path (CVE-2022-30790 among them), DNS, and related parsing — exploitable before a kernel exists, by anything the boot path touches, including a malicious USB stick or a rogue DHCP answer. A parser that runs before ASLR, before the kernel's mitigations, and before logging is a parser that earns audit attention.

The second wrong model: "the environment is configuration, not attack surface." The env partition is where bootcmd lives. An attacker who can write env — a kernel-level write to the env partition, a corrupted update, or fw_setenv on a device they already own at the OS layer — changes what the device boots without touching the kernel image at all.

FIT and verified boot

U-Boot's answer to all this is the FIT image: a flattened image tree (.its) describing kernel, device tree, ramdisk, and signatures under /configurations. With CONFIG_FIT_SIGNATURE compiled in and a public key baked into U-Boot's own control FDT under /signature, images verify — but only when the config node carries required = "conf". A FIT built without required accepts unsigned images silently, which is the single most common verified-boot failure in the field: signing infrastructure that exists and does not enforce. The enforcement key lives in U-Boot's own control FDT under /signature — so FIT verification is only as trustworthy as the stage carrying it, which is why full verified chains anchor the SPL's own image against eFuse-burned public key hashes before U-Boot ever runs. The env block also carries the boot-attempt handshake: bootcount increments per boot, bootlimit is the ceiling, and altbootcmd is what runs when it is exceeded — the poor-man's A/B.

What to actually do

Audit: interrupt autoboot, printenv, read bootcmd to find where the kernel actually loads from, and check whether FIT verification is required or ornamental. Ship: bootdelay=-2 so the countdown cannot be interrupted, disable USB/network boot in production configs unless the product needs them, require FIT signatures, and treat the env partition as a write-protected asset — or compile the environment in so saveenv has nowhere to land.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.