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

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