Skip to contentSkip to conversation

u-boot on raspberry pi with secure boot

DISCUSSION Jonas Kvinge 4 participants 6 messages Aug 19, 2024 – Aug 28, 2024

lore
Share & tools
lore
#0 lore raw

Hi,

I have a custom installation of openSUSE Tumbleweed which uses u-boot and Grub.
To use secure boot on the RPI, one creates a boot.img containing the kernel and other files which is signed, and the eeprom is locked to only allow booting with this signature.
(https://github.com/raspberrypi/usbboot/blob/master/secure-boot-recovery/README.md
).
Since I'm using u-boot, I'm creating a boot.img containing u-boot.bin instead of the linux kernel and ramdisk.
But then nothing is locking down which kernel can boot, since that's controller by UEFI and Grub. u-boot starts Grub from the UEFI partition, and Grub starts the kernel from a separate /boot partition. And I see no way to change this
I use a 3 partition setup where the partitions are 1. FAT UEFI partition, 2. Linux ext4 /boot partition, 3. Encrypted LUKS ext4 root partition.
I've been looking into
https://trac.gateworks.com/wiki/secure_boot#SecuringtheKernelFDTramdiskviaFITimages
But is that possible to do with my current setup? Can I include grub and the kernel/initrd in the boot.img and make u-boot use that instead of from the UEFI partition?

Jonas

#1 lore raw

Hi Jonas,

Quoted 15 lines · Jonas Kvinge

Hi,

I have a custom installation of openSUSE Tumbleweed which uses u-boot and Grub.
To use secure boot on the RPI, one creates a boot.img containing the kernel and other files which is signed, and the eeprom is locked to only allow booting with this signature.
(https://github.com/raspberrypi/usbboot/blob/master/secure-boot-recovery/README.md
).
Since I'm using u-boot, I'm creating a boot.img containing u-boot.bin instead of the linux kernel and ramdisk.
But then nothing is locking down which kernel can boot, since that's controller by UEFI and Grub. u-boot starts Grub from the UEFI partition, and Grub starts the kernel from a separate /boot partition. And I see no way to change this

Quoted 8 lines

I use a 3 partition setup where the partitions are 1. FAT UEFI partition, 2. Linux ext4 /boot partition, 3. Encrypted LUKS ext4 root partition.
I've been looking into
https://trac.gateworks.com/wiki/secure_boot#SecuringtheKernelFDTramdiskviaFITimages
But is that possible to do with my current setup? Can I include grub and the kernel/initrd in the boot.img and make u-boot use that instead of from the UEFI partition?

I don't know the details of how this is implemented, but the way to solve this is by doing EFI secureboot in U-Boot. The trick is to embed the securebook public key hash into U-Boot, there it will be validated by the bootrom stage and can be trusted to validate the signed kernel EFI.

The kernel would then need to be booted as a "UKI" (refer to the uapi group uki docs), this embeds the kernel, ramdisk, and DTB into a single EFI image which can be signed and verified.

Hopefully this points you in the right direction.

Kind regards,

Quoted 3 lines

Jonas

Signature · 1 line
// Caleb (they/them)
#2 lore raw
Quoted 11 lines · Caleb Connolly

Hi Jonas,

I don't know the details of how this is implemented, but the way to solve this is by doing EFI secureboot in U-Boot. The trick is to embed
the securebook public key hash into U-Boot, there it will be validated
by the bootrom stage and can be trusted to validate the signed kernel EFI.

Quoted 7 lines

The kernel would then need to be booted as a "UKI" (refer to the uapi group uki docs), this embeds the kernel, ramdisk, and DTB into a single
EFI image which can be signed and verified.

Hopefully this points you in the right direction.

Thanks, this got me a bit further, I have managed to produce a UKI using dracut on openSUSE, this is written as /boot/efi/EFI/Linux/linux- 6.10.5-1-default-69b6602716a8442d94a79481993e2ded.efi,
I verified that it works by copying it to /boot/efi/EFI/BOOT/bootaa64.efi.
I've also signed it now following the instructions on
https://github.com/u-boot/u-boot/blob/master/doc/develop/uefi/uefi.rst
So it produced a signed file (/boot/efi/EFI/Linux/linux-6.10.5-1- default-69b6602716a8442d94a79481993e2ded.efi.signed).
So the next step is to restrict booting to this signed efi file. But I'm still not sure how to configure U-Boot to only accept to boot EFI files with my certificate.
I don't see anywhere to configure that in 'make menuconfig', of course, if I copy the files to the UEFI partition, someone could just replace the .auth files.
Do I need to use FIT image like described on
https://trac.gateworks.com/wiki/secure_boot ?
In that case how do I configure the .its file to include the efi file and the certificate instead of the kernel, ramdisk and fdt files described in the wiki?

