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