From: Josh Boyer Date: Wed, 6 Feb 2013 00:25:05 +0000 (-0500) Subject: efi: Disable secure boot if shim is in insecure mode X-Git-Tag: archive/raspbian/4.9.80-2+rpi1~8^2~60 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2d4b0ab8bc0c072bc249787ab646f1d8493f387a;p=linux-4.9.git 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 Gbp-Pq: Topic features/all/securelevel Gbp-Pq: Name efi-disable-secure-boot-if-shim-is-in-insecure-mode.patch --- diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 4a7d64ef7268..e042f00cd9f7 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -713,8 +713,9 @@ void setup_graphics(struct boot_params *boot_params) static int get_secure_boot(void) { - u8 sb, setup; + u8 sb, setup, moksbstate; unsigned long datasize = sizeof(sb); + u32 attr; efi_guid_t var_guid = EFI_GLOBAL_VARIABLE_GUID; efi_status_t status; @@ -738,6 +739,23 @@ static int get_secure_boot(void) if (setup == 1) return 0; + /* See if a user has put shim into insecure_mode. If so, and the variable + * doesn't have the runtime attribute set, we might as well honor that. + */ + var_guid = EFI_SHIM_LOCK_GUID; + status = efi_early->call((unsigned long)sys_table->runtime->get_variable, + L"MokSBState", &var_guid, &attr, &datasize, + &moksbstate); + + /* If it fails, we don't care why. Default to secure */ + if (status != EFI_SUCCESS) + return 1; + + if (!(attr & EFI_VARIABLE_RUNTIME_ACCESS)) { + if (moksbstate == 1) + return 0; + } + return 1; } diff --git a/include/linux/efi.h b/include/linux/efi.h index cba7177cbec7..b020dd370d32 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -631,6 +631,9 @@ typedef struct { #define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | (10)) #define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | (02)) +#define EFI_SHIM_LOCK_GUID \ + EFI_GUID( 0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 ) + typedef struct { efi_table_hdr_t hdr; u64 fw_vendor; /* physical addr of CHAR16 vendor string */