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