aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Kiper <daniel.kiper@oracle.com>2018-05-04 01:59:47 -0400
committerIngo Molnar <mingo@kernel.org>2018-05-14 02:57:46 -0400
commita7012bdbdf406bbaa4e3de0cc3d8eb0faaacbf93 (patch)
treefba523a21d33efb207ba5128c23350577ebefaaa
parent0b3225ab9407f557a8e20f23f37aa7236c10a9b1 (diff)
x86/xen/efi: Initialize UEFI secure boot state during dom0 boot
Initialize UEFI secure boot state during dom0 boot. Otherwise the kernel may not even know that it runs on secure boot enabled platform. Note that part of drivers/firmware/efi/libstub/secureboot.c is duplicated by this patch, only in this case, it runs in the context of the kernel proper rather than UEFI boot context. The reason for the duplication is that maintaining the original code to run correctly on ARM/arm64 as well as on all the quirky x86 firmware we support is enough of a burden as it is, and adding the x86/Xen execution context to that mix just so we can reuse a single routine just isn't worth it. [ardb: explain rationale for code duplication] Signed-off-by: Daniel Kiper <daniel.kiper@oracle.com> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Matt Fleming <matt@codeblueprint.co.uk> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/20180504060003.19618-2-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--arch/x86/xen/efi.c57
-rw-r--r--drivers/firmware/efi/libstub/secureboot.c3
2 files changed, 60 insertions, 0 deletions
diff --git a/arch/x86/xen/efi.c b/arch/x86/xen/efi.c
index a18703be9ead..1804b27f9632 100644
--- a/arch/x86/xen/efi.c
+++ b/arch/x86/xen/efi.c
@@ -115,6 +115,61 @@ static efi_system_table_t __init *xen_efi_probe(void)
115 return &efi_systab_xen; 115 return &efi_systab_xen;
116} 116}
117 117
118/*
119 * Determine whether we're in secure boot mode.
120 *
121 * Please keep the logic in sync with
122 * drivers/firmware/efi/libstub/secureboot.c:efi_get_secureboot().
123 */
124static enum efi_secureboot_mode xen_efi_get_secureboot(void)
125{
126 static efi_guid_t efi_variable_guid = EFI_GLOBAL_VARIABLE_GUID;
127 static efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
128 efi_status_t status;
129 u8 moksbstate, secboot, setupmode;
130 unsigned long size;
131
132 size = sizeof(secboot);
133 status = efi.get_variable(L"SecureBoot", &efi_variable_guid,
134 NULL, &size, &secboot);
135
136 if (status == EFI_NOT_FOUND)
137 return efi_secureboot_mode_disabled;
138
139 if (status != EFI_SUCCESS)
140 goto out_efi_err;
141
142 size = sizeof(setupmode);
143 status = efi.get_variable(L"SetupMode", &efi_variable_guid,
144 NULL, &size, &setupmode);
145
146 if (status != EFI_SUCCESS)
147 goto out_efi_err;
148
149 if (secboot == 0 || setupmode == 1)
150 return efi_secureboot_mode_disabled;
151
152 /* See if a user has put the shim into insecure mode. */
153 size = sizeof(moksbstate);
154 status = efi.get_variable(L"MokSBStateRT", &shim_guid,
155 NULL, &size, &moksbstate);
156
157 /* If it fails, we don't care why. Default to secure. */
158 if (status != EFI_SUCCESS)
159 goto secure_boot_enabled;
160
161 if (moksbstate == 1)
162 return efi_secureboot_mode_disabled;
163
164 secure_boot_enabled:
165 pr_info("UEFI Secure Boot is enabled.\n");
166 return efi_secureboot_mode_enabled;
167
168 out_efi_err:
169 pr_err("Could not determine UEFI Secure Boot status.\n");
170 return efi_secureboot_mode_unknown;
171}
172
118void __init xen_efi_init(void) 173void __init xen_efi_init(void)
119{ 174{
120 efi_system_table_t *efi_systab_xen; 175 efi_system_table_t *efi_systab_xen;
@@ -129,6 +184,8 @@ void __init xen_efi_init(void)
129 boot_params.efi_info.efi_systab = (__u32)__pa(efi_systab_xen); 184 boot_params.efi_info.efi_systab = (__u32)__pa(efi_systab_xen);
130 boot_params.efi_info.efi_systab_hi = (__u32)(__pa(efi_systab_xen) >> 32); 185 boot_params.efi_info.efi_systab_hi = (__u32)(__pa(efi_systab_xen) >> 32);
131 186
187 boot_params.secure_boot = xen_efi_get_secureboot();
188
132 set_bit(EFI_BOOT, &efi.flags); 189 set_bit(EFI_BOOT, &efi.flags);
133 set_bit(EFI_PARAVIRT, &efi.flags); 190 set_bit(EFI_PARAVIRT, &efi.flags);
134 set_bit(EFI_64BIT, &efi.flags); 191 set_bit(EFI_64BIT, &efi.flags);
diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c
index 8f07eb414c00..72d9dfbebf08 100644
--- a/drivers/firmware/efi/libstub/secureboot.c
+++ b/drivers/firmware/efi/libstub/secureboot.c
@@ -30,6 +30,9 @@ static const efi_char16_t shim_MokSBState_name[] = L"MokSBState";
30 30
31/* 31/*
32 * Determine whether we're in secure boot mode. 32 * Determine whether we're in secure boot mode.
33 *
34 * Please keep the logic in sync with
35 * arch/x86/xen/efi.c:xen_efi_get_secureboot().
33 */ 36 */
34enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg) 37enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg)
35{ 38{