Skip to content

Commit f3cf6f7

Browse files
Josh Boyeringomolnar
authored andcommitted
efi: Disable secure boot if shim is in insecure mode
A user can manually tell the shim boot loader to disable validation of images it loads. When a user does this, it creates a UEFI variable called MokSBState that does not have the runtime attribute set. Given that the user explicitly disabled validation, we can honor that and not enable secure boot mode if that variable is set. Signed-off-by: Josh Boyer <[email protected]> Signed-off-by: David Howells <[email protected]> Signed-off-by: Ard Biesheuvel <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Matt Fleming <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent de8cb45 commit f3cf6f7

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

drivers/firmware/efi/libstub/secureboot.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ static const efi_char16_t const efi_SetupMode_name[] = {
2121
'S', 'e', 't', 'u', 'p', 'M', 'o', 'd', 'e', 0
2222
};
2323

24+
/* SHIM variables */
25+
static const efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
26+
static efi_char16_t const shim_MokSBState_name[] = {
27+
'M', 'o', 'k', 'S', 'B', 'S', 't', 'a', 't', 'e', 0
28+
};
29+
2430
#define get_efi_var(name, vendor, ...) \
2531
efi_call_runtime(get_variable, \
2632
(efi_char16_t *)(name), (efi_guid_t *)(vendor), \
@@ -31,7 +37,8 @@ static const efi_char16_t const efi_SetupMode_name[] = {
3137
*/
3238
enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg)
3339
{
34-
u8 secboot, setupmode;
40+
u32 attr;
41+
u8 secboot, setupmode, moksbstate;
3542
unsigned long size;
3643
efi_status_t status;
3744

@@ -50,6 +57,22 @@ enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg)
5057
if (secboot == 0 || setupmode == 1)
5158
return efi_secureboot_mode_disabled;
5259

60+
/*
61+
* See if a user has put the shim into insecure mode. If so, and if the
62+
* variable doesn't have the runtime attribute set, we might as well
63+
* honor that.
64+
*/
65+
size = sizeof(moksbstate);
66+
status = get_efi_var(shim_MokSBState_name, &shim_guid,
67+
&attr, &size, &moksbstate);
68+
69+
/* If it fails, we don't care why. Default to secure */
70+
if (status != EFI_SUCCESS)
71+
goto secure_boot_enabled;
72+
if (!(attr & EFI_VARIABLE_RUNTIME_ACCESS) && moksbstate == 1)
73+
return efi_secureboot_mode_disabled;
74+
75+
secure_boot_enabled:
5376
pr_efi(sys_table_arg, "UEFI Secure Boot is enabled.\n");
5477
return efi_secureboot_mode_enabled;
5578

0 commit comments

Comments
 (0)