pgreco / rpms / kernel

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