arrfab / rpms / shim

Forked from rpms/shim 4 years ago
Clone

Blame SOURCES/0003-mok-consolidate-mirroring-code-in-a-helper-instead-o.patch

24a050
From 29c11483101b460869a5e0dba1f425073862127d Mon Sep 17 00:00:00 2001
24a050
From: Peter Jones <pjones@redhat.com>
24a050
Date: Thu, 31 Jan 2019 13:45:30 -0500
24a050
Subject: [PATCH 3/3] mok: consolidate mirroring code in a helper instead of
24a050
 using goto
24a050
24a050
There's no reason to complicate the logic with a goto here, instead just
24a050
pull the logic we're jumping to out to a helper function.
24a050
24a050
Signed-off-by: Peter Jones <pjones@redhat.com>
24a050
---
24a050
 mok.c  | 41 ++++++++++++++++++++++++++++-------------
24a050
 shim.h |  2 ++
24a050
 2 files changed, 30 insertions(+), 13 deletions(-)
24a050
24a050
diff --git a/mok.c b/mok.c
24a050
index 41925abbb49..2f495e6cf25 100644
24a050
--- a/mok.c
24a050
+++ b/mok.c
24a050
@@ -130,7 +130,8 @@ struct mok_state_variable mok_state_variables[] = {
24a050
 	{ NULL, }
24a050
 };
24a050
 
24a050
-static EFI_STATUS mirror_one_mok_variable(struct mok_state_variable *v)
24a050
+static EFI_STATUS nonnull(1)
24a050
+mirror_one_mok_variable(struct mok_state_variable *v)
24a050
 {
24a050
 	EFI_STATUS efi_status = EFI_SUCCESS;
24a050
 	void *FullData = NULL;
24a050
@@ -196,6 +197,29 @@ static EFI_STATUS mirror_one_mok_variable(struct mok_state_variable *v)
24a050
 	return efi_status;
24a050
 }
24a050
 
24a050
+/*
24a050
+ * Mirror a variable if it has an rtname, and preserve any
24a050
+ * EFI_SECURITY_VIOLATION status at the same time.
24a050
+ */
24a050
+static EFI_STATUS nonnull(1)
24a050
+maybe_mirror_one_mok_variable(struct mok_state_variable *v, EFI_STATUS ret)
24a050
+{
24a050
+	EFI_STATUS efi_status;
24a050
+	if (v->rtname) {
24a050
+		if (v->flags & MOK_MIRROR_DELETE_FIRST)
24a050
+			LibDeleteVariable(v->rtname, v->guid);
24a050
+
24a050
+		efi_status = mirror_one_mok_variable(v);
24a050
+		if (EFI_ERROR(efi_status)) {
24a050
+			if (ret != EFI_SECURITY_VIOLATION)
24a050
+				ret = efi_status;
24a050
+			perror(L"Could not create %s: %r\n", v->rtname,
24a050
+			       efi_status);
24a050
+		}
24a050
+	}
24a050
+	return ret;
24a050
+}
24a050
+
24a050
 /*
24a050
  * Verify our non-volatile MoK state.  This checks the variables above
24a050
  * accessable and have valid attributes.  If they don't, it removes
24a050
@@ -232,7 +256,7 @@ EFI_STATUS import_mok_state(EFI_HANDLE image_handle)
24a050
 					       *v->guid, &attrs);
24a050
 		if (efi_status == EFI_NOT_FOUND) {
24a050
 			if (addend)
24a050
-				goto mirror_addend;
24a050
+				ret = maybe_mirror_one_mok_variable(v, ret);
24a050
 			/*
24a050
 			 * after possibly adding, we can continue, no
24a050
 			 * further checks to be done.
24a050
@@ -312,16 +336,8 @@ EFI_STATUS import_mok_state(EFI_HANDLE image_handle)
24a050
 			}
24a050
 		}
24a050
 
24a050
-mirror_addend:
24a050
-		if (v->rtname && (present || addend)) {
24a050
-			if (v->flags & MOK_MIRROR_DELETE_FIRST)
24a050
-				LibDeleteVariable(v->rtname, v->guid);
24a050
-
24a050
-			efi_status = mirror_one_mok_variable(v);
24a050
-			if (EFI_ERROR(efi_status) &&
24a050
-			    ret != EFI_SECURITY_VIOLATION)
24a050
-				ret = efi_status;
24a050
-		}
24a050
+		if (present)
24a050
+			ret = maybe_mirror_one_mok_variable(v, ret);
24a050
 	}
24a050
 
24a050
 	/*
24a050
@@ -340,4 +356,4 @@ mirror_addend:
24a050
 	return ret;
24a050
 }
24a050
 
24a050
-// vim:fenc=utf-8:tw=75
24a050
+// vim:fenc=utf-8:tw=75:noet
24a050
diff --git a/shim.h b/shim.h
24a050
index 2b359d821e3..c26d5f06538 100644
24a050
--- a/shim.h
24a050
+++ b/shim.h
24a050
@@ -30,6 +30,8 @@
24a050
 
24a050
 #include <stddef.h>
24a050
 
24a050
+#define nonnull(...) __attribute__((__nonnull__(__VA_ARGS__)))
24a050
+
24a050
 #define min(a, b) ({(a) < (b) ? (a) : (b);})
24a050
 
24a050
 #ifdef __x86_64__
24a050
-- 
24a050
2.20.1
24a050