zwp10758 / rpms / kernel

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