fanghuilin / rpms / kernel

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