tleleu / rpms / kernel

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