7bea88
From 3ce5852ec6add45a28fe1706e9163351940e905c Mon Sep 17 00:00:00 2001
8eb3db
From: Peter Jones <pjones@redhat.com>
8eb3db
Date: Mon, 2 Oct 2017 18:25:29 -0400
8eb3db
Subject: [PATCH 1/3] Make get_cert_list() not complain about cert lists that
8eb3db
 aren't present.
8eb3db
8eb3db
Signed-off-by: Peter Jones <pjones@redhat.com>
8eb3db
---
cc1db7
 security/integrity/platform_certs/load_uefi.c | 37 ++++++++++++++++++++++---------------
8eb3db
 1 file changed, 22 insertions(+), 15 deletions(-)
8eb3db
cc1db7
diff --git a/security/integrity/platform_certs/load_uefi.c b/security/integrity/platform_certs/load_uefi.c
cc1db7
index 81b19c52832b..e188f3ecbce3 100644
cc1db7
--- a/security/integrity/platform_certs/load_uefi.c
cc1db7
+++ b/security/integrity/platform_certs/load_uefi.c
cc1db7
@@ -38,8 +38,8 @@ static __init bool uefi_check_ignore_db(void)
8eb3db
 /*
8eb3db
  * Get a certificate list blob from the named EFI variable.
8eb3db
  */
8eb3db
-static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
8eb3db
-				  unsigned long *size)
8eb3db
+static __init int get_cert_list(efi_char16_t *name, efi_guid_t *guid,
cc1db7
+				  unsigned long *size , void **cert_list)
8eb3db
 {
8eb3db
 	efi_status_t status;
8eb3db
 	unsigned long lsize = 4;
cc1db7
@@ -47,24 +47,31 @@ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
8eb3db
 	void *db;
cc1db7
8eb3db
 	status = efi.get_variable(name, guid, NULL, &lsize, &tmpdb);
8eb3db
+	if (status == EFI_NOT_FOUND) {
8eb3db
+		*size = 0;
8eb3db
+		*cert_list = NULL;
8eb3db
+		return 0;
8eb3db
+	}
8eb3db
+
8eb3db
 	if (status != EFI_BUFFER_TOO_SMALL) {
8eb3db
 		pr_err("Couldn't get size: 0x%lx\n", status);
8eb3db
-		return NULL;
8eb3db
+		return efi_status_to_err(status);
8eb3db
 	}
cc1db7
8eb3db
 	db = kmalloc(lsize, GFP_KERNEL);
cc1db7
 	if (!db)
8eb3db
-		return NULL;
8eb3db
+		return -ENOMEM;
cc1db7
8eb3db
 	status = efi.get_variable(name, guid, NULL, &lsize, db);
8eb3db
 	if (status != EFI_SUCCESS) {
8eb3db
 		kfree(db);
8eb3db
 		pr_err("Error reading db var: 0x%lx\n", status);
8eb3db
-		return NULL;
8eb3db
+		return efi_status_to_err(status);
8eb3db
 	}
cc1db7
8eb3db
 	*size = lsize;
8eb3db
-	return db;
8eb3db
+	*cert_list = db;
8eb3db
+	return 0;
8eb3db
 }
cc1db7
8eb3db
 /*
cc1db7
@@ -153,10 +160,10 @@ static int __init load_uefi_certs(void)
8eb3db
 	 * an error if we can't get them.
8eb3db
 	 */
8eb3db
 	if (!uefi_check_ignore_db()) {
8eb3db
-		db = get_cert_list(L"db", &secure_var, &dbsize);
8eb3db
-		if (!db) {
8eb3db
+		rc = get_cert_list(L"db", &secure_var, &dbsize, &db);
8eb3db
+		if (rc < 0) {
8eb3db
 			pr_err("MODSIGN: Couldn't get UEFI db list\n");
8eb3db
-		} else {
8eb3db
+		} else if (dbsize != 0) {
8eb3db
 			rc = parse_efi_signature_list("UEFI:db",
cc1db7
 					db, dbsize, get_handler_for_db);
8eb3db
 			if (rc)
cc1db7
@@ -166,10 +173,10 @@ static int __init load_uefi_certs(void)
8eb3db
 		}
8eb3db
 	}
cc1db7
8eb3db
-	mok = get_cert_list(L"MokListRT", &mok_var, &moksize);
8eb3db
-	if (!mok) {
8eb3db
+	rc = get_cert_list(L"MokListRT", &mok_var, &moksize, &mok;;
8eb3db
+	if (rc < 0) {
cc1db7
 		pr_info("Couldn't get UEFI MokListRT\n");
8eb3db
-	} else {
8eb3db
+	} else if (moksize != 0) {
8eb3db
 		rc = parse_efi_signature_list("UEFI:MokListRT",
8eb3db
 					      mok, moksize, get_handler_for_db);
8eb3db
 		if (rc)
cc1db7
@@ -177,10 +184,10 @@ static int __init load_uefi_certs(void)
8eb3db
 		kfree(mok);
8eb3db
 	}
cc1db7
8eb3db
-	dbx = get_cert_list(L"dbx", &secure_var, &dbxsize);
8eb3db
-	if (!dbx) {
8eb3db
+	rc = get_cert_list(L"dbx", &secure_var, &dbxsize, &dbx;;
8eb3db
+	if (rc < 0) {
cc1db7
 		pr_info("Couldn't get UEFI dbx list\n");
8eb3db
-	} else {
8eb3db
+	} else if (dbxsize != 0) {
8eb3db
 		rc = parse_efi_signature_list("UEFI:dbx",
8eb3db
 					      dbx, dbxsize,
8eb3db
 					      get_handler_for_dbx);