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

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