Blame SOURCES/0056-Make-cert.S-not-impossible-to-read.patch

d1e1c8
From 7d542805ba5c48185128a2351bb315a5648fe3d7 Mon Sep 17 00:00:00 2001
d1e1c8
From: Peter Jones <pjones@redhat.com>
d1e1c8
Date: Thu, 23 Jul 2020 00:08:30 -0400
d1e1c8
Subject: [PATCH 56/62] Make cert.S not impossible to read.
d1e1c8
d1e1c8
Signed-off-by: Peter Jones <pjones@redhat.com>
d1e1c8
Upstream: pr#206
d1e1c8
---
d1e1c8
 shim.c | 47 +++++++++++++++++--------------
d1e1c8
 shim.h | 28 +++++++++++++++---
d1e1c8
 cert.S | 89 ++++++++++++++++++++++------------------------------------
d1e1c8
 3 files changed, 84 insertions(+), 80 deletions(-)
d1e1c8
d1e1c8
diff --git a/shim.c b/shim.c
d1e1c8
index 0e7e784b4c8..888ee6e8d7b 100644
d1e1c8
--- a/shim.c
d1e1c8
+++ b/shim.c
d1e1c8
@@ -68,16 +68,18 @@ static UINT32 load_options_size;
d1e1c8
  * The vendor certificate used for validating the second stage loader
d1e1c8
  */
d1e1c8
 extern struct {
d1e1c8
-	UINT32 vendor_cert_size;
d1e1c8
-	UINT32 vendor_dbx_size;
d1e1c8
-	UINT32 vendor_cert_offset;
d1e1c8
-	UINT32 vendor_dbx_offset;
d1e1c8
+	UINT32 vendor_authorized_size;
d1e1c8
+	UINT32 vendor_deauthorized_size;
d1e1c8
+	UINT32 vendor_authorized_offset;
d1e1c8
+	UINT32 vendor_deauthorized_offset;
d1e1c8
 } cert_table;
d1e1c8
 
d1e1c8
-UINT32 vendor_cert_size;
d1e1c8
-UINT32 vendor_dbx_size;
d1e1c8
-UINT8 *vendor_cert;
d1e1c8
-UINT8 *vendor_dbx;
d1e1c8
+UINT32 vendor_authorized_size = 0;
d1e1c8
+UINT8 *vendor_authorized = NULL;
d1e1c8
+
d1e1c8
+UINT32 vendor_deauthorized_size = 0;
d1e1c8
+UINT8 *vendor_deauthorized = NULL;
d1e1c8
+
d1e1c8
 #if defined(ENABLE_SHIM_CERT)
d1e1c8
 UINT32 build_cert_size;
d1e1c8
 UINT8 *build_cert;
