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