Article by : Mohamed BELOUARGA & Fabien Lahoudere
The world is becoming more and more connected, and millions of devices are developed to be connected either to servers or to each other. This hyper connectivity comes with many threats and Linux-based embedded systems are not exempt from them.
In this article, we will discuss a technique that adds security to embedded Linux devices, but the reader should be aware that this method does not protect embedded Linux devices from all threats.
The reader should know that the author is an embedded Linux engineer and not a cybersecurity expert.
Secure boot is all about implementing a trust chain between different software components of an embedded Linux device. This chain of trust is implemented to prevent the devices from running corrupted software, or software that does not originate from the device manufacturer.
This chain of trust is, in fact, a layered verification process that will identify the origin of these software components
First the ROM code verifies that the bootloader comes from the manufacturer, then the bootloader verifies that the Linux kernel also comes from the manufacturer before launching it and finally the kernel verifies that the ROOTFS (the application) comes from the manufacturer.
We will see below how this trust chain works – or what we call secure boot-, and how to implement it.
This part is hardware dependent and realized by hardware and ROM code. The ROM code verifies that the bootloader is from the manufacturer, by checking its signature. The signature of the bootloader is usually its hash encrypted by a private key.
If the signature is corrupted, the ROM code does not launch the bootloader, thereby the device doesn’t boot.
After its verification, the ROM code launches the bootloader.
The bootloader initializes just enough hardware (at least SDRAM and serial console) to boot the kernel and to load the kernel as well as the device tree into RAM.
The bootloader checks kernel and the device tree signature’s (and other binaries if necessary), before booting the kernel.
If binaries have to be checked, a FIT image containing all these binaries, can be used to gain some efficiency in this process.
To secure the ROOTFS, it is preferable to use a read-only ROOTFS and take advantage of a feature provided by the kernel, called DM-verity.
Dm-verity uses a hash tree to ensure that the ROOTFS is not corrupted. Layer0 of the hash tree contains the ROOTFS hashes -one hash for every 4k.
More detail in the schema below.
In order to use DM-verity on the ROOTFS partition, it is easier to use an InitRamFS that launches DM-verity on the partition of the ROOTFS before switching to the ROOTFS.
The InitRamFS (that contains the root hash) should be added to the FIT image and should also be signed.
If DM-verity detects a corruption in the ROOTFS or if the root hash changed, the feature generates a kernel panic, which blocks the launch.
To illustrate some hardware dependent aspects of the secure boot, we will take imx8 as an example:
Before trying to implement secure boot on imx8, we need to generate some private keys that will be used to sign the binaries. NXP provides CST tools (Code Signing Tool) that generates privates and public keys, and allows us to sign the bootloader and other binaries.
Imx8 has a module called CAAM (Cryptographic Acceleration and Assurance Module) that will be used to speed up the verification of all signatures. Imx8 also has some registers called One-Time Programmable registers (eFuse).
In order to enable signature verification, SRK_HASH eFuses must be programmed with the generated public keys hashes, and to lock the card, another eFuse should be programmed.
All these elements will be used to implement the HAB (High Assurance Boot): the imx secure boot.
At the boot time, The ROM code verifies if the SRK_HASH eFuses are programmed. If it is the case, it will verify the signature of the bootloader (SPL + ATF + OPTEE + U-boot). Depending on the card being locked or not, the rom code will continue the booting process, or will stop it:
The Rom code verifies an image, as the picture below shows:
Note: Other eFuses also need to be programmed to properly implement Secure Boot. For example, the eFuse that disables the JTAG.
After verifying its signature, the ROM code launches the bootloader (SPL then ATF and OPTEE then U-boot).
U-boot should be configured to check the signature of the FIT image if the HAB is activated. The verification of the signature of the FIT image is done by making some calls to the ROM code (through ATF).
U-boot will then behave like the ROM code in the previous step: if the card is locked and the signature is corrupted, it will stop the booting process.
The Fit Image contains at least three elements: the kernel, the device tree and the InitRamFS.
When U-boot checks the signature of the Image: it extracts these elements and launches the kernel.
When the kernel is launched with the InitRamFS, this last one applies DM-verity on the ROOTFS partition, and it gives the kernel the root hash. Finally, the kernel continues booting on the ROOTFS.
These different steps constituted the secure boot for imx8:
The curious reader can find more documentation about HAB implementation on internet, this second part of the article was not meant to explain the whole HAB details, but only to show the relationship between secure boot and the hardware.
Ask your questions and find solutions for your product development
Contact usTristan joined T&S after a background in international relations and freelance experience in project management and production within the video game industry. Drawn by international opportunities and T&S's values, he started as a recruiter, where he gained an understanding of embedded systems and engineering roles. He quickly transitioned to a technical project manager role, developing teams and driving innovative projects, particularly in AI and machine learning. He takes pride in collective achievements with his team, notably the expansion of a key client account. Looking ahead, he aims to continue working on cutting-edge technologies while contributing to the structuring and development of teams.
READ MORETechnology & Strategy has set up a yearly sponsorship program to support projects with a social or environmental impact. Our collaborators were invited to propose organizations to benefit from financial support. This initiative allows the company to consolidate its commitment to CSR, foster solidarity between collaborators and contribute to a more equitable world.
READ MOREEnglab's experimental Industry 5.0 production line, revolutionizes manufacturing by combining human-machine collaboration, AI, and automation to optimize processes, increase flexibility, and improve product quality. To learn more about this project, read the article below.
READ MORE