Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with booting DTS with UEFI Secure Boot enabled #1085

Open
pietrushnic opened this issue Oct 10, 2024 · 2 comments
Open

Problem with booting DTS with UEFI Secure Boot enabled #1085

pietrushnic opened this issue Oct 10, 2024 · 2 comments
Labels
bug Something isn't working DasharoToolsSuite

Comments

@pietrushnic
Copy link

Dasharo version (if applicable)

Dasharo (coreboot+UEFI) v0.9.0-rc2 for Odroid-H4

During training, we tried numerous things with @filipleple and @philipandag:

For example, we put the platform in Setup Mode and enrolled our keys using sbctl:

bash-5.2# sbctl enroll-keys
‼ File is immutable: /sys/firmware/efi/efivars/KEK-8be4df61-93ca-11d2-aa0d-00e098032b8c
‼ File is immutable: /sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f
You need to chattr -i files in efivarfs
bash-5.2# chattr -i /sys/firmware/efi/efivars/*
bash-5.2# sbctl enroll-keys
Enrolling keys to EFI variables...✓
Enrolled keys to the EFI variables!
bash-5.2#
bash-5.2# sbctl enroll-keys
Enrolling keys to EFI variables...✓
Enrolled keys to the EFI variables!
bash-5.2# sbctl status
Installed:      ✓ sbctl is installed
Owner GUID:     00a5425f-7c57-4cb1-8260-2f3f800c3f1e
Setup Mode:     ✓ Disabled
Secure Boot:    ✗ Disabled
Vendor Keys:    none
bash-5.2#


bash-5.2# sbctl verify
failed to find EFI system partition
bash-5.2# ESP_PATH=/boot/EFI/ sbctl verify
Verifying file database and EFI images in /boot/EFI/...
✗ /boot/EFI/BOOT/bootx64.efi is not signed
✗ /boot/EFI/DTS/grubx64.efi is not signed
✗ /boot/EFI/DTS/mmx64.efi is not signed
✗ /boot/EFI/DTS/shimx64.efi is not signed
bash-5.2#



bash-5.2# ESP_PATH=/boot/EFI/ sbctl status
Installed:      ✓ sbctl is installed
Owner GUID:     00a5425f-7c57-4cb1-8260-2f3f800c3f1e
Setup Mode:     ✓ Disabled
Secure Boot:    ✗ Disabled
Vendor Keys:    none
bash-5.2# ESP_PATH=/boot/EFI/ sbctl verify
Verifying file database and EFI images in /boot/EFI/...
✓ /boot/EFI/DTS/grubx64.efi is signed
✓ /boot/EFI/DTS/mmx64.efi is signed
✓ /boot/EFI/DTS/shimx64.efi is signed
✓ /boot/EFI/BOOT/bootx64.efi is signed
bash-5.2# ESP_PATH=/boot/EFI/ sbctl list-files
/boot/EFI/DTS/shimx64.efi
Signed:         ✓ Signed

/boot/EFI/BOOT/bootx64.efi
Signed:         ✓ Signed

/boot/EFI/DTS/grubx64.efi
Signed:         ✓ Signed

/boot/EFI/DTS/mmx64.efi
Signed:         ✓ Signed

bash-5.2#

