RFC: ieee1275: link appended-signature enforcement to secure boot
cover RFC: ieee1275: link appended-signature enforcement to secure boot
This patch demonstrates how secure boot on pseries machines could be linked to the appended signature verification I sent earlier.
It's a pretty big hammer at the moment - I am posting it so we can discuss whether this is something that would be acceptable in upstream grub. If it acceptable in theory I'm happy to rework it to be less invasive.
(The rest of this cover letter concerns testing the entire end-to-end setup - signing grub, verifying signatures in grub and enforcing secure boot.)
You can experiement with this using entirely free software.
You need the following trees:
https://github.com/daxtens/qemu branch pseries-secboot
https://github.com/daxtens/SLOF branch ibm,secure-boot
https://github.com/daxtens/grub branch ibm,secure-boot
You also need:
- a key to sign grub, and accompanying DER certificate
- a key to sign linux, and accompanying DER certificate
Both should have keyUsage=digitalSignature and not be CAs.
Lastly you will need a working a ppc64(le) vm.
Then:
- build qemu. You need qemu-system-ppc64.
- use xxd to convert the certificate for verifying grub into a header file, and copy it in to SLOF/lib/libcrypto/certificate.h. It must create variables certificate_der and certificate_der_len.
- build SLOF for qemu (make qemu)
- verify that you can boot your VM with new SLOF and stock grub.
To boot with new SLOF, pass -bios ./SLOF/boot_rom.bin . It should boot with new slof in non-secure (default) mode.
To enable secure boot, add ",secure-boot" to your machine parameter, e.g. "-M pseries,secure-boot". This should now refuse to boot with an error in SLOF.
(Note that the SLOF verfication is a bit lackadaisical, it doesn't
stop you dropping to the all-powerful OF prompt, and it only requires signatures on 32-bit binaries. -kernel vmlinux should still work even in SB mode, for example. I haven't tested netbooting.)
- Build grub in your VM.
- Build the signing key into grub, along with the appendedsig module. The following incantation should give you a working but non-portable grub, assuming you have grub installed on /dev/sda1:
touch empty
sign-file SHA256 grub-signing.key grub-signing-certificate.der \
empty empty.signed
SIG_SIZE=stat -c '%s' empty.signed
echo "Detected signature size: $SIG_SIZE bytes"
rm empty empty.signed
GRUB_MODULES="appendedsig gcry_sha256 all_video boot btrfs cat configfile echo ext2 fat font gfxmenu gfxterm gzio halt hfsplus http iso9660 jpeg loadenv loopback linux lvm mdraid09 mdraid1x minicmd net normal part_apple part_msdos part_gpt password_pbkdf2 png reboot regexp search search_fs_uuid search_fs_file search_label serial sleep syslinuxcfg test tftp video xfs"
./grub-install --appended-signature-size $SIG_SIZE --modules="$GRUB_MODULES" \
-d ./grub-core/ /dev/sda1 -x linux-signing-certificate.der
cp /boot/grub/powerpc-ieee1275/core.elf core.elf truncate -s -$SIG_SIZE core.elf
sign-file SHA256 grub-signing.key grub-signing-certificate.der \
core.elf core.elf.signed
dd if=core.elf.signed of=/dev/sda1
- Sign your kernel, e.g.:
sign-file SHA256 linux-signing.key linux-signing-certificate.der \
/boot/vmlinux /boot/vmlinux.signed
- You should now be able to boot with new SLOF and qemu in secure-boot mode.
Daniel Axtens (1):
ieee1275: link appended-signature enforcement to /ibm,secure-boot
grub-core/commands/appendedsig/appendedsig.c | 44 +++++++++++++++----- grub-core/kern/ieee1275/init.c | 26 ++++++++++++ 2 files changed, 60 insertions(+), 10 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/1 ieee1275: link appended-signature enforcement to /ibm, secure-boot
If the 'ibm,secure-boot' property of the root node is 2 or greater, require that the kernel pass appended-signature verification.
Do not consider the presence of a certificate to enforce verification.
--- grub-core/commands/appendedsig/appendedsig.c | 44 +++++++++++++++----- grub-core/kern/ieee1275/init.c | 26 ++++++++++++ 2 files changed, 60 insertions(+), 10 deletions(-)
grub-core/commands/appendedsig/appendedsig.c +34 -10
@@ -95,10 +95,24 @@ static char * grub_env_write_sec (struct grub_env_var *var __attribute__((unused)), const char *val) { +if (check_sigs ==2 ) +return grub_strdup ("forced" ); check_sigs = (*val =='1' ) || (*val =='e' );return grub_strdup (check_sigs ?"enforce" :"no" ); } +static const char * +grub_env_read_sec (struct grub_env_var *var __attribute__ ((unused)), +const char *val __attribute__ ((unused))) +{ +if (check_sigs ==2 ) +return "forced" ; +else if (check_sigs ==1 ) +return "enforce" ; +else +return "no" ; +} +static grub_err_t read_cert_from_file (grub_file_t f,struct x509_certificate *certificate) {
@@ -552,14 +566,20 @@ GRUB_MOD_INIT (appendedsig) val =grub_env_get ("check_appended_signatures" );grub_dprintf ("appendedsig" ,"check_appended_signatures='%s'\n" , val); -if (val && (val[0 ] =='1' || val[0 ] =='e' )) - check_sigs =1 ; -else - check_sigs =0 ; +if (val) + { +if (val[0 ] =='2' || val[0 ] =='f' ) + check_sigs =2 ; +else if (val[0 ] =='1' || val[0 ] =='e' ) + check_sigs =1 ; +else + check_sigs =0 ; + } grub_trusted_key =NULL ; -grub_register_variable_hook ("check_appended_signatures" ,0 , +grub_register_variable_hook ("check_appended_signatures" , + grub_env_read_sec, grub_env_write_sec);grub_env_export ("check_appended_signatures" );
@@ -603,11 +623,15 @@ GRUB_MOD_INIT (appendedsig) grub_trusted_key = pk; } -if (!val || val[0 ] =='\0' ) - { -grub_env_set ("check_appended_signatures" , - grub_trusted_key ?"enforce" :"no" ); - } +/* +* When controlled by ibm,secure-boot, we don't want the presence of +* a certificate to enforce secure boot. +* if (!val || val[0] == '\0') +* { +* grub_env_set ("check_appended_signatures", +* grub_trusted_key ? "enforce" : "no"); +* } +*/ cmd_trust = grub_register_command ("trust_certificate", grub_cmd_trust,
grub-core/kern/ieee1275/init.c +26 -0
@@ -371,6 +371,30 @@ grub_parse_cmdline (void) } } +static void +grub_get_ieee1275_secure_boot (void ) +{ +grub_ieee1275_phandle_t root; +int rc; +grub_uint32_t is_sb; + +grub_ieee1275_finddevice ("/" , &root); + + rc =grub_ieee1275_get_integer_property (root,"ibm,secure-boot" , &is_sb, +sizeof (is_sb),0 ); + +/* ibm,secure-boot: +* 0 - disabled +* 1 - audit +* 2 - enforce +* 3 - enforce + OS-specific behaviour +* +* We only support enforce. +*/ +if (rc >=0 && is_sb >=2 ) +grub_env_set ("check_appended_signatures" ,"forced" ); +} +grub_addr_t grub_modbase;void
@@ -396,6 +420,8 @@ grub_machine_init (void)#else grub_install_get_time_ms (grub_rtc_get_time_ms);#endif + +grub_get_ieee1275_secure_boot (); }void
Signature · 1 line
2.25.1