ignatenkobrain / rpms / kernel

Forked from rpms/kernel 3 years ago
Clone
e336be
From 9f1958a0cc911e1f79b2733ee5029dbd819ff328 Mon Sep 17 00:00:00 2001
e336be
From: Josh Boyer <jwboyer@fedoraproject.org>
e336be
Date: Fri, 5 May 2017 08:21:59 +0100
e336be
Subject: [PATCH 4/4] MODSIGN: Allow the "db" UEFI variable to be suppressed
e336be
e336be
If a user tells shim to not use the certs/hashes in the UEFI db variable
e336be
for verification purposes, shim will set a UEFI variable called
e336be
MokIgnoreDB.  Have the uefi import code look for this and ignore the db
e336be
variable if it is found.
e336be
e336be
Signed-off-by: Josh Boyer <jwboyer@fedoraproject.org>
e336be
Signed-off-by: David Howells <dhowells@redhat.com>
e336be
---
e336be
 certs/load_uefi.c | 44 ++++++++++++++++++++++++++++++++++----------
e336be
 1 file changed, 34 insertions(+), 10 deletions(-)
e336be
e336be
diff --git a/certs/load_uefi.c b/certs/load_uefi.c
e336be
index b44e464..3d88459 100644
e336be
--- a/certs/load_uefi.c
e336be
+++ b/certs/load_uefi.c
e336be
@@ -13,6 +13,26 @@ static __initdata efi_guid_t efi_cert_x509_sha256_guid = EFI_CERT_X509_SHA256_GU
e336be
 static __initdata efi_guid_t efi_cert_sha256_guid = EFI_CERT_SHA256_GUID;
e336be
e336be
 /*
e336be
+ * Look to see if a UEFI variable called MokIgnoreDB exists and return true if
e336be
+ * it does.
e336be
+ *
e336be
+ * This UEFI variable is set by the shim if a user tells the shim to not use
e336be
+ * the certs/hashes in the UEFI db variable for verification purposes.  If it
e336be
+ * is set, we should ignore the db variable also and the true return indicates
e336be
+ * this.
e336be
+ */
e336be
+static __init bool uefi_check_ignore_db(void)
e336be
+{
e336be
+	efi_status_t status;
e336be
+	unsigned int db = 0;
e336be
+	unsigned long size = sizeof(db);
e336be
+	efi_guid_t guid = EFI_SHIM_LOCK_GUID;
e336be
+
e336be
+	status = efi.get_variable(L"MokIgnoreDB", &guid, NULL, &size, &db);
e336be
+	return status == EFI_SUCCESS;
e336be
+}
e336be
+
e336be
+/*
e336be
  * Get a certificate list blob from the named EFI variable.
e336be
  */
e336be
 static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
e336be
@@ -113,7 +133,9 @@ static __init efi_element_handler_t get_handler_for_dbx(const efi_guid_t *sig_ty
e336be
 }
e336be
e336be
 /*
e336be
- * Load the certs contained in the UEFI databases
e336be
+ * Load the certs contained in the UEFI databases into the secondary trusted
e336be
+ * keyring and the UEFI blacklisted X.509 cert SHA256 hashes into the blacklist
e336be
+ * keyring.
e336be
  */
e336be
 static int __init load_uefi_certs(void)
e336be
 {
e336be
@@ -129,15 +151,17 @@ static int __init load_uefi_certs(void)
e336be
 	/* Get db, MokListRT, and dbx.  They might not exist, so it isn't
e336be
 	 * an error if we can't get them.
e336be
 	 */
e336be
-	db = get_cert_list(L"db", &secure_var, &dbsize);
e336be
-	if (!db) {
e336be
-		pr_err("MODSIGN: Couldn't get UEFI db list\n");
e336be
-	} else {
e336be
-		rc = parse_efi_signature_list("UEFI:db",
e336be
-					      db, dbsize, get_handler_for_db);
e336be
-		if (rc)
e336be
-			pr_err("Couldn't parse db signatures: %d\n", rc);
e336be
-		kfree(db);
e336be
+	if (!uefi_check_ignore_db()) {
e336be
+		db = get_cert_list(L"db", &secure_var, &dbsize);
e336be
+		if (!db) {
e336be
+			pr_err("MODSIGN: Couldn't get UEFI db list\n");
e336be
+		} else {
e336be
+			rc = parse_efi_signature_list("UEFI:db",
e336be
+						      db, dbsize, get_handler_for_db);
e336be
+			if (rc)
e336be
+				pr_err("Couldn't parse db signatures: %d\n", rc);
e336be
+			kfree(db);
e336be
+		}
e336be
 	}
e336be
e336be
 	mok = get_cert_list(L"MokListRT", &mok_var, &moksize);
e336be
-- 
e336be
2.9.3
e336be