Version v2.0.0 causes this:

  Booting `boot'

error: shim_lock protocol not found.

Press any key to continue...

We were able to run shim first with engineering version we received internally, but we still had problems:

/------------------------------------------------------------------------------\
|                                    ERROR                                     |
|                                                                              |
|                Verification failed: (0x1A) Security Violation                |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                     /----\                                   |
|                                     | OK |                                   |
|                                     \----/                                   |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
\------------------------------------------------------------------------------/
04/05/2011  23:00          13,218,816  bzImage
04/05/2011  23:00 <DIR>         2,048  EFI
04/05/2011  23:00             174,144  libcom32.c32
04/05/2011  23:00              22,836  libutil.c32
04/05/2011  23:00                 146  syslinux.cfg
04/05/2011  23:00              27,052  vesamenu.c32
          5 File(s)  13,442,994 bytes
          1 Dir(s)
FS0:\> cd EFI
FS0:\EFI\> ls
Directory of: FS0:\EFI\
04/05/2011  23:00 <DIR>         2,048  .
04/05/2011  23:00 <DIR>             0  ..
04/05/2011  23:00 <DIR>         2,048  BOOT
04/05/2011  23:00 <DIR>         2,048  DTS
          0 File(s)           0 bytes
          4 Dir(s)
FS0:\EFI\> cd DTS
FS0:\EFI\DTS\> ls
Directory of: FS0:\EFI\DTS\
04/05/2011  23:00 <DIR>         2,048  .
04/05/2011  23:00 <DIR>         2,048  ..
10/10/2024  13:47             657,528  grubx64.efi
10/10/2024  13:48             846,312  mmx64.efi
10/10/2024  13:48             938,320  shimx64.efi
          3 File(s)   2,442,160 bytes
          2 Dir(s)
FS0:\EFI\DTS\> shimx64.efi
bash-5.2# mokutil --disable-validation
password length: 8~16
input password:
password should be 8~16 characters
input password:
password should be 8~16 characters
input password:
password should be 8~16 characters
Abort
bash-5.2# mokutil --list-enrolled
bash-5.2# mokutil --sb-state
SecureBoot disabled
bash-5.2# mokutil --disable-validation
password length: 8~16
input password:







/------------------------------------------------------------------------------\
|                                  Select Key                                  |
|                                                                              |
|           The selected key will be enrolled into the MOK database            |
|     This means any binaries signed with it will be run without prompting     |
|        Remember to make sure it is a genuine key before Enrolling it         |
|                                                                              |
|                                                                              |
|                                                                              |
|                                    /------\                                  |
|                                    | ../  |                                  |
|                                    | PK/  |                                  |
|                                    | KEK/ |                                  |
|                                    | db/  |                                  |
|                                    \------/                                  |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
\------------------------------------------------------------------------------/
Failed to load image: Security Policy Violation





/------------------------------------------------------------------------------\
|                              Unsupported Format                              |
|                                                                              |
|          Only DER encoded certificate (*.cer/der/crt) is supported           |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                     /----\                                   |
|                                     | OK |                                   |
|                                     \----/                                   |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
|                                                                              |
\------------------------------------------------------------------------------/
Failed to load image: Security Policy Violation

We need the correct procedure to make DTS work with UEFI Secure Boot. We did that in the past for embedded devices with Zarhus, so this should be possible, especially when we control PK.

@artur-rs artur-rs added bug Something isn't working DasharoToolsSuite labels Oct 16, 2024
@m-iwanicki
Copy link

m-iwanicki commented Oct 17, 2024

DTS built from this branch and yml file should work: https://github.com/Dasharo/meta-dts/blob/ost2-custom/kas-ost2.yml

Tested on:

  • QEMU, OSFV main branch - works

  • QEMU, OSFV develop branch - doesn't work, problem with writing efi variables

    sbctl enroll-keys --yes-this-might-brick-my-machine
    Enrolling keys to EFI variables...✗
    couldn't sync keys: couldn't write efi variable: write /sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f: input/output error
    
  • ODROID-H4+, AMI ADLN-H4_B1.0 - works

Below are commands and outputs used during verification

bash-5.2# export ESP_PATH=/boot/EFI

bash-5.2# sbctl create-keys
Created Owner UUID 5ea93056-a548-4c03-965b-a44bf6009e1f
Creating secure boot keys...✓
Secure boot keys created!

bash-5.2# sbctl enroll-keys --yes-this-might-brick-my-machine
Enrolling keys to EFI variables...✓
Enrolled keys to the EFI variables!

bash-5.2# sbctl status
Installed:      ✓ sbctl is installed
Owner GUID:     5ea93056-a548-4c03-965b-a44bf6009e1f
Setup Mode:     ✓ Disabled
Secure Boot:    ✗ Disabled
Vendor Keys:    none

bash-5.2# sbctl verify
Verifying file database and EFI images in /boot/EFI...
✗ /boot/EFI/BOOT/Hash2DxeCrypto.efi is not signed
✗ /boot/EFI/BOOT/Pkcs7VerifyDxe.efi is not signed
✗ /boot/EFI/BOOT/SELoaderx64.efi is not signed
✗ /boot/EFI/BOOT/bootx64.efi is not signed
✗ /boot/EFI/BOOT/grubx64.efi is not signed
✗ /boot/EFI/BOOT/mmx64.efi is not signed

bash-5.2# find /boot/EFI/BOOT/ -name "*.efi" -exec sbctl sign {} \;
✓ Signed /boot/EFI/BOOT/bootx64.efi
✓ Signed /boot/EFI/BOOT/grubx64.efi
✓ Signed /boot/EFI/BOOT/SELoaderx64.efi
✓ Signed /boot/EFI/BOOT/mmx64.efi
✓ Signed /boot/EFI/BOOT/Pkcs7VerifyDxe.efi
✓ Signed /boot/EFI/BOOT/Hash2DxeCrypto.efi


bash-5.2# sbctl verify
Verifying file database and EFI images in /boot/EFI...
✓ /boot/EFI/BOOT/Hash2DxeCrypto.efi is signed
✓ /boot/EFI/BOOT/Pkcs7VerifyDxe.efi is signed
✓ /boot/EFI/BOOT/SELoaderx64.efi is signed
✓ /boot/EFI/BOOT/bootx64.efi is signed
✓ /boot/EFI/BOOT/grubx64.efi is signed
✓ /boot/EFI/BOOT/mmx64.efi is signed

bash-5.2# ls /boot/EFI/BOOT/
SELoaderx64.efi  bootx64.efi  grub.cfg  grubenv  grubx64.efi  mmx64.efi  x86_64-efi

bash-5.2# selsign --key /var/lib/sbctl/keys/db/db.key --cert /var/lib/sbctl/keys/db/db.pem /boot/EFI/BOOT/grub.cfg
SELoader signing tool
Copyright (c) 2017, Lans Zhang <[email protected]>
Version: 0.3.2+giteb3a5927dd18e166014cf1e2eb6e9e461cf973fb
Build Machine: @Linux 1fa4d3536335 6.6.41 #1-NixOS SMP PREEMPT_DYNAMIC Thu Jul 18 11:21:27 UTC 2024 x86_64 GNU/Linux
Wed Oct 16 21:50:27 UTC 2024: [INFO] signaturelet SELoader registered
Wed Oct 16 21:50:27 UTC 2024: [INFO] SELoader PKCS#7 attached signature (signed content 93-byte) generated

bash-5.2# ls /boot/EFI/BOOT/
SELoaderx64.efi  bootx64.efi  grub.cfg  grub.cfg.p7b  grubenv  grubx64.efi  mmx64.efi  x86_64-efi

bash-5.2# selsign --key /var/lib/sbctl/keys/db/db.key --cert /var/lib/sbctl/keys/db/db.pem /boot/bzImage
SELoader signing tool
Copyright (c) 2017, Lans Zhang <[email protected]>
Version: 0.3.2+giteb3a5927dd18e166014cf1e2eb6e9e461cf973fb
Build Machine: @Linux 1fa4d3536335 6.6.41 #1-NixOS SMP PREEMPT_DYNAMIC Thu Jul 18 11:21:27 UTC 2024 x86_64 GNU/Linux
Wed Oct 16 21:52:36 UTC 2024: [INFO] signaturelet SELoader registered
Wed Oct 16 21:52:36 UTC 2024: [INFO] SELoader PKCS#7 attached signature (signed content 93-byte) generated

bash-5.2# ls /boot/
EFI  bzImage  bzImage.p7b  ldlinux.c32  ldlinux.sys  libcom32.c32  libutil.c32  syslinux.cfg  vesamenu.c32

After rebooting and enabling Secure Boot:

SELoader 0.4.6+git8b90f76a8df51d9020e67824026556434f407086 launched
Preparing to load grubx64.efi ...
error: no such device: ((hd0,msdos1)/EFI/BOOT)/EFI/BOOT/grub.cfg.
PKCS#7 Verify Protocol loaded
EFI Hash2 Protocol loaded
The file \EFI\BOOT\grub.cfg loaded with the exit code 0x0

(...)

bash-5.2# sbctl status
Installed:      ✓ sbctl is installed
Owner GUID:     09ce4785-0c3f-44c4-b94d-b04baa92a6a1
Setup Mode:     ✓ Disabled
Secure Boot:    ✓ Enabled
Vendor Keys:    none

bash-5.2# dmesg | grep -i secure
[    0.011341] Secure boot enabled

@pietrushnic
Copy link
Author

We should be interested in making DTS work on Dasharo with UEFI Secure Boot enabled. Even more, DTS should enforce checking the signatures of all modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working DasharoToolsSuite
Projects
None yet
Development

No branches or pull requests

3 participants