Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | From 6fe755c5c07bb386fda58306bfd19e4a1c974c53 Mon Sep 17 00:00:00 2001 |
| 2 | From: Julian Andres Klode <julian.klode@canonical.com> |
| 3 | Date: Thu, 2 Dec 2021 15:03:53 +0100 |
| 4 | Subject: [PATCH] kern/efi/sb: Reject non-kernel files in the shim_lock |
| 5 | verifier |
| 6 | |
| 7 | We must not allow other verifiers to pass things like the GRUB modules. |
| 8 | Instead of maintaining a blocklist, maintain an allowlist of things |
| 9 | that we do not care about. |
| 10 | |
| 11 | This allowlist really should be made reusable, and shared by the |
| 12 | lockdown verifier, but this is the minimal patch addressing |
| 13 | security concerns where the TPM verifier was able to mark modules |
| 14 | as verified (or the OpenPGP verifier for that matter), when it |
| 15 | should not do so on shim-powered secure boot systems. |
| 16 | |
| 17 | Fixes: CVE-2022-28735 |
| 18 | |
| 19 | Signed-off-by: Julian Andres Klode <julian.klode@canonical.com> |
| 20 | Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> |
| 21 | |
| 22 | Upstream-Status: Backport |
| 23 | CVE:CVE-2022-28735 |
| 24 | |
| 25 | Reference to upstream patch: |
| 26 | https://git.savannah.gnu.org/cgit/grub.git/commit/?id=6fe755c5c07bb386fda58306bfd19e4a1c974c53 |
| 27 | |
| 28 | Signed-off-by: Yongxin Liu <yongxin.liu@windriver.com> |
| 29 | --- |
| 30 | grub-core/kern/efi/sb.c | 39 ++++++++++++++++++++++++++++++++++++--- |
| 31 | include/grub/verify.h | 1 + |
| 32 | 2 files changed, 37 insertions(+), 3 deletions(-) |
| 33 | |
| 34 | diff --git a/grub-core/kern/efi/sb.c b/grub-core/kern/efi/sb.c |
| 35 | index c52ec6226..89c4bb3fd 100644 |
| 36 | --- a/grub-core/kern/efi/sb.c |
| 37 | +++ b/grub-core/kern/efi/sb.c |
| 38 | @@ -119,10 +119,11 @@ shim_lock_verifier_init (grub_file_t io __attribute__ ((unused)), |
| 39 | void **context __attribute__ ((unused)), |
| 40 | enum grub_verify_flags *flags) |
| 41 | { |
| 42 | - *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION; |
| 43 | + *flags = GRUB_VERIFY_FLAGS_NONE; |
| 44 | |
| 45 | switch (type & GRUB_FILE_TYPE_MASK) |
| 46 | { |
| 47 | + /* Files we check. */ |
| 48 | case GRUB_FILE_TYPE_LINUX_KERNEL: |
| 49 | case GRUB_FILE_TYPE_MULTIBOOT_KERNEL: |
| 50 | case GRUB_FILE_TYPE_BSD_KERNEL: |
| 51 | @@ -130,11 +131,43 @@ shim_lock_verifier_init (grub_file_t io __attribute__ ((unused)), |
| 52 | case GRUB_FILE_TYPE_PLAN9_KERNEL: |
| 53 | case GRUB_FILE_TYPE_EFI_CHAINLOADED_IMAGE: |
| 54 | *flags = GRUB_VERIFY_FLAGS_SINGLE_CHUNK; |
| 55 | + return GRUB_ERR_NONE; |
| 56 | |
| 57 | - /* Fall through. */ |
| 58 | + /* Files that do not affect secureboot state. */ |
| 59 | + case GRUB_FILE_TYPE_NONE: |
| 60 | + case GRUB_FILE_TYPE_LOOPBACK: |
| 61 | + case GRUB_FILE_TYPE_LINUX_INITRD: |
| 62 | + case GRUB_FILE_TYPE_OPENBSD_RAMDISK: |
| 63 | + case GRUB_FILE_TYPE_XNU_RAMDISK: |
| 64 | + case GRUB_FILE_TYPE_SIGNATURE: |
| 65 | + case GRUB_FILE_TYPE_PUBLIC_KEY: |
| 66 | + case GRUB_FILE_TYPE_PUBLIC_KEY_TRUST: |
| 67 | + case GRUB_FILE_TYPE_PRINT_BLOCKLIST: |
| 68 | + case GRUB_FILE_TYPE_TESTLOAD: |
| 69 | + case GRUB_FILE_TYPE_GET_SIZE: |
| 70 | + case GRUB_FILE_TYPE_FONT: |
| 71 | + case GRUB_FILE_TYPE_ZFS_ENCRYPTION_KEY: |
| 72 | + case GRUB_FILE_TYPE_CAT: |
| 73 | + case GRUB_FILE_TYPE_HEXCAT: |
| 74 | + case GRUB_FILE_TYPE_CMP: |
| 75 | + case GRUB_FILE_TYPE_HASHLIST: |
| 76 | + case GRUB_FILE_TYPE_TO_HASH: |
| 77 | + case GRUB_FILE_TYPE_KEYBOARD_LAYOUT: |
| 78 | + case GRUB_FILE_TYPE_PIXMAP: |
| 79 | + case GRUB_FILE_TYPE_GRUB_MODULE_LIST: |
| 80 | + case GRUB_FILE_TYPE_CONFIG: |
| 81 | + case GRUB_FILE_TYPE_THEME: |
| 82 | + case GRUB_FILE_TYPE_GETTEXT_CATALOG: |
| 83 | + case GRUB_FILE_TYPE_FS_SEARCH: |
| 84 | + case GRUB_FILE_TYPE_LOADENV: |
| 85 | + case GRUB_FILE_TYPE_SAVEENV: |
| 86 | + case GRUB_FILE_TYPE_VERIFY_SIGNATURE: |
| 87 | + *flags = GRUB_VERIFY_FLAGS_SKIP_VERIFICATION; |
| 88 | + return GRUB_ERR_NONE; |
| 89 | |
| 90 | + /* Other files. */ |
| 91 | default: |
| 92 | - return GRUB_ERR_NONE; |
| 93 | + return grub_error (GRUB_ERR_ACCESS_DENIED, N_("prohibited by secure boot policy")); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | diff --git a/include/grub/verify.h b/include/grub/verify.h |
| 98 | index cd129c398..672ae1692 100644 |
| 99 | --- a/include/grub/verify.h |
| 100 | +++ b/include/grub/verify.h |
| 101 | @@ -24,6 +24,7 @@ |
| 102 | |
| 103 | enum grub_verify_flags |
| 104 | { |
| 105 | + GRUB_VERIFY_FLAGS_NONE = 0, |
| 106 | GRUB_VERIFY_FLAGS_SKIP_VERIFICATION = 1, |
| 107 | GRUB_VERIFY_FLAGS_SINGLE_CHUNK = 2, |
| 108 | /* Defer verification to another authority. */ |
| 109 | -- |
| 110 | 2.34.1 |
| 111 | |