6a9155
From: Josh Boyer <jwboyer@fedoraproject.org>
6a9155
Date: Thu, 3 Oct 2013 10:14:23 -0400
6a9155
Subject: [PATCH] MODSIGN: Support not importing certs from db
6a9155
6a9155
If a user tells shim to not use the certs/hashes in the UEFI db variable
6a9155
for verification purposes, shim will set a UEFI variable called MokIgnoreDB.
6a9155
Have the uefi import code look for this and not import things from the db
6a9155
variable.
6a9155
6a9155
Signed-off-by: Josh Boyer <jwboyer@fedoraproject.org>
6a9155
---
6a9155
 kernel/modsign_uefi.c | 40 +++++++++++++++++++++++++++++++---------
6a9155
 1 file changed, 31 insertions(+), 9 deletions(-)
6a9155
6a9155
diff --git a/kernel/modsign_uefi.c b/kernel/modsign_uefi.c
6a9155
index 94b0eb38a284..ae28b974d49a 100644
6a9155
--- a/kernel/modsign_uefi.c
6a9155
+++ b/kernel/modsign_uefi.c
6a9155
@@ -8,6 +8,23 @@
6a9155
 #include <keys/system_keyring.h>
6a9155
 #include "module-internal.h"
6a9155
 
6a9155
+static __init int check_ignore_db(void)
6a9155
+{
6a9155
+	efi_status_t status;
6a9155
+	unsigned int db = 0;
6a9155
+	unsigned long size = sizeof(db);
6a9155
+	efi_guid_t guid = EFI_SHIM_LOCK_GUID;
6a9155
+
6a9155
+	/* Check and see if the MokIgnoreDB variable exists.  If that fails
6a9155
+	 * then we don't ignore DB.  If it succeeds, we do.
6a9155
+	 */
6a9155
+	status = efi.get_variable(L"MokIgnoreDB", &guid, NULL, &size, &db);
6a9155
+	if (status != EFI_SUCCESS)
6a9155
+		return 0;
6a9155
+
6a9155
+	return 1;
6a9155
+}
6a9155
+
6a9155
 static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid, unsigned long *size)
6a9155
 {
6a9155
 	efi_status_t status;
6a9155
@@ -47,23 +64,28 @@ static int __init load_uefi_certs(void)
6a9155
 	efi_guid_t mok_var = EFI_SHIM_LOCK_GUID;
6a9155
 	void *db = NULL, *dbx = NULL, *mok = NULL;
6a9155
 	unsigned long dbsize = 0, dbxsize = 0, moksize = 0;
6a9155
-	int rc = 0;
6a9155
+	int ignore_db, rc = 0;
6a9155
 
6a9155
 	/* Check if SB is enabled and just return if not */
6a9155
 	if (!efi_enabled(EFI_SECURE_BOOT))
6a9155
 		return 0;
6a9155
 
6a9155
+	/* See if the user has setup Ignore DB mode */
6a9155
+	ignore_db = check_ignore_db();
6a9155
+
6a9155
 	/* Get db, MokListRT, and dbx.  They might not exist, so it isn't
6a9155
 	 * an error if we can't get them.
6a9155
 	 */
6a9155
-	db = get_cert_list(L"db", &secure_var, &dbsize);
6a9155
-	if (!db) {
6a9155
-		pr_err("MODSIGN: Couldn't get UEFI db list\n");
6a9155
-	} else {
6a9155
-		rc = parse_efi_signature_list(db, dbsize, system_trusted_keyring);
6a9155
-		if (rc)
6a9155
-			pr_err("Couldn't parse db signatures: %d\n", rc);
6a9155
-		kfree(db);
6a9155
+	if (!ignore_db) {
6a9155
+		db = get_cert_list(L"db", &secure_var, &dbsize);
6a9155
+		if (!db) {
6a9155
+			pr_err("MODSIGN: Couldn't get UEFI db list\n");
6a9155
+		} else {
6a9155
+			rc = parse_efi_signature_list(db, dbsize, system_trusted_keyring);
6a9155
+			if (rc)
6a9155
+				pr_err("Couldn't parse db signatures: %d\n", rc);
6a9155
+			kfree(db);
6a9155
+		}
6a9155
 	}
6a9155
 
6a9155
 	mok = get_cert_list(L"MokListRT", &mok_var, &moksize);