Blame SOURCES/0239-kern-efi-sb-Reject-non-kernel-files-in-the-shim_lock.patch

e28c09
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
e28c09
From: Julian Andres Klode <julian.klode@canonical.com>
e28c09
Date: Thu, 2 Dec 2021 15:03:53 +0100
e28c09
Subject: [PATCH] kern/efi/sb: Reject non-kernel files in the shim_lock
e28c09
 verifier
e28c09
e28c09
We must not allow other verifiers to pass things like the GRUB modules.
e28c09
Instead of maintaining a blocklist, maintain an allowlist of things
e28c09
that we do not care about.
e28c09
e28c09
This allowlist really should be made reusable, and shared by the
e28c09
lockdown verifier, but this is the minimal patch addressing
e28c09
security concerns where the TPM verifier was able to mark modules
e28c09
as verified (or the OpenPGP verifier for that matter), when it
e28c09
should not do so on shim-powered secure boot systems.
e28c09
e28c09
Fixes: CVE-2022-28735
e28c09
e28c09
Signed-off-by: Julian Andres Klode <julian.klode@canonical.com>
e28c09
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
e28c09
(cherry picked from commit fa61ad69861c1cb3f68bf853d78fae7fd93986a0)
e28c09
(cherry picked from commit f418191e01b38a635319a26925cf345523d4440c)
e28c09
---
e28c09
 grub-core/kern/efi/sb.c | 39 ++++++++++++++++++++++++++++++++++++---
e28c09
 include/grub/verify.h   |  1 +
e28c09
 2 files changed, 37 insertions(+), 3 deletions(-)
e28c09
e28c09
diff --git a/grub-core/kern/efi/sb.c b/grub-core/kern/efi/sb.c
e28c09
index c52ec6226a..89c4bb3fd1 100644
e28c09
--- a/grub-core/kern/efi/sb.c
e28c09
+++ b/grub-core/kern/efi/sb.c
e28c09
@@ -119,10 +119,11 @@ shim_lock_verifier_init (grub_file_t io __attribute__ ((unused)),
e28c09
 			 void **context __attribute__ ((unused)),
e28c09
 			 enum grub_verify_flags *flags)
e28c09
 {
e28c09
-  *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION;
e28c09
+  *flags = GRUB_VERIFY_FLAGS_NONE;
e28c09
 
e28c09
   switch (type & GRUB_FILE_TYPE_MASK)
e28c09
     {
e28c09
+    /* Files we check. */
e28c09
     case GRUB_FILE_TYPE_LINUX_KERNEL:
e28c09
     case GRUB_FILE_TYPE_MULTIBOOT_KERNEL:
e28c09
     case GRUB_FILE_TYPE_BSD_KERNEL:
e28c09
@@ -130,11 +131,43 @@ shim_lock_verifier_init (grub_file_t io __attribute__ ((unused)),
e28c09
     case GRUB_FILE_TYPE_PLAN9_KERNEL:
e28c09
     case GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE:
e28c09
       *flags = GRUB_VERIFY_FLAGS_SINGLE_CHUNK;
e28c09
+      return GRUB_ERR_NONE;
e28c09
 
e28c09
-      /* Fall through. */
e28c09
+    /* Files that do not affect secureboot state. */
e28c09
+    case GRUB_FILE_TYPE_NONE:
e28c09
+    case GRUB_FILE_TYPE_LOOPBACK:
e28c09
+    case GRUB_FILE_TYPE_LINUX_INITRD:
e28c09
+    case GRUB_FILE_TYPE_OPENBSD_RAMDISK:
e28c09
+    case GRUB_FILE_TYPE_XNU_RAMDISK:
e28c09
+    case GRUB_FILE_TYPE_SIGNATURE:
e28c09
+    case GRUB_FILE_TYPE_PUBLIC_KEY:
e28c09
+    case GRUB_FILE_TYPE_PUBLIC_KEY_TRUST:
e28c09
+    case GRUB_FILE_TYPE_PRINT_BLOCKLIST:
e28c09
+    case GRUB_FILE_TYPE_TESTLOAD:
e28c09
+    case GRUB_FILE_TYPE_GET_SIZE:
e28c09
+    case GRUB_FILE_TYPE_FONT:
e28c09
+    case GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY:
e28c09
+    case GRUB_FILE_TYPE_CAT:
e28c09
+    case GRUB_FILE_TYPE_HEXCAT:
e28c09
+    case GRUB_FILE_TYPE_CMP:
e28c09
+    case GRUB_FILE_TYPE_HASHLIST:
e28c09
+    case GRUB_FILE_TYPE_TO_HASH:
e28c09
+    case GRUB_FILE_TYPE_KEYBOARD_LAYOUT:
e28c09
+    case GRUB_FILE_TYPE_PIXMAP:
e28c09
+    case GRUB_FILE_TYPE_GRUB_MODULE_LIST:
e28c09
+    case GRUB_FILE_TYPE_CONFIG:
e28c09
+    case GRUB_FILE_TYPE_THEME:
e28c09
+    case GRUB_FILE_TYPE_GETTEXT_CATALOG:
e28c09
+    case GRUB_FILE_TYPE_FS_SEARCH:
e28c09
+    case GRUB_FILE_TYPE_LOADENV:
e28c09
+    case GRUB_FILE_TYPE_SAVEENV:
e28c09
+    case GRUB_FILE_TYPE_VERIFY_SIGNATURE:
e28c09
+      *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION;
e28c09
+      return GRUB_ERR_NONE;
e28c09
 
e28c09
+    /* Other files. */
e28c09
     default:
e28c09
-      return GRUB_ERR_NONE;
e28c09
+      return grub_error (GRUB_ERR_ACCESS_DENIED, N_("prohibited by secure boot policy"));
e28c09
     }
e28c09
 }
e28c09
 
e28c09
diff --git a/include/grub/verify.h b/include/grub/verify.h
e28c09
index cd129c398f..672ae16924 100644
e28c09
--- a/include/grub/verify.h
e28c09
+++ b/include/grub/verify.h
e28c09
@@ -24,6 +24,7 @@
e28c09
 
e28c09
 enum grub_verify_flags
e28c09
   {
e28c09
+    GRUB_VERIFY_FLAGS_NONE		= 0,
e28c09
     GRUB_VERIFY_FLAGS_SKIP_VERIFICATION	= 1,
e28c09
     GRUB_VERIFY_FLAGS_SINGLE_CHUNK	= 2,
e28c09
     /* Defer verification to another authority. */