d1e1c8
@@ -554,22 +556,22 @@ static CHECK_STATUS check_db_hash(CHAR16 *dbname, EFI_GUID guid, UINT8 *data,
d1e1c8
 static EFI_STATUS check_blacklist (WIN_CERTIFICATE_EFI_PKCS *cert,
d1e1c8
 				   UINT8 *sha256hash, UINT8 *sha1hash)
d1e1c8
 {
d1e1c8
-	EFI_SIGNATURE_LIST *dbx = (EFI_SIGNATURE_LIST *)vendor_dbx;
d1e1c8
+	EFI_SIGNATURE_LIST *dbx = (EFI_SIGNATURE_LIST *)vendor_deauthorized;
d1e1c8
 
d1e1c8
-	if (check_db_hash_in_ram(dbx, vendor_dbx_size, sha256hash,
d1e1c8
+	if (check_db_hash_in_ram(dbx, vendor_deauthorized_size, sha256hash,
d1e1c8
 			SHA256_DIGEST_SIZE, EFI_CERT_SHA256_GUID, L"dbx",
d1e1c8
 			EFI_SECURE_BOOT_DB_GUID) == DATA_FOUND) {
d1e1c8
 		LogError(L"binary sha256hash found in vendor dbx\n");
d1e1c8
 		return EFI_SECURITY_VIOLATION;
d1e1c8
 	}
d1e1c8
-	if (check_db_hash_in_ram(dbx, vendor_dbx_size, sha1hash,
d1e1c8
+	if (check_db_hash_in_ram(dbx, vendor_deauthorized_size, sha1hash,
d1e1c8
 				 SHA1_DIGEST_SIZE, EFI_CERT_SHA1_GUID, L"dbx",
d1e1c8
 				 EFI_SECURE_BOOT_DB_GUID) == DATA_FOUND) {
d1e1c8
 		LogError(L"binary sha1hash found in vendor dbx\n");
d1e1c8
 		return EFI_SECURITY_VIOLATION;
d1e1c8
 	}
d1e1c8
 	if (cert &&
d1e1c8
-	    check_db_cert_in_ram(dbx, vendor_dbx_size, cert, sha256hash, L"dbx",
d1e1c8
+	    check_db_cert_in_ram(dbx, vendor_deauthorized_size, cert, sha256hash, L"dbx",
d1e1c8
 				 EFI_SECURE_BOOT_DB_GUID) == DATA_FOUND) {
d1e1c8
 		LogError(L"cert sha256hash found in vendor dbx\n");
d1e1c8
 		return EFI_SECURITY_VIOLATION;
d1e1c8
@@ -1077,19 +1079,19 @@ static EFI_STATUS verify_buffer (char *data, int datasize,
d1e1c8
 		/*
d1e1c8
 		 * And finally, check against shim's built-in key
d1e1c8
 		 */
d1e1c8
-		if (vendor_cert_size &&
d1e1c8
+		if (vendor_authorized_size &&
d1e1c8
 		    AuthenticodeVerify(cert->CertData,
d1e1c8
 				       cert->Hdr.dwLength - sizeof(cert->Hdr),
d1e1c8
-				       vendor_cert, vendor_cert_size,
d1e1c8
+				       vendor_authorized, vendor_authorized_size,
d1e1c8
 				       sha256hash, SHA256_DIGEST_SIZE)) {
d1e1c8
 			update_verification_method(VERIFIED_BY_CERT);
d1e1c8
 			tpm_measure_variable(L"Shim", SHIM_LOCK_GUID,
d1e1c8
-					     vendor_cert_size, vendor_cert);
d1e1c8
+					     vendor_authorized_size, vendor_authorized);
d1e1c8
 			efi_status = EFI_SUCCESS;
d1e1c8
 			drain_openssl_errors();
d1e1c8
 			return efi_status;
d1e1c8
 		} else {
d1e1c8
-			LogError(L"AuthenticodeVerify(vendor_cert) failed\n");
d1e1c8
+			LogError(L"AuthenticodeVerify(vendor_authorized) failed\n");
d1e1c8
 		}
d1e1c8
 	}
d1e1c8
 
d1e1c8
@@ -2501,7 +2503,7 @@ shim_init(void)
d1e1c8
 	}
d1e1c8
 
d1e1c8
 	if (secure_mode()) {
d1e1c8
-		if (vendor_cert_size || vendor_dbx_size) {
d1e1c8
+		if (vendor_authorized_size || vendor_deauthorized_size) {
d1e1c8
 			/*
d1e1c8
 			 * If shim includes its own certificates then ensure
d1e1c8
 			 * that anything it boots has performed some
d1e1c8
@@ -2606,14 +2608,17 @@ efi_main (EFI_HANDLE passed_image_handle, EFI_SYSTEM_TABLE *passed_systab)
d1e1c8
 
d1e1c8
 	verification_method = VERIFIED_BY_NOTHING;
d1e1c8
 
d1e1c8
-	vendor_cert_size = cert_table.vendor_cert_size;
d1e1c8
-	vendor_dbx_size = cert_table.vendor_dbx_size;
d1e1c8
-	vendor_cert = (UINT8 *)&cert_table + cert_table.vendor_cert_offset;
d1e1c8
-	vendor_dbx = (UINT8 *)&cert_table + cert_table.vendor_dbx_offset;
d1e1c8
+	vendor_authorized_size = cert_table.vendor_authorized_size;
d1e1c8
+	vendor_authorized = (UINT8 *)&cert_table + cert_table.vendor_authorized_offset;
d1e1c8
+
d1e1c8
+	vendor_deauthorized_size = cert_table.vendor_deauthorized_size;
d1e1c8
+	vendor_deauthorized = (UINT8 *)&cert_table + cert_table.vendor_deauthorized_offset;
d1e1c8
+
d1e1c8
 #if defined(ENABLE_SHIM_CERT)
d1e1c8
 	build_cert_size = sizeof(shim_cert);
d1e1c8
 	build_cert = shim_cert;
d1e1c8
 #endif /* defined(ENABLE_SHIM_CERT) */
d1e1c8
+
d1e1c8
 	CHAR16 *msgs[] = {
d1e1c8
 		L"import_mok_state() failed",
d1e1c8
 		L"shim_init() failed",
d1e1c8
diff --git a/shim.h b/shim.h
d1e1c8
index a0fa5a75e7e..555498c6673 100644
d1e1c8
--- a/shim.h
d1e1c8
+++ b/shim.h
d1e1c8
@@ -97,6 +97,24 @@
d1e1c8
 #define FALLBACK L"\\fb" EFI_ARCH L".efi"
d1e1c8
 #define MOK_MANAGER L"\\mm" EFI_ARCH L".efi"
d1e1c8
 
d1e1c8
+#if defined(VENDOR_CERT_FILE)
d1e1c8
+# define vendor_authorized vendor_cert
d1e1c8
+# define vendor_authorized_size vendor_cert_size
d1e1c8
+# define vendor_authorized_category VENDOR_ADDEND_X509
d1e1c8
+#else
d1e1c8
+# define vendor_authorized vendor_null
d1e1c8
+# define vendor_authorized_size vendor_null_size
d1e1c8
+# define vendor_authorized_category VENDOR_ADDEND_NONE
d1e1c8
+#endif
d1e1c8
+
d1e1c8
+#if defined(VENDOR_DBX_FILE)
d1e1c8
+# define vendor_deauthorized vendor_dbx
d1e1c8
+# define vendor_deauthorized_size vendor_dbx_size
d1e1c8
+#else
d1e1c8
+# define vendor_deauthorized vendor_deauthorized_null
d1e1c8
+# define vendor_deauthorized_size vendor_deauthorized_null_size
d1e1c8
+#endif
d1e1c8
+
d1e1c8
 #include "include/asm.h"
d1e1c8
 #include "include/configtable.h"
d1e1c8
 #include "include/console.h"
d1e1c8
@@ -166,10 +184,12 @@ extern VOID ClearErrors(VOID);
d1e1c8
 extern EFI_STATUS start_image(EFI_HANDLE image_handle, CHAR16 *ImagePath);
d1e1c8
 extern EFI_STATUS import_mok_state(EFI_HANDLE image_handle);
d1e1c8
 
d1e1c8
-extern UINT32 vendor_cert_size;
d1e1c8
-extern UINT32 vendor_dbx_size;
d1e1c8
-extern UINT8 *vendor_cert;
d1e1c8
-extern UINT8 *vendor_dbx;
d1e1c8
+extern UINT32 vendor_authorized_size;
d1e1c8
+extern UINT8 *vendor_authorized;
d1e1c8
+
d1e1c8
+extern UINT32 vendor_deauthorized_size;
d1e1c8
+extern UINT8 *vendor_deauthorized;
d1e1c8
+
d1e1c8
 #if defined(ENABLE_SHIM_CERT)
d1e1c8
 extern UINT32 build_cert_size;
d1e1c8
 extern UINT8 *build_cert;
d1e1c8
diff --git a/cert.S b/cert.S
d1e1c8
index cfc4525b44c..520caaef3af 100644
d1e1c8
--- a/cert.S
d1e1c8
+++ b/cert.S
d1e1c8
@@ -1,65 +1,44 @@
d1e1c8
+
d1e1c8
+#if defined(VENDOR_CERT_FILE)
d1e1c8
+# define vendor_authorized vendor_cert
d1e1c8
+# define vendor_authorized_end vendor_cert_end
d1e1c8
+# define vendor_authorized_size vendor_cert_size
d1e1c8
+# define vendor_authorized_size_end vendor_cert_size_end
d1e1c8
+#endif
d1e1c8
+
d1e1c8
+#if defined(VENDOR_DBX_FILE)
d1e1c8
+# define vendor_deauthorized vendor_dbx
d1e1c8
+# define vendor_deauthorized_end vendor_dbx_end
d1e1c8
+# define vendor_deauthorized_size vendor_dbx_size
d1e1c8
+# define vendor_deauthorized_size_end vendor_dbx_size_end
d1e1c8
+#endif
d1e1c8
+
d1e1c8
 	.globl cert_table
d1e1c8
 	.type	cert_table, %object
d1e1c8
-	.size	cert_table, 4
d1e1c8
+	.size	cert_table, .Lcert_table_end - cert_table
d1e1c8
 	.section .vendor_cert, "a", %progbits
d1e1c8
+	.balignl 4, 0
d1e1c8
 cert_table:
d1e1c8
-#if defined(VENDOR_CERT_FILE)
d1e1c8
-	.long	vendor_cert_priv_end - vendor_cert_priv
d1e1c8
-#else
d1e1c8
-	.long	0
d1e1c8
-#endif
d1e1c8
-#if defined(VENDOR_DBX_FILE)
d1e1c8
-	.long	vendor_dbx_priv_end - vendor_dbx_priv
d1e1c8
-#else
d1e1c8
-	.long	0
d1e1c8
-#endif
d1e1c8
-	.long	vendor_cert_priv - cert_table
d1e1c8
-	.long	vendor_dbx_priv - cert_table
d1e1c8
-#if defined(VENDOR_CERT_FILE)
d1e1c8
-	.data
d1e1c8
-	.align	1
d1e1c8
-	.type	vendor_cert_priv, %object
d1e1c8
-	.size	vendor_cert_priv, vendor_cert_priv_end-vendor_cert_priv
d1e1c8
+	.4byte	.Lvendor_authorized_end - vendor_authorized
d1e1c8
+	.4byte	.Lvendor_deauthorized_end - vendor_deauthorized
d1e1c8
+	.4byte	vendor_authorized - cert_table
d1e1c8
+	.4byte	vendor_deauthorized - cert_table
d1e1c8
+	.balign	1, 0
d1e1c8
+	.type	vendor_authorized, %object
d1e1c8
+	.size	vendor_authorized, .Lvendor_authorized_end - vendor_authorized
d1e1c8
 	.section .vendor_cert, "a", %progbits
d1e1c8
-vendor_cert_priv:
d1e1c8
+vendor_authorized:
d1e1c8
+#if defined(VENDOR_CERT_FILE)
d1e1c8
 .incbin VENDOR_CERT_FILE
d1e1c8
-vendor_cert_priv_end:
d1e1c8
-#else
d1e1c8
-	.bss
d1e1c8
-	.type	vendor_cert_priv, %object
d1e1c8
-	.size	vendor_cert_priv, 1
d1e1c8
-	.section .vendor_cert, "a", %progbits
d1e1c8
-vendor_cert_priv:
d1e1c8
-	.zero	1
d1e1c8
-
d1e1c8
-	.data
d1e1c8
-	.align 4
d1e1c8
-	.type	vendor_cert_size_priv, %object
d1e1c8
-	.size	vendor_cert_size_priv, 4
d1e1c8
-	.section .vendor_cert, "a", %progbits
d1e1c8
-vendor_cert_priv_end:
d1e1c8
 #endif
d1e1c8
+.Lvendor_authorized_end:
d1e1c8
+	.balign	1, 0
d1e1c8
+	.type	vendor_deauthorized, %object
d1e1c8
+	.size	vendor_deauthorized, .Lvendor_deauthorized_end - vendor_deauthorized
d1e1c8
+	.section .vendor_cert, "a", %progbits
d1e1c8
+vendor_deauthorized:
d1e1c8
 #if defined(VENDOR_DBX_FILE)
d1e1c8
-	.data
d1e1c8
-	.align	1
d1e1c8
-	.type	vendor_dbx_priv, %object
d1e1c8
-	.size	vendor_dbx_priv, vendor_dbx_priv_end-vendor_dbx_priv
d1e1c8
-	.section .vendor_cert, "a", %progbits
d1e1c8
-vendor_dbx_priv:
d1e1c8
 .incbin VENDOR_DBX_FILE
d1e1c8
-vendor_dbx_priv_end:
d1e1c8
-#else
d1e1c8
-	.bss
d1e1c8
-	.type	vendor_dbx_priv, %object
d1e1c8
-	.size	vendor_dbx_priv, 1
d1e1c8
-	.section .vendor_cert, "a", %progbits
d1e1c8
-vendor_dbx_priv:
d1e1c8
-	.zero	1
d1e1c8
-
d1e1c8
-	.data
d1e1c8
-	.align 4
d1e1c8
-	.type	vendor_dbx_size_priv, %object
d1e1c8
-	.size	vendor_dbx_size_priv, 4
d1e1c8
-	.section .vendor_cert, "a", %progbits
d1e1c8
-vendor_dbx_priv_end:
d1e1c8
 #endif
d1e1c8
+.Lvendor_deauthorized_end:
d1e1c8
+.Lcert_table_end:
d1e1c8
-- 
d1e1c8
2.26.2
d1e1c8