42d2805
From 0a5c52b9eb4918fb2bee43bacc3521b574334cff Mon Sep 17 00:00:00 2001
6a91557
From: Josh Boyer <jwboyer@fedoraproject.org>
6a91557
Date: Tue, 5 Feb 2013 19:25:05 -0500
42d2805
Subject: [PATCH 1/9] efi: Disable secure boot if shim is in insecure mode
6a91557
6a91557
A user can manually tell the shim boot loader to disable validation of
6a91557
images it loads.  When a user does this, it creates a UEFI variable called
6a91557
MokSBState that does not have the runtime attribute set.  Given that the
6a91557
user explicitly disabled validation, we can honor that and not enable
6a91557
secure boot mode if that variable is set.
6a91557
6a91557
Signed-off-by: Josh Boyer <jwboyer@fedoraproject.org>
6a91557
---
6a91557
 arch/x86/boot/compressed/eboot.c | 20 +++++++++++++++++++-
6a91557
 1 file changed, 19 insertions(+), 1 deletion(-)
6a91557
6a91557
diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
42d2805
index 6b8b9a775b46..b3a5364d31c6 100644
6a91557
--- a/arch/x86/boot/compressed/eboot.c
6a91557
+++ b/arch/x86/boot/compressed/eboot.c
42d2805
@@ -574,8 +574,9 @@ free_handle:
6a91557
 
6a91557
 static int get_secure_boot(void)
6a91557
 {
6a91557
-	u8 sb, setup;
6a91557
+	u8 sb, setup, moksbstate;
6a91557
 	unsigned long datasize = sizeof(sb);
6a91557
+	u32 attr;
6a91557
 	efi_guid_t var_guid = EFI_GLOBAL_VARIABLE_GUID;
6a91557
 	efi_status_t status;
6a91557
 
42d2805
@@ -599,6 +600,23 @@ static int get_secure_boot(void)
6a91557
 	if (setup == 1)
6a91557
 		return 0;
6a91557
 
6a91557
+	/* See if a user has put shim into insecure_mode.  If so, and the variable
6a91557
+	 * doesn't have the runtime attribute set, we might as well honor that.
6a91557
+	 */
6a91557
+	var_guid = EFI_SHIM_LOCK_GUID;
6a91557
+	status = efi_early->call((unsigned long)sys_table->runtime->get_variable,
6a91557
+				L"MokSBState", &var_guid, &attr, &datasize,
6a91557
+				&moksbstate);
6a91557
+
6a91557
+	/* If it fails, we don't care why.  Default to secure */
6a91557
+	if (status != EFI_SUCCESS)
6a91557
+		return 1;
6a91557
+
6a91557
+	if (!(attr & EFI_VARIABLE_RUNTIME_ACCESS)) {
6a91557
+		if (moksbstate == 1)
6a91557
+			return 0;
6a91557
+	}
6a91557
+
6a91557
 	return 1;
6a91557
 }
6a91557
 
18c8249
-- 
42d2805
2.5.5
18c8249