Blame SOURCES/0208-grub-core-loader-efi-chainloader.c-do-not-validate-c.patch

fd0330
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
fd0330
From: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
fd0330
Date: Fri, 4 Mar 2022 09:31:43 +0100
fd0330
Subject: [PATCH] grub-core/loader/efi/chainloader.c: do not validate
fd0330
 chainloader twice
fd0330
fd0330
On secureboot systems, with shimlock verifier, call to
fd0330
grub_file_open(, GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE) will already
fd0330
pass the chainloader target through shim-lock protocol verify
fd0330
call. And create a TPM measurement. If verification fails,
fd0330
grub_cmd_chainloader will fail at file open time.
fd0330
fd0330
This makes previous code paths for negative, and zero return codes
fd0330
from grub_linuxefi_secure_validate unreachable under secureboot. But
fd0330
also breaking measurements compatibility with 2.04+linuxefi codebases,
fd0330
as the chainloader file is passed through shim_lock->verify() twice
fd0330
(via verifier & direct call to grub_linuxefi_secure_validate)
fd0330
extending the PCRs twice.
fd0330
fd0330
This reduces grub_loader options to perform
fd0330
grub_secureboot_chainloader when secureboot is on, and otherwise
fd0330
attempt grub_chainloader_boot.
fd0330
fd0330
It means that booting with secureboot off, yet still with shim (which
fd0330
always verifies things successfully), will stop choosing
fd0330
grub_secureboot_chainloader, and opting for a more regular
fd0330
loadimage/startimage codepath. If we want to use the
fd0330
grub_secureboot_chainloader codepath in such scenarios we should adapt
fd0330
the code to simply check for shim_lock protocol presence /
fd0330
shim_lock->context() success?! But I am not sure if that is necessary.
fd0330
fd0330
This patch must not be ported to older editions of grub code bases
fd0330
that do not have verifiers framework, or it is not builtin, or
fd0330
shim-lock-verifier is an optional module.
fd0330
fd0330
Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
fd0330
---
fd0330
 grub-core/loader/efi/chainloader.c | 8 ++------
fd0330
 1 file changed, 2 insertions(+), 6 deletions(-)
fd0330
fd0330
diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c
fd0330
index 3af6b12292..644cd2e56f 100644
fd0330
--- a/grub-core/loader/efi/chainloader.c
fd0330
+++ b/grub-core/loader/efi/chainloader.c
fd0330
@@ -906,7 +906,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
fd0330
   grub_efi_device_path_t *dp = 0;
fd0330
   char *filename;
fd0330
   void *boot_image = 0;
fd0330
-  int rc;
fd0330
 
fd0330
   if (argc == 0)
fd0330
     return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected"));
fd0330
@@ -1082,9 +1081,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
fd0330
       orig_dev = 0;
fd0330
     }
fd0330
 
fd0330
-  rc = grub_linuxefi_secure_validate((void *)(unsigned long)address, fsize);
fd0330
-  grub_dprintf ("chain", "linuxefi_secure_validate: %d\n", rc);
fd0330
-  if (rc > 0)
fd0330
+  if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
fd0330
     {
fd0330
       grub_file_close (file);
fd0330
       grub_device_close (dev);
fd0330
@@ -1092,7 +1089,7 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
fd0330
 		       grub_secureboot_chainloader_unload, 0);
fd0330
       return 0;
fd0330
     }
fd0330
-  else if (rc == 0)
fd0330
+  else
fd0330
     {
fd0330
       grub_load_and_start_image(boot_image);
fd0330
       grub_file_close (file);
fd0330
@@ -1101,7 +1098,6 @@ grub_cmd_chainloader (grub_command_t cmd __attribute__ ((unused)),
fd0330
 
fd0330
       return 0;
fd0330
     }
fd0330
-  // -1 fall-through to fail
fd0330
 
fd0330
 fail:
fd0330
   if (orig_dev)