|
|
00e791 |
From 3d62232feb296b238ca5d7963ba40a2c346767e7 Mon Sep 17 00:00:00 2001
|
|
|
00e791 |
From: Gary Lin <glin@suse.com>
|
|
|
00e791 |
Date: Wed, 19 Dec 2018 12:40:02 +0800
|
|
|
00e791 |
Subject: [PATCH 24/62] mok: also mirror the build cert to MokListRT
|
|
|
00e791 |
|
|
|
00e791 |
If the build cert is enabled, we should also mirror it to MokListRT.
|
|
|
00e791 |
|
|
|
00e791 |
Signed-off-by: Gary Lin <glin@suse.com>
|
|
|
00e791 |
Upstream-commit-id: aecbe1f99b6
|
|
|
00e791 |
---
|
|
|
00e791 |
mok.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
|
|
|
00e791 |
1 file changed, 72 insertions(+), 6 deletions(-)
|
|
|
00e791 |
|
|
|
00e791 |
diff --git a/mok.c b/mok.c
|
|
|
00e791 |
index 2b9d796a0e8..6150d8c8868 100644
|
|
|
00e791 |
--- a/mok.c
|
|
|
00e791 |
+++ b/mok.c
|
|
|
00e791 |
@@ -68,6 +68,10 @@ struct mok_state_variable {
|
|
|
00e791 |
*/
|
|
|
00e791 |
UINT8 **addend_source;
|
|
|
00e791 |
UINT32 *addend_size;
|
|
|
00e791 |
+#if defined(ENABLE_SHIM_CERT)
|
|
|
00e791 |
+ UINT8 **build_cert;
|
|
|
00e791 |
+ UINT32 *build_cert_size;
|
|
|
00e791 |
+#endif /* defined(ENABLE_SHIM_CERT) */
|
|
|
00e791 |
UINT32 yes_attr;
|
|
|
00e791 |
UINT32 no_attr;
|
|
|
00e791 |
UINT32 flags;
|
|
|
00e791 |
@@ -90,6 +94,10 @@ struct mok_state_variable mok_state_variables[] = {
|
|
|
00e791 |
.no_attr = EFI_VARIABLE_RUNTIME_ACCESS,
|
|
|
00e791 |
.addend_source = &vendor_cert,
|
|
|
00e791 |
.addend_size = &vendor_cert_size,
|
|
|
00e791 |
+#if defined(ENABLE_SHIM_CERT)
|
|
|
00e791 |
+ .build_cert = &build_cert,
|
|
|
00e791 |
+ .build_cert_size = &build_cert_size,
|
|
|
00e791 |
+#endif /* defined(ENABLE_SHIM_CERT) */
|
|
|
00e791 |
.flags = MOK_MIRROR_KEYDB |
|
|
|
00e791 |
MOK_VARIABLE_LOG,
|
|
|
00e791 |
.pcr = 14,
|
|
|
00e791 |
@@ -130,6 +138,22 @@ struct mok_state_variable mok_state_variables[] = {
|
|
|
00e791 |
{ NULL, }
|
|
|
00e791 |
};
|
|
|
00e791 |
|
|
|
00e791 |
+inline BOOLEAN check_vendor_cert(struct mok_state_variable *v)
|
|
|
00e791 |
+{
|
|
|
00e791 |
+ return (v->addend_source && v->addend_size &&
|
|
|
00e791 |
+ *v->addend_source && *v->addend_size) ? TRUE : FALSE;
|
|
|
00e791 |
+}
|
|
|
00e791 |
+#if defined(ENABLE_SHIM_CERT)
|
|
|
00e791 |
+inline BOOLEAN check_build_cert(struct mok_state_variable *v)
|
|
|
00e791 |
+{
|
|
|
00e791 |
+ return (v->build_cert && v->build_cert_size &&
|
|
|
00e791 |
+ *v->build_cert && *v->build_cert_size) ? TRUE : FALSE;
|
|
|
00e791 |
+}
|
|
|
00e791 |
+#define check_addend(v) (check_vendor_cert(v) || check_build_cert(v))
|
|
|
00e791 |
+#else
|
|
|
00e791 |
+#define check_addend(v) check_vendor_cert(v)
|
|
|
00e791 |
+#endif /* defined(ENABLE_SHIM_CERT) */
|
|
|
00e791 |
+
|
|
|
00e791 |
static EFI_STATUS nonnull(1)
|
|
|
00e791 |
mirror_one_mok_variable(struct mok_state_variable *v)
|
|
|
00e791 |
{
|
|
|
00e791 |
@@ -138,15 +162,27 @@ mirror_one_mok_variable(struct mok_state_variable *v)
|
|
|
00e791 |
UINTN FullDataSize = 0;
|
|
|
00e791 |
uint8_t *p = NULL;
|
|
|
00e791 |
|
|
|
00e791 |
- if ((v->flags & MOK_MIRROR_KEYDB) &&
|
|
|
00e791 |
- v->addend_source && *v->addend_source &&
|
|
|
00e791 |
- v->addend_size && *v->addend_size) {
|
|
|
00e791 |
+ if ((v->flags & MOK_MIRROR_KEYDB) && check_addend(v)) {
|
|
|
00e791 |
EFI_SIGNATURE_LIST *CertList = NULL;
|
|
|
00e791 |
EFI_SIGNATURE_DATA *CertData = NULL;
|
|
|
00e791 |
+#if defined(ENABLE_SHIM_CERT)
|
|
|
00e791 |
+ FullDataSize = v->data_size;
|
|
|
00e791 |
+ if (check_build_cert(v)) {
|
|
|
00e791 |
+ FullDataSize += sizeof (*CertList)
|
|
|
00e791 |
+ + sizeof (EFI_GUID)
|
|
|
00e791 |
+ + *v->build_cert_size;
|
|
|
00e791 |
+ }
|
|
|
00e791 |
+ if (check_vendor_cert(v)) {
|
|
|
00e791 |
+ FullDataSize += sizeof (*CertList)
|
|
|
00e791 |
+ + sizeof (EFI_GUID)
|
|
|
00e791 |
+ + *v->addend_size;
|
|
|
00e791 |
+ }
|
|
|
00e791 |
+#else
|
|
|
00e791 |
FullDataSize = v->data_size
|
|
|
00e791 |
+ sizeof (*CertList)
|
|
|
00e791 |
+ sizeof (EFI_GUID)
|
|
|
00e791 |
+ *v->addend_size;
|
|
|
00e791 |
+#endif /* defined(ENABLE_SHIM_CERT) */
|
|
|
00e791 |
FullData = AllocatePool(FullDataSize);
|
|
|
00e791 |
if (!FullData) {
|
|
|
00e791 |
perror(L"Failed to allocate space for MokListRT\n");
|
|
|
00e791 |
@@ -158,6 +194,35 @@ mirror_one_mok_variable(struct mok_state_variable *v)
|
|
|
00e791 |
CopyMem(p, v->data, v->data_size);
|
|
|
00e791 |
p += v->data_size;
|
|
|
00e791 |
}
|
|
|
00e791 |
+
|
|
|
00e791 |
+#if defined(ENABLE_SHIM_CERT)
|
|
|
00e791 |
+ if (check_build_cert(v) == FALSE)
|
|
|
00e791 |
+ goto skip_build_cert;
|
|
|
00e791 |
+
|
|
|
00e791 |
+ CertList = (EFI_SIGNATURE_LIST *)p;
|
|
|
00e791 |
+ p += sizeof (*CertList);
|
|
|
00e791 |
+ CertData = (EFI_SIGNATURE_DATA *)p;
|
|
|
00e791 |
+ p += sizeof (EFI_GUID);
|
|
|
00e791 |
+
|
|
|
00e791 |
+ CertList->SignatureType = EFI_CERT_TYPE_X509_GUID;
|
|
|
00e791 |
+ CertList->SignatureListSize = *v->build_cert_size
|
|
|
00e791 |
+ + sizeof (*CertList)
|
|
|
00e791 |
+ + sizeof (*CertData)
|
|
|
00e791 |
+ -1;
|
|
|
00e791 |
+ CertList->SignatureHeaderSize = 0;
|
|
|
00e791 |
+ CertList->SignatureSize = *v->build_cert_size +
|
|
|
00e791 |
+ sizeof (EFI_GUID);
|
|
|
00e791 |
+
|
|
|
00e791 |
+ CertData->SignatureOwner = SHIM_LOCK_GUID;
|
|
|
00e791 |
+ CopyMem(p, *v->build_cert, *v->build_cert_size);
|
|
|
00e791 |
+
|
|
|
00e791 |
+ p += *v->build_cert_size;
|
|
|
00e791 |
+
|
|
|
00e791 |
+ if (check_vendor_cert(v) == FALSE)
|
|
|
00e791 |
+ goto skip_vendor_cert;
|
|
|
00e791 |
+skip_build_cert:
|
|
|
00e791 |
+#endif /* defined(ENABLE_SHIM_CERT) */
|
|
|
00e791 |
+
|
|
|
00e791 |
CertList = (EFI_SIGNATURE_LIST *)p;
|
|
|
00e791 |
p += sizeof (*CertList);
|
|
|
00e791 |
CertData = (EFI_SIGNATURE_DATA *)p;
|
|
|
00e791 |
@@ -174,6 +239,9 @@ mirror_one_mok_variable(struct mok_state_variable *v)
|
|
|
00e791 |
CertData->SignatureOwner = SHIM_LOCK_GUID;
|
|
|
00e791 |
CopyMem(p, *v->addend_source, *v->addend_size);
|
|
|
00e791 |
|
|
|
00e791 |
+#if defined(ENABLE_SHIM_CERT)
|
|
|
00e791 |
+skip_vendor_cert:
|
|
|
00e791 |
+#endif /* defined(ENABLE_SHIM_CERT) */
|
|
|
00e791 |
if (v->data && v->data_size)
|
|
|
00e791 |
FreePool(v->data);
|
|
|
00e791 |
v->data = FullData;
|
|
|
00e791 |
@@ -247,9 +315,7 @@ EFI_STATUS import_mok_state(EFI_HANDLE image_handle)
|
|
|
00e791 |
UINT32 attrs = 0;
|
|
|
00e791 |
BOOLEAN delete = FALSE, present, addend;
|
|
|
00e791 |
|
|
|
00e791 |
- addend = (v->addend_source && v->addend_size &&
|
|
|
00e791 |
- *v->addend_source && *v->addend_size)
|
|
|
00e791 |
- ? TRUE : FALSE;
|
|
|
00e791 |
+ addend = check_addend(v);
|
|
|
00e791 |
|
|
|
00e791 |
efi_status = get_variable_attr(v->name,
|
|
|
00e791 |
&v->data, &v->data_size,
|
|
|
00e791 |
--
|
|
|
00e791 |
2.26.2
|
|
|
00e791 |
|