From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753961AbdBGJsr (ORCPT ); Tue, 7 Feb 2017 04:48:47 -0500 Received: from terminus.zytor.com ([65.50.211.136]:33876 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753230AbdBGJso (ORCPT ); Tue, 7 Feb 2017 04:48:44 -0500 Date: Tue, 7 Feb 2017 01:48:00 -0800 From: tip-bot for Josh Boyer Message-ID: Cc: peterz@infradead.org, jwboyer@fedoraproject.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, dhowells@redhat.com, torvalds@linux-foundation.org, hpa@zytor.com, ard.biesheuvel@linaro.org, matt@codeblueprint.co.uk, mingo@kernel.org Reply-To: peterz@infradead.org, jwboyer@fedoraproject.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, ard.biesheuvel@linaro.org, torvalds@linux-foundation.org, dhowells@redhat.com, hpa@zytor.com, mingo@kernel.org, matt@codeblueprint.co.uk In-Reply-To: <1486380166-31868-6-git-send-email-ard.biesheuvel@linaro.org> References: <1486380166-31868-6-git-send-email-ard.biesheuvel@linaro.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:efi/core] efi: Disable secure boot if shim is in insecure mode Git-Commit-ID: f3cf6f7434debcc65f397228c689641b07c1be35 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: f3cf6f7434debcc65f397228c689641b07c1be35 Gitweb: http://git.kernel.org/tip/f3cf6f7434debcc65f397228c689641b07c1be35 Author: Josh Boyer AuthorDate: Mon, 6 Feb 2017 11:22:44 +0000 Committer: Ingo Molnar CommitDate: Tue, 7 Feb 2017 10:42:10 +0100 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 Signed-off-by: David Howells Signed-off-by: Ard Biesheuvel Cc: Linus Torvalds Cc: Matt Fleming Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: linux-efi@vger.kernel.org Link: http://lkml.kernel.org/r/1486380166-31868-6-git-send-email-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar --- drivers/firmware/efi/libstub/secureboot.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c index b20b8b4..6def402 100644 --- a/drivers/firmware/efi/libstub/secureboot.c +++ b/drivers/firmware/efi/libstub/secureboot.c @@ -21,6 +21,12 @@ static const efi_char16_t const efi_SetupMode_name[] = { 'S', 'e', 't', 'u', 'p', 'M', 'o', 'd', 'e', 0 }; +/* SHIM variables */ +static const efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID; +static efi_char16_t const shim_MokSBState_name[] = { + 'M', 'o', 'k', 'S', 'B', 'S', 't', 'a', 't', 'e', 0 +}; + #define get_efi_var(name, vendor, ...) \ efi_call_runtime(get_variable, \ (efi_char16_t *)(name), (efi_guid_t *)(vendor), \ @@ -31,7 +37,8 @@ static const efi_char16_t const efi_SetupMode_name[] = { */ enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg) { - u8 secboot, setupmode; + u32 attr; + u8 secboot, setupmode, moksbstate; unsigned long size; efi_status_t status; @@ -50,6 +57,22 @@ enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg) if (secboot == 0 || setupmode == 1) return efi_secureboot_mode_disabled; + /* + * See if a user has put the shim into insecure mode. If so, and if the + * variable doesn't have the runtime attribute set, we might as well + * honor that. + */ + size = sizeof(moksbstate); + status = get_efi_var(shim_MokSBState_name, &shim_guid, + &attr, &size, &moksbstate); + + /* If it fails, we don't care why. Default to secure */ + if (status != EFI_SUCCESS) + goto secure_boot_enabled; + if (!(attr & EFI_VARIABLE_RUNTIME_ACCESS) && moksbstate == 1) + return efi_secureboot_mode_disabled; + +secure_boot_enabled: pr_efi(sys_table_arg, "UEFI Secure Boot is enabled.\n"); return efi_secureboot_mode_enabled;