5804b7
From 3ce5852ec6add45a28fe1706e9163351940e905c Mon Sep 17 00:00:00 2001
ef8989
From: Peter Jones <pjones@redhat.com>
ef8989
Date: Mon, 2 Oct 2017 18:25:29 -0400
ef8989
Subject: [PATCH 1/3] Make get_cert_list() not complain about cert lists that
ef8989
 aren't present.
ef8989
ef8989
Signed-off-by: Peter Jones <pjones@redhat.com>
ef8989
---
ef8989
 certs/load_uefi.c | 37 ++++++++++++++++++++++---------------
ef8989
 1 file changed, 22 insertions(+), 15 deletions(-)
ef8989
ef8989
diff --git a/certs/load_uefi.c b/certs/load_uefi.c
5804b7
index 3d884598601..9ef34c44fd1 100644
ef8989
--- a/certs/load_uefi.c
ef8989
+++ b/certs/load_uefi.c
ef8989
@@ -35,8 +35,8 @@ static __init bool uefi_check_ignore_db(void)
ef8989
 /*
ef8989
  * Get a certificate list blob from the named EFI variable.
ef8989
  */
ef8989
-static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
ef8989
-				  unsigned long *size)
ef8989
+static __init int get_cert_list(efi_char16_t *name, efi_guid_t *guid,
ef8989
+				unsigned long *size, void **cert_list)
ef8989
 {
ef8989
 	efi_status_t status;
ef8989
 	unsigned long lsize = 4;
ef8989
@@ -44,26 +44,33 @@ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
ef8989
 	void *db;
ef8989
 
ef8989
 	status = efi.get_variable(name, guid, NULL, &lsize, &tmpdb);
ef8989
+	if (status == EFI_NOT_FOUND) {
ef8989
+		*size = 0;
ef8989
+		*cert_list = NULL;
ef8989
+		return 0;
ef8989
+	}
ef8989
+
ef8989
 	if (status != EFI_BUFFER_TOO_SMALL) {
ef8989
 		pr_err("Couldn't get size: 0x%lx\n", status);
ef8989
-		return NULL;
ef8989
+		return efi_status_to_err(status);
ef8989
 	}
ef8989
 
ef8989
 	db = kmalloc(lsize, GFP_KERNEL);
ef8989
 	if (!db) {
ef8989
 		pr_err("Couldn't allocate memory for uefi cert list\n");
ef8989
-		return NULL;
ef8989
+		return -ENOMEM;
ef8989
 	}
ef8989
 
ef8989
 	status = efi.get_variable(name, guid, NULL, &lsize, db);
ef8989
 	if (status != EFI_SUCCESS) {
ef8989
 		kfree(db);
ef8989
 		pr_err("Error reading db var: 0x%lx\n", status);
ef8989
-		return NULL;
ef8989
+		return efi_status_to_err(status);
ef8989
 	}
ef8989
 
ef8989
 	*size = lsize;
ef8989
-	return db;
ef8989
+	*cert_list = db;
ef8989
+	return 0;
ef8989
 }
ef8989
 
ef8989
 /*
ef8989
@@ -152,10 +159,10 @@ static int __init load_uefi_certs(void)
ef8989
 	 * an error if we can't get them.
ef8989
 	 */
ef8989
 	if (!uefi_check_ignore_db()) {
ef8989
-		db = get_cert_list(L"db", &secure_var, &dbsize);
ef8989
-		if (!db) {
ef8989
+		rc = get_cert_list(L"db", &secure_var, &dbsize, &db);
ef8989
+		if (rc < 0) {
ef8989
 			pr_err("MODSIGN: Couldn't get UEFI db list\n");
ef8989
-		} else {
ef8989
+		} else if (dbsize != 0) {
ef8989
 			rc = parse_efi_signature_list("UEFI:db",
ef8989
 						      db, dbsize, get_handler_for_db);
ef8989
 			if (rc)
ef8989
@@ -164,10 +171,10 @@ static int __init load_uefi_certs(void)
ef8989
 		}
ef8989
 	}
ef8989
 
ef8989
-	mok = get_cert_list(L"MokListRT", &mok_var, &moksize);
ef8989
-	if (!mok) {
ef8989
+	rc = get_cert_list(L"MokListRT", &mok_var, &moksize, &mok;;
ef8989
+	if (rc < 0) {
ef8989
 		pr_info("MODSIGN: Couldn't get UEFI MokListRT\n");
ef8989
-	} else {
ef8989
+	} else if (moksize != 0) {
ef8989
 		rc = parse_efi_signature_list("UEFI:MokListRT",
ef8989
 					      mok, moksize, get_handler_for_db);
ef8989
 		if (rc)
ef8989
@@ -175,10 +182,10 @@ static int __init load_uefi_certs(void)
ef8989
 		kfree(mok);
ef8989
 	}
ef8989
 
ef8989
-	dbx = get_cert_list(L"dbx", &secure_var, &dbxsize);
ef8989
-	if (!dbx) {
ef8989
+	rc = get_cert_list(L"dbx", &secure_var, &dbxsize, &dbx;;
ef8989
+	if (rc < 0) {
ef8989
 		pr_info("MODSIGN: Couldn't get UEFI dbx list\n");
ef8989
-	} else {
ef8989
+	} else if (dbxsize != 0) {
ef8989
 		rc = parse_efi_signature_list("UEFI:dbx",
ef8989
 					      dbx, dbxsize,
ef8989
 					      get_handler_for_dbx);
ef8989
-- 
5804b7
2.15.0
ef8989