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