90dacf5
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
90dacf5
From: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
90dacf5
Date: Thu, 3 Mar 2022 13:10:56 +0100
90dacf5
Subject: [PATCH] grub-core/loader/i386/efi/linux.c: do not validate kernels
90dacf5
 twice
90dacf5
90dacf5
On codebases that have shim-lock-verifier built into the grub core
90dacf5
(like 2.06 upstream), shim-lock-verifier is in enforcing mode when
90dacf5
booted with secureboot. It means that grub_cmd_linux() command
90dacf5
attempts to perform shim validate upon opening linux kernel image,
90dacf5
including kernel measurement. And the verifier correctly returns file
90dacf5
open error when shim validate protocol is not present or shim fails to
90dacf5
validate the kernel.
90dacf5
90dacf5
This makes the call to grub_linuxefi_secure_validate() redundant, but
90dacf5
also harmful. As validating the kernel image twice, extends the PCRs
90dacf5
with the same measurement twice. Which breaks existing sealing
90dacf5
policies when upgrading from grub2.04+rhboot+sb+linuxefi to
90dacf5
grub2.06+rhboot+sb+linuxefi builds. It is also incorrect to measure
90dacf5
the kernel twice.
90dacf5
90dacf5
This patch must not be ported to older editions of grub code bases
90dacf5
that do not have verifiers framework, or it is not builtin, or
90dacf5
shim-lock-verifier is an optional module.
90dacf5
90dacf5
This patch is tested to ensure that unsigned kernels are not possible
90dacf5
to boot in secureboot mode when shim rejects kernel, or shim protocol
90dacf5
is missing, and that the measurements become stable once again. The
90dacf5
above also ensures that CVE-2020-15705 is not reintroduced.
90dacf5
90dacf5
Signed-off-by: Dimitri John Ledkov <dimitri.ledkov@canonical.com>
90dacf5
---
90dacf5
 grub-core/loader/i386/efi/linux.c | 13 -------------
90dacf5
 1 file changed, 13 deletions(-)
90dacf5
90dacf5
diff --git a/grub-core/loader/i386/efi/linux.c b/grub-core/loader/i386/efi/linux.c
e622855
index 3cf0f9b330..941df6400b 100644
90dacf5
--- a/grub-core/loader/i386/efi/linux.c
90dacf5
+++ b/grub-core/loader/i386/efi/linux.c
90dacf5
@@ -30,7 +30,6 @@
90dacf5
 #include <grub/cpu/efi/memory.h>
90dacf5
 #include <grub/tpm.h>
90dacf5
 #include <grub/safemath.h>
90dacf5
-#include <grub/efi/sb.h>
90dacf5
 
90dacf5
 GRUB_MOD_LICENSE ("GPLv3+");
90dacf5
 
90dacf5
@@ -278,7 +277,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
90dacf5
   grub_ssize_t start, filelen;
90dacf5
   void *kernel = NULL;
90dacf5
   int setup_header_end_offset;
90dacf5
-  int rc;
90dacf5
 
90dacf5
   grub_dl_ref (my_mod);
90dacf5
 
90dacf5
@@ -308,17 +306,6 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)),
90dacf5
       goto fail;
90dacf5
     }
90dacf5
 
90dacf5
-  if (grub_efi_get_secureboot () == GRUB_EFI_SECUREBOOT_MODE_ENABLED)
90dacf5
-    {
90dacf5
-      rc = grub_linuxefi_secure_validate (kernel, filelen);
90dacf5
-      if (rc <= 0)
90dacf5
-	{
90dacf5
-	  grub_error (GRUB_ERR_INVALID_COMMAND,
90dacf5
-		      N_("%s has invalid signature"), argv[0]);
90dacf5
-	  goto fail;
90dacf5
-	}
90dacf5
-    }
90dacf5
-
90dacf5
   lh = (struct linux_i386_kernel_header *)kernel;
90dacf5
   grub_dprintf ("linux", "original lh is at %p\n", kernel);
90dacf5