Jonas

#3 lore raw

Hi Jonas on mobile and on vacation, I'll respond in a week or so. In the meantime https://www.linaro.org/blog/uefi-secureboot-in-u-boot/ this might help.

In sort you have to include the efi keys in the uboot binary.

Cheers
Ilias

Quoted 44 lines · On Wed, Aug 21, 2024, 20:35 Jonas Kvinge <[email protected]> wrote:
Quoted 11 lines · Caleb Connolly

Hi Jonas,

I don't know the details of how this is implemented, but the way to solve this is by doing EFI secureboot in U-Boot. The trick is to embed
the securebook public key hash into U-Boot, there it will be validated
by the bootrom stage and can be trusted to validate the signed kernel EFI.

Quoted 7 lines

The kernel would then need to be booted as a "UKI" (refer to the uapi group uki docs), this embeds the kernel, ramdisk, and DTB into a single
EFI image which can be signed and verified.

Hopefully this points you in the right direction.

Thanks, this got me a bit further, I have managed to produce a UKI using dracut on openSUSE, this is written as /boot/efi/EFI/Linux/linux- 6.10.5-1-default-69b6602716a8442d94a79481993e2ded.efi,
I verified that it works by copying it to /boot/efi/EFI/BOOT/bootaa64.efi.
I've also signed it now following the instructions on
https://github.com/u-boot/u-boot/blob/master/doc/develop/uefi/uefi.rst
So it produced a signed file (/boot/efi/EFI/Linux/linux-6.10.5-1- default-69b6602716a8442d94a79481993e2ded.efi.signed).
So the next step is to restrict booting to this signed efi file. But I'm still not sure how to configure U-Boot to only accept to boot EFI files with my certificate.
I don't see anywhere to configure that in 'make menuconfig', of course, if I copy the files to the UEFI partition, someone could just replace the .auth files.
Do I need to use FIT image like described on
https://trac.gateworks.com/wiki/secure_boot ?
In that case how do I configure the .its file to include the efi file and the certificate instead of the kernel, ramdisk and fdt files described in the wiki?

Jonas

#4 lore raw
In reply to Jonas Kvinge

Hi,
I have produced a signed linux UKI image.

But I need to build u-boot to only allow booting with the signed certificate.

So I need a ubootefi.var for (EFI_VAR_SEED_FILE) according tohttps://github.com/u-boot/u-boot/blob/ee2af844ba1b27b2e959c4e649e4b769fbeb4074/lib/efi_loader/Kconfig#L146

How do I produce this file?

https://lists.denx.de/pipermail/u-boot/2020-December/433925.html

If I type saveenv on the u-boot console, I get "uboot.env", is this the file that's needed?

I've tried to sign the file using the efivar.py script, but I find very little information on this topic, I've found this from the mailinglist:(https://lists.denx.de/pipermail/u-boot/2020-December/433925.html).

Here's what I've tried:

./tools/efivar.py set --infile uboot.env -n db -d secureboot-db.esl -t file
err: invalid magic number: 0x756162006d72613d

I've produced the certificates according to the instructions on
https://github.com/u-boot/u-boot/blob/master/doc/develop/uefi/uefi.rst

Jonas

#5 lore raw
In reply to Jonas Kvinge

Hi Jonas,

Quoted 16 lines · Jonas Kvinge

Hi,

I have a custom installation of openSUSE Tumbleweed which uses u-boot and Grub.
To use secure boot on the RPI, one creates a boot.img containing the kernel and other files which is signed, and the eeprom is locked to only allow booting with this signature.
(https://github.com/raspberrypi/usbboot/blob/master/secure-boot-recovery/README.md
).
Since I'm using u-boot, I'm creating a boot.img containing u-boot.bin instead of the linux kernel and ramdisk.
But then nothing is locking down which kernel can boot, since that's controller by UEFI and Grub. u-boot starts Grub from the UEFI partition, and Grub starts the kernel from a separate /boot partition. And I see no way to change this

Quoted 8 lines

I use a 3 partition setup where the partitions are 1. FAT UEFI partition, 2. Linux ext4 /boot partition, 3. Encrypted LUKS ext4 root partition.
I've been looking into
https://trac.gateworks.com/wiki/secure_boot#SecuringtheKernelFDTramdiskviaFITimages
But is that possible to do with my current setup? Can I include grub and the kernel/initrd in the boot.img and make u-boot use that instead of from the UEFI partition?

It's 'U-Boot', BTW.

I don't fully understand your situation, but you should be able to use FIT as there is an EFI test for it - see test/py/tests/test_efi_capsule/test_capsule_firmware_fit.py

Note that RPI typically uses a private bootloader, so I'm not sure how secure it can actually be.

Regards,
Simon