diff options
author | Jason Wessel <jason.wessel@windriver.com> | 2019-10-24 14:00:42 -0700 |
---|---|---|
committer | Jia Zhang <zhang.jia@linux.alibaba.com> | 2019-11-08 13:27:23 +0800 |
commit | 01f67e4c7e4cb33acfa5a7a0c3d634cb6489278a (patch) | |
tree | 56f5a9ab8d410ad1f6df44dc63a58e55579f0ee8 | |
parent | e19748f11e061fff827ecfa0fc88af822e6f9ab4 (diff) | |
download | meta-secure-core-01f67e4c7e4cb33acfa5a7a0c3d634cb6489278a.tar.gz |
grub: Make SELoader optional and add gpg verify support
Allow SELoader to be an optional component for secure boot
verification. The GPG_SIGN_VERIFY variable was added to control the
ability to have grub perform all of the verification of the loaded
files using a public key which gets built into grub at the time that
mkimage is run.
It is not intended that GPG_SIGN_VERIFY and UEFI_SELOADER would both
be set to "1". While this configuration could work, it makes very
little sense to use the system that way.
Also enabled is the tftp feature for grub as a builtin. This allows
grub to start from the network when the UEFI is configured to boot off
the network with tftp.
[ Issue: LINUXEXEC-2450 ]
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
5 files changed, 253 insertions, 74 deletions
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi-efi-secure-boot.inc b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi-efi-secure-boot.inc index 71a2bc1..6d1d284 100644 --- a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi-efi-secure-boot.inc +++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi-efi-secure-boot.inc | |||
@@ -1,10 +1,16 @@ | |||
1 | DEPENDS += "openssl-native" | 1 | DEPENDS += "openssl-native" |
2 | FILESEXTRAPATHS_prepend := "${THISDIR}/grub-efi:" | 2 | FILESEXTRAPATHS_prepend := "${THISDIR}/grub-efi:" |
3 | 3 | ||
4 | GRUB_SIGN_VERIFY_STRICT ?= "1" | ||
5 | |||
4 | EXTRA_SRC_URI = "\ | 6 | EXTRA_SRC_URI = "\ |
5 | ${@'file://efi-secure-boot.inc file://password.inc' if d.getVar('UEFI_SB', True) == '1' else ''} \ | 7 | ${@'file://efi-secure-boot.inc file://password.inc' if d.getVar('UEFI_SB', True) == '1' else ''} \ |
6 | " | 8 | " |
7 | 9 | ||
10 | GRUB_MOKVERIFY_PATCH = " \ | ||
11 | file://mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch \ | ||
12 | file://mok2verify-multiboot.patch" | ||
13 | |||
8 | SRC_URI += "\ | 14 | SRC_URI += "\ |
9 | file://0001-pe32.h-add-header-structures-for-TE-and-DOS-executab.patch \ | 15 | file://0001-pe32.h-add-header-structures-for-TE-and-DOS-executab.patch \ |
10 | file://0002-shim-add-needed-data-structures.patch \ | 16 | file://0002-shim-add-needed-data-structures.patch \ |
@@ -18,10 +24,11 @@ SRC_URI += "\ | |||
18 | file://chainloader-Actually-find-the-relocations-correctly-.patch \ | 24 | file://chainloader-Actually-find-the-relocations-correctly-.patch \ |
19 | file://efi-chainloader-implemented-for-32-bit.patch \ | 25 | file://efi-chainloader-implemented-for-32-bit.patch \ |
20 | file://Grub-get-and-set-efi-variables.patch \ | 26 | file://Grub-get-and-set-efi-variables.patch \ |
21 | file://mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch \ | 27 | file://uefi_verify.patch \ |
22 | file://mok2verify-multiboot.patch \ | 28 | file://0001-grub-verify-Add-strict_security-variable.patch \ |
23 | file://grub-efi.cfg \ | 29 | file://grub-efi.cfg \ |
24 | file://boot-menu.inc \ | 30 | file://boot-menu.inc \ |
31 | ${@d.getVar('GRUB_MOKVERIFY_PATCH', True) if d.getVar('UEFI_SELOADER', True) == '1' else ''} \ | ||
25 | ${EXTRA_SRC_URI} \ | 32 | ${EXTRA_SRC_URI} \ |
26 | " | 33 | " |
27 | 34 | ||
@@ -30,8 +37,17 @@ COMPATIBLE_HOST_aarch64 = 'null' | |||
30 | 37 | ||
31 | EFI_BOOT_PATH = "/boot/efi/EFI/BOOT" | 38 | EFI_BOOT_PATH = "/boot/efi/EFI/BOOT" |
32 | 39 | ||
33 | GRUB_BUILDIN_append += " chain ${@'efivar mok2verify password_pbkdf2' \ | 40 | GRUB_SECURE_BOOT_MODULES += "${@'efivar password_pbkdf2 ' if d.getVar('UEFI_SB', True) == '1' else ''}" |
34 | if d.getVar('UEFI_SB', True) == '1' else ''}" | 41 | |
42 | GRUB_SIGNING_MODULES += "${@'pgp gcry_rsa gcry_sha256 gcry_sha512 --pubkey %s ' % d.getVar('GRUB_PUB_KEY', True) \ | ||
43 | if d.getVar('GRUB_SIGN_VERIFY', True) == '1' else ''}" | ||
44 | |||
45 | GRUB_SELOADER_MODULES += "${@'mok2verify ' if d.getVar('UEFI_SELOADER', True) == '1' else ''}" | ||
46 | |||
47 | GRUB_BUILDIN_append += "tftp reboot chain \ | ||
48 | ${GRUB_SECURE_BOOT_MODULES} \ | ||
49 | ${GRUB_SIGNING_MODULES} \ | ||
50 | ${GRUB_SELOADER_MODULES}" | ||
35 | 51 | ||
36 | # For efi_call_foo and efi_shim_exit | 52 | # For efi_call_foo and efi_shim_exit |
37 | CFLAGS_append = " -fno-toplevel-reorder" | 53 | CFLAGS_append = " -fno-toplevel-reorder" |
@@ -59,6 +75,22 @@ python __anonymous () { | |||
59 | d.setVar("GRUB_IMAGE", grubimage) | 75 | d.setVar("GRUB_IMAGE", grubimage) |
60 | } | 76 | } |
61 | 77 | ||
78 | do_compile_append() { | ||
79 | if [ "${GRUB_SIGN_VERIFY}" = "1" -a "${GRUB_SIGN_VERIFY_STRICT}" = "1" ] ; then | ||
80 | cat<<EOF>${WORKDIR}/cfg | ||
81 | insmod verify | ||
82 | set strict_security=1 | ||
83 | search.file (\$cmdpath)/EFI/BOOT/grub.cfg root | ||
84 | set prefix=(\$root)/EFI/BOOT | ||
85 | EOF | ||
86 | else | ||
87 | cat<<EOF>${WORKDIR}/cfg | ||
88 | search.file (\$cmdpath)/EFI/BOOT/grub.cfg root | ||
89 | set prefix=(\$root)/EFI/BOOT | ||
90 | EOF | ||
91 | fi | ||
92 | } | ||
93 | |||
62 | do_compile_append_class-native() { | 94 | do_compile_append_class-native() { |
63 | make grub-editenv | 95 | make grub-editenv |
64 | } | 96 | } |
@@ -97,7 +129,7 @@ do_install_append_class-target() { | |||
97 | grub-editenv "${D}${EFI_BOOT_PATH}/grubenv" create | 129 | grub-editenv "${D}${EFI_BOOT_PATH}/grubenv" create |
98 | 130 | ||
99 | install -d "${D}${EFI_BOOT_PATH}/${GRUB_TARGET}-efi" | 131 | install -d "${D}${EFI_BOOT_PATH}/${GRUB_TARGET}-efi" |
100 | grub-mkimage -p /EFI/BOOT -d "./grub-core" \ | 132 | grub-mkimage -c ../cfg -p /EFI/BOOT -d "./grub-core" \ |
101 | -O "${GRUB_TARGET}-efi" -o "${B}/${GRUB_IMAGE}" \ | 133 | -O "${GRUB_TARGET}-efi" -o "${B}/${GRUB_IMAGE}" \ |
102 | ${GRUB_BUILDIN} | 134 | ${GRUB_BUILDIN} |
103 | 135 | ||
@@ -117,28 +149,29 @@ fakeroot python do_sign_class-target() { | |||
117 | dir = image_dir + efi_boot_path + '/' | 149 | dir = image_dir + efi_boot_path + '/' |
118 | 150 | ||
119 | sb_sign(dir + grub_image, dir + grub_image, d) | 151 | sb_sign(dir + grub_image, dir + grub_image, d) |
120 | uks_sel_sign(dir + 'grub.cfg', d) | 152 | uks_bl_sign(dir + 'grub.cfg', d) |
121 | uks_sel_sign(dir + 'boot-menu.inc', d) | 153 | uks_bl_sign(dir + 'boot-menu.inc', d) |
122 | 154 | ||
123 | if d.getVar('UEFI_SB', True) == "1": | 155 | if d.getVar('UEFI_SB', True) == "1": |
124 | uks_sel_sign(dir + 'efi-secure-boot.inc', d) | 156 | uks_bl_sign(dir + 'efi-secure-boot.inc', d) |
125 | uks_sel_sign(dir + 'password.inc', d) | 157 | uks_bl_sign(dir + 'password.inc', d) |
126 | } | 158 | } |
127 | 159 | ||
128 | python do_sign() { | 160 | python do_sign() { |
129 | } | 161 | } |
130 | addtask sign after do_install before do_deploy do_package | 162 | addtask sign after do_install before do_deploy do_package |
131 | do_sign[prefuncs] += "check_deploy_keys" | 163 | do_sign[prefuncs] += "check_deploy_keys" |
164 | do_sign[prefuncs] += "${@'check_boot_public_key' if d.getVar('GRUB_SIGN_VERIFY', True) == '1' else ''}" | ||
132 | 165 | ||
133 | fakeroot do_chownp7b() { | 166 | fakeroot do_chownboot() { |
134 | chown root:root -R "${D}${EFI_BOOT_PATH}/grub.cfg.p7b" | 167 | chown root:root -R "${D}${EFI_BOOT_PATH}/grub.cfg${SB_FILE_EXT}" |
135 | chown root:root -R "${D}${EFI_BOOT_PATH}/boot-menu.inc.p7b" | 168 | chown root:root -R "${D}${EFI_BOOT_PATH}/boot-menu.inc${SB_FILE_EXT}" |
136 | [ x"${UEFI_SB}" = x"1" ] && { | 169 | [ x"${UEFI_SB}" = x"1" ] && { |
137 | chown root:root -R "${D}${EFI_BOOT_PATH}/efi-secure-boot.inc.p7b" | 170 | chown root:root -R "${D}${EFI_BOOT_PATH}/efi-secure-boot.inc${SB_FILE_EXT}" |
138 | chown root:root -R "${D}${EFI_BOOT_PATH}/password.inc.p7b" | 171 | chown root:root -R "${D}${EFI_BOOT_PATH}/password.inc${SB_FILE_EXT}" |
139 | } | 172 | } |
140 | } | 173 | } |
141 | addtask chownp7b after do_deploy before do_package | 174 | addtask chownboot after do_deploy before do_package |
142 | 175 | ||
143 | # Override the do_deploy() in oe-core. | 176 | # Override the do_deploy() in oe-core. |
144 | do_deploy_class-target() { | 177 | do_deploy_class-target() { |
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0001-grub-verify-Add-strict_security-variable.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0001-grub-verify-Add-strict_security-variable.patch new file mode 100644 index 0000000..11bfe76 --- /dev/null +++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/0001-grub-verify-Add-strict_security-variable.patch | |||
@@ -0,0 +1,102 @@ | |||
1 | From 8a7ad88b4880e25df1f54b80631dc035e1e25662 Mon Sep 17 00:00:00 2001 | ||
2 | From: Jason Wessel <jason.wessel@windriver.com> | ||
3 | Date: Thu, 17 Oct 2019 12:35:01 -0700 | ||
4 | Subject: [PATCH] grub verify: Add strict_security variable | ||
5 | |||
6 | With strict_security set to 1, it is impossible to change the value of | ||
7 | check_signatures. It will also cause grub to reboot instead of | ||
8 | allowing a rescue or grub shell, which could allow an end user to | ||
9 | alter boot arguments or load some other binary. | ||
10 | |||
11 | Upstream-Status: Pending | ||
12 | |||
13 | Signed-off-by: Jason Wessel <jason.wessel@windriver.com> | ||
14 | --- | ||
15 | grub-core/commands/pgp.c | 16 +++++++++++++++- | ||
16 | grub-core/kern/main.c | 9 +++++++++ | ||
17 | grub-core/normal/main.c | 7 +++++-- | ||
18 | 3 files changed, 29 insertions(+), 3 deletions(-) | ||
19 | |||
20 | --- a/grub-core/commands/pgp.c | ||
21 | +++ b/grub-core/commands/pgp.c | ||
22 | @@ -864,6 +864,7 @@ grub_cmd_verify_signature (grub_extcmd_c | ||
23 | } | ||
24 | |||
25 | static int sec = 0; | ||
26 | +static int strict_sec = 0; | ||
27 | |||
28 | static grub_err_t | ||
29 | grub_pubkey_init (grub_file_t io, enum grub_file_type type __attribute__ ((unused)), | ||
30 | @@ -918,10 +919,21 @@ static char * | ||
31 | grub_env_write_sec (struct grub_env_var *var __attribute__ ((unused)), | ||
32 | const char *val) | ||
33 | { | ||
34 | - sec = (*val == '1') || (*val == 'e'); | ||
35 | + if (!strict_sec) | ||
36 | + sec = (*val == '1') || (*val == 'e'); | ||
37 | return grub_strdup (sec ? "enforce" : "no"); | ||
38 | } | ||
39 | |||
40 | +static char * | ||
41 | +grub_env_write_strict_sec (struct grub_env_var *var __attribute__ ((unused)), | ||
42 | + const char *val) | ||
43 | +{ | ||
44 | + /* once it is set, it is a one way transition */ | ||
45 | + if (!strict_sec) | ||
46 | + strict_sec = (*val == '1') || (*val == 'e'); | ||
47 | + return grub_strdup (strict_sec ? "enforce" : "no"); | ||
48 | +} | ||
49 | + | ||
50 | static grub_ssize_t | ||
51 | pseudo_read (struct grub_file *file, char *buf, grub_size_t len) | ||
52 | { | ||
53 | @@ -961,7 +973,9 @@ GRUB_MOD_INIT(pgp) | ||
54 | sec = 0; | ||
55 | |||
56 | grub_register_variable_hook ("check_signatures", 0, grub_env_write_sec); | ||
57 | + grub_register_variable_hook ("strict_security", 0, grub_env_write_strict_sec); | ||
58 | grub_env_export ("check_signatures"); | ||
59 | + grub_env_export ("strict_security"); | ||
60 | |||
61 | grub_pk_trusted = 0; | ||
62 | FOR_MODULES (header) | ||
63 | --- a/grub-core/kern/main.c | ||
64 | +++ b/grub-core/kern/main.c | ||
65 | @@ -29,6 +29,7 @@ | ||
66 | #include <grub/command.h> | ||
67 | #include <grub/reader.h> | ||
68 | #include <grub/parser.h> | ||
69 | +#include <grub/time.h> | ||
70 | |||
71 | #ifdef GRUB_MACHINE_PCBIOS | ||
72 | #include <grub/machine/memory.h> | ||
73 | @@ -308,5 +309,13 @@ grub_main (void) | ||
74 | grub_boot_time ("After execution of embedded config. Attempt to go to normal mode"); | ||
75 | |||
76 | grub_load_normal_mode (); | ||
77 | + const char *val = grub_env_get ("strict_security"); | ||
78 | + if (val && (val[0] == '1' || val[0] == 'e')) | ||
79 | + while (1) { | ||
80 | + grub_printf("Boot configuration error - Attempting reboot\n"); | ||
81 | + grub_sleep(3); | ||
82 | + grub_dl_load ("reboot"); | ||
83 | + grub_command_execute ("reboot", 0, 0); | ||
84 | + } | ||
85 | grub_rescue_run (); | ||
86 | } | ||
87 | --- a/grub-core/normal/main.c | ||
88 | +++ b/grub-core/normal/main.c | ||
89 | @@ -301,8 +301,11 @@ grub_enter_normal_mode (const char *conf | ||
90 | grub_boot_time ("Entering normal mode"); | ||
91 | nested_level++; | ||
92 | grub_normal_execute (config, 0, 0); | ||
93 | - grub_boot_time ("Entering shell"); | ||
94 | - grub_cmdline_run (0, 1); | ||
95 | + const char *val = grub_env_get ("strict_security"); | ||
96 | + if (!(val && (val[0] == '1' || val[0] == 'e'))) { | ||
97 | + grub_boot_time ("Entering shell"); | ||
98 | + grub_cmdline_run (0, 1); | ||
99 | + } | ||
100 | nested_level--; | ||
101 | if (grub_normal_exit_level) | ||
102 | grub_normal_exit_level--; | ||
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch index b4467c2..4cd8953 100644 --- a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch +++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/mok2verify-support-to-verify-non-PE-file-with-PKCS-7.patch | |||
@@ -37,22 +37,20 @@ grub_file_open function. | |||
37 | 37 | ||
38 | Signed-off-by: Yi Zhao <yi.zhao@windriver.com> | 38 | Signed-off-by: Yi Zhao <yi.zhao@windriver.com> |
39 | --- | 39 | --- |
40 | grub-core/Makefile.core.def | 6 ++ | 40 | grub-core/Makefile.core.def | 6 + |
41 | grub-core/commands/boot.c | 14 +++- | 41 | grub-core/commands/boot.c | 14 ++- |
42 | grub-core/gfxmenu/gui_label.c | 39 +++++++-- | 42 | grub-core/gfxmenu/gui_label.c | 39 +++++++- |
43 | grub-core/lib/efi/mok2verify.c | 182 +++++++++++++++++++++++++++++++++++++++++ | 43 | grub-core/lib/efi/mok2verify.c | 182 +++++++++++++++++++++++++++++++++++++++++ |
44 | grub-core/loader/i386/linux.c | 60 ++++++++++++++ | 44 | grub-core/loader/i386/linux.c | 60 +++++++++++++ |
45 | grub-core/loader/linux.c | 27 +++++- | 45 | grub-core/loader/linux.c | 27 +++++- |
46 | grub-core/normal/main.c | 53 +++++++++++- | 46 | grub-core/normal/main.c | 53 +++++++++++ |
47 | grub-core/normal/menu.c | 31 +++++-- | 47 | grub-core/normal/menu.c | 31 +++++- |
48 | grub-core/normal/menu_text.c | 33 ++++++-- | 48 | grub-core/normal/menu_text.c | 33 +++++-- |
49 | include/grub/efi/mok2verify.h | 48 +++++++++++ | 49 | include/grub/efi/mok2verify.h | 48 ++++++++++ |
50 | 10 files changed, 463 insertions(+), 30 deletions(-) | 50 | 10 files changed, 463 insertions(+), 30 deletions(-) |
51 | create mode 100644 grub-core/lib/efi/mok2verify.c | 51 | create mode 100644 grub-core/lib/efi/mok2verify.c |
52 | create mode 100644 include/grub/efi/mok2verify.h | 52 | create mode 100644 include/grub/efi/mok2verify.h |
53 | 53 | ||
54 | diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def | ||
55 | index 18d2316..59a5cf1 100644 | ||
56 | --- a/grub-core/Makefile.core.def | 54 | --- a/grub-core/Makefile.core.def |
57 | +++ b/grub-core/Makefile.core.def | 55 | +++ b/grub-core/Makefile.core.def |
58 | @@ -1870,6 +1870,12 @@ module = { | 56 | @@ -1870,6 +1870,12 @@ module = { |
@@ -68,8 +66,6 @@ index 18d2316..59a5cf1 100644 | |||
68 | name = mmap; | 66 | name = mmap; |
69 | common = mmap/mmap.c; | 67 | common = mmap/mmap.c; |
70 | x86 = mmap/i386/uppermem.c; | 68 | x86 = mmap/i386/uppermem.c; |
71 | diff --git a/grub-core/commands/boot.c b/grub-core/commands/boot.c | ||
72 | index bbca81e..3f44a7e 100644 | ||
73 | --- a/grub-core/commands/boot.c | 69 | --- a/grub-core/commands/boot.c |
74 | +++ b/grub-core/commands/boot.c | 70 | +++ b/grub-core/commands/boot.c |
75 | @@ -24,6 +24,9 @@ | 71 | @@ -24,6 +24,9 @@ |
@@ -100,8 +96,6 @@ index bbca81e..3f44a7e 100644 | |||
100 | 96 | ||
101 | grub_machine_fini (grub_loader_flags); | 97 | grub_machine_fini (grub_loader_flags); |
102 | 98 | ||
103 | diff --git a/grub-core/gfxmenu/gui_label.c b/grub-core/gfxmenu/gui_label.c | ||
104 | index a4c8178..da49c9e 100644 | ||
105 | --- a/grub-core/gfxmenu/gui_label.c | 99 | --- a/grub-core/gfxmenu/gui_label.c |
106 | +++ b/grub-core/gfxmenu/gui_label.c | 100 | +++ b/grub-core/gfxmenu/gui_label.c |
107 | @@ -24,6 +24,9 @@ | 101 | @@ -24,6 +24,9 @@ |
@@ -114,7 +108,7 @@ index a4c8178..da49c9e 100644 | |||
114 | 108 | ||
115 | static const char *align_options[] = | 109 | static const char *align_options[] = |
116 | { | 110 | { |
117 | @@ -183,15 +186,37 @@ label_set_property (void *vself, const char *name, const char *value) | 111 | @@ -183,15 +186,37 @@ label_set_property (void *vself, const c |
118 | else | 112 | else |
119 | { | 113 | { |
120 | if (grub_strcmp (value, "@KEYMAP_LONG@") == 0) | 114 | if (grub_strcmp (value, "@KEYMAP_LONG@") == 0) |
@@ -159,9 +153,6 @@ index a4c8178..da49c9e 100644 | |||
159 | /* FIXME: Add more templates here if needed. */ | 153 | /* FIXME: Add more templates here if needed. */ |
160 | self->template = grub_strdup (value); | 154 | self->template = grub_strdup (value); |
161 | self->text = grub_xasprintf (value, self->value); | 155 | self->text = grub_xasprintf (value, self->value); |
162 | diff --git a/grub-core/lib/efi/mok2verify.c b/grub-core/lib/efi/mok2verify.c | ||
163 | new file mode 100644 | ||
164 | index 0000000..790efa0 | ||
165 | --- /dev/null | 156 | --- /dev/null |
166 | +++ b/grub-core/lib/efi/mok2verify.c | 157 | +++ b/grub-core/lib/efi/mok2verify.c |
167 | @@ -0,0 +1,182 @@ | 158 | @@ -0,0 +1,182 @@ |
@@ -347,11 +338,9 @@ index 0000000..790efa0 | |||
347 | +} | 338 | +} |
348 | + | 339 | + |
349 | +#pragma GCC diagnostic error "-Wvla" | 340 | +#pragma GCC diagnostic error "-Wvla" |
350 | diff --git a/grub-core/loader/i386/linux.c b/grub-core/loader/i386/linux.c | ||
351 | index d0501e2..e684300 100644 | ||
352 | --- a/grub-core/loader/i386/linux.c | 341 | --- a/grub-core/loader/i386/linux.c |
353 | +++ b/grub-core/loader/i386/linux.c | 342 | +++ b/grub-core/loader/i386/linux.c |
354 | @@ -36,6 +36,9 @@ | 343 | @@ -40,6 +40,9 @@ |
355 | #include <grub/lib/cmdline.h> | 344 | #include <grub/lib/cmdline.h> |
356 | #include <grub/linux.h> | 345 | #include <grub/linux.h> |
357 | #include <grub/machine/kernel.h> | 346 | #include <grub/machine/kernel.h> |
@@ -361,7 +350,7 @@ index d0501e2..e684300 100644 | |||
361 | 350 | ||
362 | GRUB_MOD_LICENSE ("GPLv3+"); | 351 | GRUB_MOD_LICENSE ("GPLv3+"); |
363 | 352 | ||
364 | @@ -635,6 +638,55 @@ grub_linux_unload (void) | 353 | @@ -657,6 +660,55 @@ grub_shim_verify (grub_addr_t addr, grub |
365 | return GRUB_ERR_NONE; | 354 | return GRUB_ERR_NONE; |
366 | } | 355 | } |
367 | 356 | ||
@@ -417,7 +406,7 @@ index d0501e2..e684300 100644 | |||
417 | static grub_err_t | 406 | static grub_err_t |
418 | grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | 407 | grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), |
419 | int argc, char *argv[]) | 408 | int argc, char *argv[]) |
420 | @@ -657,6 +709,9 @@ grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | 409 | @@ -679,6 +731,9 @@ grub_cmd_linux (grub_command_t cmd __att |
421 | goto fail; | 410 | goto fail; |
422 | } | 411 | } |
423 | 412 | ||
@@ -427,7 +416,7 @@ index d0501e2..e684300 100644 | |||
427 | file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); | 416 | file = grub_file_open (argv[0], GRUB_FILE_TYPE_LINUX_KERNEL); |
428 | if (! file) | 417 | if (! file) |
429 | goto fail; | 418 | goto fail; |
430 | @@ -1114,6 +1169,11 @@ grub_cmd_initrd (grub_command_t cmd __attribute__ ((unused)), | 419 | @@ -1140,6 +1195,11 @@ grub_cmd_initrd (grub_command_t cmd __at |
431 | fail: | 420 | fail: |
432 | grub_initrd_close (&initrd_ctx); | 421 | grub_initrd_close (&initrd_ctx); |
433 | 422 | ||
@@ -439,8 +428,6 @@ index d0501e2..e684300 100644 | |||
439 | return grub_errno; | 428 | return grub_errno; |
440 | } | 429 | } |
441 | 430 | ||
442 | diff --git a/grub-core/loader/linux.c b/grub-core/loader/linux.c | ||
443 | index 471b214..bb312ac 100644 | ||
444 | --- a/grub-core/loader/linux.c | 431 | --- a/grub-core/loader/linux.c |
445 | +++ b/grub-core/loader/linux.c | 432 | +++ b/grub-core/loader/linux.c |
446 | @@ -4,6 +4,9 @@ | 433 | @@ -4,6 +4,9 @@ |
@@ -453,7 +440,7 @@ index 471b214..bb312ac 100644 | |||
453 | 440 | ||
454 | struct newc_head | 441 | struct newc_head |
455 | { | 442 | { |
456 | @@ -253,6 +256,7 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, | 443 | @@ -253,6 +256,7 @@ grub_initrd_load (struct grub_linux_init |
457 | int newc = 0; | 444 | int newc = 0; |
458 | struct dir *root = 0; | 445 | struct dir *root = 0; |
459 | grub_ssize_t cursize = 0; | 446 | grub_ssize_t cursize = 0; |
@@ -461,7 +448,7 @@ index 471b214..bb312ac 100644 | |||
461 | 448 | ||
462 | for (i = 0; i < initrd_ctx->nfiles; i++) | 449 | for (i = 0; i < initrd_ctx->nfiles; i++) |
463 | { | 450 | { |
464 | @@ -288,6 +292,25 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, | 451 | @@ -288,6 +292,25 @@ grub_initrd_load (struct grub_linux_init |
465 | grub_initrd_close (initrd_ctx); | 452 | grub_initrd_close (initrd_ctx); |
466 | return grub_errno; | 453 | return grub_errno; |
467 | } | 454 | } |
@@ -487,7 +474,7 @@ index 471b214..bb312ac 100644 | |||
487 | ptr += cursize; | 474 | ptr += cursize; |
488 | } | 475 | } |
489 | if (newc) | 476 | if (newc) |
490 | @@ -296,7 +319,9 @@ grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, | 477 | @@ -296,7 +319,9 @@ grub_initrd_load (struct grub_linux_init |
491 | ptr += ALIGN_UP_OVERHEAD (cursize, 4); | 478 | ptr += ALIGN_UP_OVERHEAD (cursize, 4); |
492 | ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0); | 479 | ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0); |
493 | } | 480 | } |
@@ -498,8 +485,6 @@ index 471b214..bb312ac 100644 | |||
498 | - return GRUB_ERR_NONE; | 485 | - return GRUB_ERR_NONE; |
499 | + return err; | 486 | + return err; |
500 | } | 487 | } |
501 | diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c | ||
502 | index 1b03dfd..f48a549 100644 | ||
503 | --- a/grub-core/normal/main.c | 488 | --- a/grub-core/normal/main.c |
504 | +++ b/grub-core/normal/main.c | 489 | +++ b/grub-core/normal/main.c |
505 | @@ -33,6 +33,9 @@ | 490 | @@ -33,6 +33,9 @@ |
@@ -521,7 +506,7 @@ index 1b03dfd..f48a549 100644 | |||
521 | /* Initialize the screen. */ | 506 | /* Initialize the screen. */ |
522 | void | 507 | void |
523 | grub_normal_init_page (struct grub_term_output *term, | 508 | grub_normal_init_page (struct grub_term_output *term, |
524 | @@ -202,13 +207,24 @@ grub_normal_init_page (struct grub_term_output *term, | 509 | @@ -202,13 +207,24 @@ grub_normal_init_page (struct grub_term_ |
525 | { | 510 | { |
526 | grub_ssize_t msg_len; | 511 | grub_ssize_t msg_len; |
527 | int posx; | 512 | int posx; |
@@ -547,7 +532,7 @@ index 1b03dfd..f48a549 100644 | |||
547 | if (!msg_formatted) | 532 | if (!msg_formatted) |
548 | return; | 533 | return; |
549 | 534 | ||
550 | @@ -233,6 +249,8 @@ grub_normal_init_page (struct grub_term_output *term, | 535 | @@ -233,6 +249,8 @@ grub_normal_init_page (struct grub_term_ |
551 | grub_free (unicode_msg); | 536 | grub_free (unicode_msg); |
552 | } | 537 | } |
553 | 538 | ||
@@ -556,7 +541,7 @@ index 1b03dfd..f48a549 100644 | |||
556 | static void | 541 | static void |
557 | read_lists (const char *val) | 542 | read_lists (const char *val) |
558 | { | 543 | { |
559 | @@ -273,6 +291,20 @@ grub_normal_execute (const char *config, int nested, int batch) | 544 | @@ -273,6 +291,20 @@ grub_normal_execute (const char *config, |
560 | 545 | ||
561 | if (config) | 546 | if (config) |
562 | { | 547 | { |
@@ -577,19 +562,19 @@ index 1b03dfd..f48a549 100644 | |||
577 | menu = read_config_file (config); | 562 | menu = read_config_file (config); |
578 | 563 | ||
579 | /* Ignore any error. */ | 564 | /* Ignore any error. */ |
580 | @@ -302,7 +334,10 @@ grub_enter_normal_mode (const char *config) | 565 | @@ -304,7 +336,10 @@ grub_enter_normal_mode (const char *conf |
581 | nested_level++; | 566 | const char *val = grub_env_get ("strict_security"); |
582 | grub_normal_execute (config, 0, 0); | 567 | if (!(val && (val[0] == '1' || val[0] == 'e'))) { |
583 | grub_boot_time ("Entering shell"); | 568 | grub_boot_time ("Entering shell"); |
584 | - grub_cmdline_run (0, 1); | 569 | - grub_cmdline_run (0, 1); |
585 | +#ifdef GRUB_MACHINE_EFI | 570 | +#ifdef GRUB_MACHINE_EFI |
586 | + if (grub_is_locked () == 0) | 571 | + if (grub_is_locked () == 0) |
587 | +#endif | 572 | +#endif |
588 | + grub_cmdline_run (0, 1); | 573 | + grub_cmdline_run (0, 1); |
574 | } | ||
589 | nested_level--; | 575 | nested_level--; |
590 | if (grub_normal_exit_level) | 576 | if (grub_normal_exit_level) |
591 | grub_normal_exit_level--; | 577 | @@ -341,6 +376,13 @@ grub_cmd_normal (struct grub_command *cm |
592 | @@ -338,6 +373,13 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), | ||
593 | grub_enter_normal_mode (argv[0]); | 578 | grub_enter_normal_mode (argv[0]); |
594 | 579 | ||
595 | quit: | 580 | quit: |
@@ -603,7 +588,7 @@ index 1b03dfd..f48a549 100644 | |||
603 | return 0; | 588 | return 0; |
604 | } | 589 | } |
605 | 590 | ||
606 | @@ -525,8 +567,11 @@ GRUB_MOD_INIT(normal) | 591 | @@ -528,8 +570,11 @@ GRUB_MOD_INIT(normal) |
607 | /* Register a command "normal" for the rescue mode. */ | 592 | /* Register a command "normal" for the rescue mode. */ |
608 | grub_register_command ("normal", grub_cmd_normal, | 593 | grub_register_command ("normal", grub_cmd_normal, |
609 | 0, N_("Enter normal mode.")); | 594 | 0, N_("Enter normal mode.")); |
@@ -617,8 +602,6 @@ index 1b03dfd..f48a549 100644 | |||
617 | 602 | ||
618 | /* Reload terminal colors when these variables are written to. */ | 603 | /* Reload terminal colors when these variables are written to. */ |
619 | grub_register_variable_hook ("color_normal", NULL, grub_env_write_color_normal); | 604 | grub_register_variable_hook ("color_normal", NULL, grub_env_write_color_normal); |
620 | diff --git a/grub-core/normal/menu.c b/grub-core/normal/menu.c | ||
621 | index d5e0c79..512f710 100644 | ||
622 | --- a/grub-core/normal/menu.c | 605 | --- a/grub-core/normal/menu.c |
623 | +++ b/grub-core/normal/menu.c | 606 | +++ b/grub-core/normal/menu.c |
624 | @@ -32,6 +32,9 @@ | 607 | @@ -32,6 +32,9 @@ |
@@ -631,7 +614,7 @@ index d5e0c79..512f710 100644 | |||
631 | 614 | ||
632 | /* Time to delay after displaying an error message about a default/fallback | 615 | /* Time to delay after displaying an error message about a default/fallback |
633 | entry failing to boot. */ | 616 | entry failing to boot. */ |
634 | @@ -773,18 +776,30 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot) | 617 | @@ -773,18 +776,30 @@ run_menu (grub_menu_t menu, int nested, |
635 | break; | 618 | break; |
636 | 619 | ||
637 | case 'c': | 620 | case 'c': |
@@ -670,8 +653,6 @@ index d5e0c79..512f710 100644 | |||
670 | 653 | ||
671 | default: | 654 | default: |
672 | { | 655 | { |
673 | diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c | ||
674 | index e22bb91..28c675f 100644 | ||
675 | --- a/grub-core/normal/menu_text.c | 656 | --- a/grub-core/normal/menu_text.c |
676 | +++ b/grub-core/normal/menu_text.c | 657 | +++ b/grub-core/normal/menu_text.c |
677 | @@ -27,6 +27,9 @@ | 658 | @@ -27,6 +27,9 @@ |
@@ -684,7 +665,7 @@ index e22bb91..28c675f 100644 | |||
684 | 665 | ||
685 | static grub_uint8_t grub_color_menu_normal; | 666 | static grub_uint8_t grub_color_menu_normal; |
686 | static grub_uint8_t grub_color_menu_highlight; | 667 | static grub_uint8_t grub_color_menu_highlight; |
687 | @@ -165,6 +168,7 @@ command-line or ESC to discard edits and return to the GRUB menu."), | 668 | @@ -165,6 +168,7 @@ command-line or ESC to discard edits and |
688 | } | 669 | } |
689 | else | 670 | else |
690 | { | 671 | { |
@@ -692,7 +673,7 @@ index e22bb91..28c675f 100644 | |||
692 | char *msg_translated; | 673 | char *msg_translated; |
693 | 674 | ||
694 | msg_translated = grub_xasprintf (_("Use the %C and %C keys to select which " | 675 | msg_translated = grub_xasprintf (_("Use the %C and %C keys to select which " |
695 | @@ -180,19 +184,32 @@ command-line or ESC to discard edits and return to the GRUB menu."), | 676 | @@ -180,19 +184,32 @@ command-line or ESC to discard edits and |
696 | 677 | ||
697 | if (nested) | 678 | if (nested) |
698 | { | 679 | { |
@@ -733,9 +714,6 @@ index e22bb91..28c675f 100644 | |||
733 | } | 714 | } |
734 | } | 715 | } |
735 | return ret; | 716 | return ret; |
736 | diff --git a/include/grub/efi/mok2verify.h b/include/grub/efi/mok2verify.h | ||
737 | new file mode 100644 | ||
738 | index 0000000..98ef2d4 | ||
739 | --- /dev/null | 717 | --- /dev/null |
740 | +++ b/include/grub/efi/mok2verify.h | 718 | +++ b/include/grub/efi/mok2verify.h |
741 | @@ -0,0 +1,48 @@ | 719 | @@ -0,0 +1,48 @@ |
@@ -787,6 +765,3 @@ index 0000000..98ef2d4 | |||
787 | +EXPORT_FUNC (grub_verify_file) (const char *path); | 765 | +EXPORT_FUNC (grub_verify_file) (const char *path); |
788 | + | 766 | + |
789 | +#endif /* ! GRUB_EFI_MOK2_VERIFY_HEADER */ | 767 | +#endif /* ! GRUB_EFI_MOK2_VERIFY_HEADER */ |
790 | -- | ||
791 | 2.7.4 | ||
792 | |||
diff --git a/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/uefi_verify.patch b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/uefi_verify.patch new file mode 100644 index 0000000..68aca71 --- /dev/null +++ b/meta-efi-secure-boot/recipes-bsp/grub/grub-efi/uefi_verify.patch | |||
@@ -0,0 +1,63 @@ | |||
1 | From: Jason Wessel <jason.wessel@windriver.com> | ||
2 | Date: Thu, 17 Oct 2019 12:35:01 -0700 | ||
3 | Subject: [PATCH] grub shim verify: Report that the loaded object is verified | ||
4 | |||
5 | When check_signatures is set to enforcing, the signatures of the | ||
6 | loaded files have been checked, so the shim service should be informed | ||
7 | that it is ok to execute the loaded file. | ||
8 | |||
9 | Upstream-Status: Inappropriate | ||
10 | |||
11 | Signed-off-by: Jason Wessel <jason.wessel@windriver.com> | ||
12 | --- | ||
13 | grub-core/loader/i386/linux.c | 26 ++++++++++++++++++++++++++ | ||
14 | 1 file changed, 26 insertions(+) | ||
15 | |||
16 | --- a/grub-core/loader/i386/linux.c | ||
17 | +++ b/grub-core/loader/i386/linux.c | ||
18 | @@ -21,6 +21,10 @@ | ||
19 | #include <grub/normal.h> | ||
20 | #include <grub/file.h> | ||
21 | #include <grub/disk.h> | ||
22 | +#include <grub/efi/api.h> | ||
23 | +#include <grub/efi/efi.h> | ||
24 | +#include <grub/efi/disk.h> | ||
25 | +#include <grub/efi/shim.h> | ||
26 | #include <grub/err.h> | ||
27 | #include <grub/misc.h> | ||
28 | #include <grub/types.h> | ||
29 | @@ -673,6 +677,23 @@ grub_linux_unload (void) | ||
30 | return GRUB_ERR_NONE; | ||
31 | } | ||
32 | |||
33 | +static grub_efi_guid_t grub_shim_protocol_guid = GRUB_EFI_SHIM_PROTOCOL_GUID; | ||
34 | + | ||
35 | +static grub_efi_status_t | ||
36 | +grub_shim_verify (grub_addr_t addr, grub_ssize_t size) | ||
37 | +{ | ||
38 | + struct grub_shim_lock *shim_lock; | ||
39 | + shim_lock = grub_efi_locate_protocol (&grub_shim_protocol_guid, 0); | ||
40 | + if (!shim_lock) | ||
41 | + { | ||
42 | + grub_error (GRUB_ERR_BAD_OS, "could not load shim protocol"); | ||
43 | + return GRUB_EFI_UNSUPPORTED; | ||
44 | + } | ||
45 | + | ||
46 | + shim_lock->verify((void *) addr, size); | ||
47 | + return GRUB_ERR_NONE; | ||
48 | +} | ||
49 | + | ||
50 | static grub_err_t | ||
51 | grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), | ||
52 | int argc, char *argv[]) | ||
53 | @@ -706,6 +728,10 @@ grub_cmd_linux (grub_command_t cmd __att | ||
54 | argv[0]); | ||
55 | goto fail; | ||
56 | } | ||
57 | + const char *ge_val = grub_env_get ("check_signatures"); | ||
58 | + if (ge_val && (ge_val[0] == '1' || ge_val[0] == 'e')) | ||
59 | + /* Verify was handled by .sig files, inform shim */ | ||
60 | + grub_shim_verify((grub_addr_t)&lh, sizeof(lh)); | ||
61 | |||
62 | if (lh.boot_flag != grub_cpu_to_le16_compile_time (0xaa55)) | ||
63 | { | ||
diff --git a/meta-signing-key/conf/layer.conf b/meta-signing-key/conf/layer.conf index 2755aa2..84b06a2 100644 --- a/meta-signing-key/conf/layer.conf +++ b/meta-signing-key/conf/layer.conf | |||
@@ -31,6 +31,12 @@ MSFT_KEK_CERT = "${LAYERDIR}/files/uefi_sb_keys/ms-KEK.crt" | |||
31 | # EV certificate | 31 | # EV certificate |
32 | EV_CERT ??= "${LAYERDIR}/files/mok_sb_keys/wosign_ev_cert.crt" | 32 | EV_CERT ??= "${LAYERDIR}/files/mok_sb_keys/wosign_ev_cert.crt" |
33 | 33 | ||
34 | # Use SELoader with the UEFI shim | ||
35 | UEFI_SELOADER ??= "1" | ||
36 | |||
37 | # Use gpg key to protect and verify all files used by grub | ||
38 | GRUB_SIGN_VERIFY ??= "0" | ||
39 | |||
34 | # By default the sample keys are used | 40 | # By default the sample keys are used |
35 | MOK_SB_KEYS_DIR ??= "${SAMPLE_MOK_SB_KEYS_DIR}" | 41 | MOK_SB_KEYS_DIR ??= "${SAMPLE_MOK_SB_KEYS_DIR}" |
36 | UEFI_SB_KEYS_DIR ??= "${SAMPLE_UEFI_SB_KEYS_DIR}" | 42 | UEFI_SB_KEYS_DIR ??= "${SAMPLE_UEFI_SB_KEYS_DIR}" |