Blame SOURCES/0064-Fix-some-mokmanager-stuff.patch

ec51ad
From 18843127dc0eace16d43d479bd091e221e8785c4 Mon Sep 17 00:00:00 2001
ec51ad
From: Peter Jones <pjones@redhat.com>
ec51ad
Date: Mon, 17 Aug 2020 15:47:19 -0400
ec51ad
Subject: [PATCH] Fix some mokmanager stuff
ec51ad
ec51ad
---
ec51ad
 MokManager.c | 24 +++++++++++++++++++++++-
ec51ad
 Makefile     |  2 +-
ec51ad
 2 files changed, 24 insertions(+), 2 deletions(-)
ec51ad
ec51ad
diff --git a/MokManager.c b/MokManager.c
ec51ad
index c9949e33bcf..9bae3414fe7 100644
ec51ad
--- a/MokManager.c
ec51ad
+++ b/MokManager.c
ec51ad
@@ -9,6 +9,8 @@
ec51ad
 
ec51ad
 #include "shim.h"
ec51ad
 
ec51ad
+#include "hexdump.h"
ec51ad
+
ec51ad
 #define PASSWORD_MAX 256
ec51ad
 #define PASSWORD_MIN 1
ec51ad
 #define SB_PASSWORD_LEN 16
ec51ad
@@ -1050,9 +1052,11 @@ static EFI_STATUS mok_reset_prompt(BOOLEAN MokX)
ec51ad
 	if (MokX) {
ec51ad
 		LibDeleteVariable(L"MokXNew", &SHIM_LOCK_GUID);
ec51ad
 		LibDeleteVariable(L"MokXAuth", &SHIM_LOCK_GUID);
ec51ad
+		LibDeleteVariable(L"MokListX", &SHIM_LOCK_GUID);
ec51ad
 	} else {
ec51ad
 		LibDeleteVariable(L"MokNew", &SHIM_LOCK_GUID);
ec51ad
 		LibDeleteVariable(L"MokAuth", &SHIM_LOCK_GUID);
ec51ad
+		LibDeleteVariable(L"MokList", &SHIM_LOCK_GUID);
ec51ad
 	}
ec51ad
 
ec51ad
 	return EFI_SUCCESS;
ec51ad
@@ -1075,6 +1079,7 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
ec51ad
 	else
ec51ad
 		db_name = L"MokList";
ec51ad
 
ec51ad
+	dprint(L"Writing back %s (%d entries)\n", db_name, key_num);
ec51ad
 	for (i = 0; i < key_num; i++) {
ec51ad
 		if (list[i].Mok == NULL)
ec51ad
 			continue;
ec51ad
@@ -1085,8 +1090,15 @@ static EFI_STATUS write_back_mok_list(MokListNode * list, INTN key_num,
ec51ad
 			DataSize += sizeof(EFI_GUID);
ec51ad
 		DataSize += list[i].MokSize;
ec51ad
 	}
ec51ad
-	if (DataSize == 0)
ec51ad
+	if (DataSize == 0) {
ec51ad
+		dprint(L"DataSize = 0; deleting variable %s\n", db_name);
ec51ad
+		efi_status = gRT->SetVariable(db_name, &SHIM_LOCK_GUID,
ec51ad
+					      EFI_VARIABLE_NON_VOLATILE |
ec51ad
+					      EFI_VARIABLE_BOOTSERVICE_ACCESS,
ec51ad
+					      DataSize, Data);
ec51ad
+		dprint(L"efi_status:%llu\n", efi_status);
ec51ad
 		return EFI_SUCCESS;
ec51ad
+	}
ec51ad
 
ec51ad
 	Data = AllocatePool(DataSize);
ec51ad
 	if (Data == NULL)
ec51ad
@@ -1291,11 +1303,15 @@ static EFI_STATUS delete_keys(void *MokDel, UINTN MokDelSize, BOOLEAN MokX)
ec51ad
 	}
ec51ad
 
ec51ad
 	if (auth_size == PASSWORD_CRYPT_SIZE) {
ec51ad
+		dprint(L"matching password with CRYPT");
ec51ad
 		efi_status = match_password((PASSWORD_CRYPT *) auth, NULL, 0,
ec51ad
 					    NULL, NULL);
ec51ad
+		dprint(L"match_password(0x%llx, NULL, 0, NULL, NULL) = %lu\n", auth, efi_status);
ec51ad
 	} else {
ec51ad
+		dprint(L"matching password as sha256sum");
ec51ad
 		efi_status =
ec51ad
 		    match_password(NULL, MokDel, MokDelSize, auth, NULL);
ec51ad
+		dprint(L"match_password(NULL, 0x%llx, %llu, 0x%llx, NULL) = %lu\n", MokDel, MokDelSize, auth, efi_status);
ec51ad
 	}
ec51ad
 	if (EFI_ERROR(efi_status))
ec51ad
 		return EFI_ACCESS_DENIED;
ec51ad
@@ -1365,12 +1381,17 @@ static EFI_STATUS delete_keys(void *MokDel, UINTN MokDelSize, BOOLEAN MokX)
ec51ad
 	}
ec51ad
 
ec51ad
 	/* Search and destroy */
ec51ad
+	dprint(L"deleting certs from %a\n", MokX ? "MokListX" : "MokList");
ec51ad
 	for (i = 0; i < del_num; i++) {
ec51ad
 		type = del_key[i].Type; /* avoid -Werror=address-of-packed-member */
ec51ad
 		if (CompareGuid(&type, &X509_GUID) == 0) {
ec51ad
+			dprint(L"deleting key %d (total %d):\n", i, mok_num);
ec51ad
+			dhexdumpat(del_key[i].Mok, del_key[i].MokSize, 0);
ec51ad
 			delete_cert(del_key[i].Mok, del_key[i].MokSize,
ec51ad
 				    mok, mok_num);
ec51ad
 		} else if (is_sha2_hash(del_key[i].Type)) {
ec51ad
+			dprint(L"deleting hash %d (total %d):\n", i, mok_num);
ec51ad
+			dhexdumpat(del_key[i].Mok, del_key[i].MokSize, 0);
ec51ad
 			delete_hash_list(del_key[i].Type, del_key[i].Mok,
ec51ad
 					 del_key[i].MokSize, mok, mok_num);
ec51ad
 		}
ec51ad
@@ -2564,6 +2585,7 @@ EFI_STATUS efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE * systab)
ec51ad
 
ec51ad
 	InitializeLib(image_handle, systab);
ec51ad
 
ec51ad
+	setup_verbosity();
ec51ad
 	setup_rand();
ec51ad
 
ec51ad
 	console_mode_handle();
ec51ad
diff --git a/Makefile b/Makefile
ec51ad
index 49e14a26521..a17fa2bef14 100644
ec51ad
--- a/Makefile
ec51ad
+++ b/Makefile
ec51ad
@@ -36,7 +36,7 @@ endif
ec51ad
 OBJS	= shim.o mok.o netboot.o cert.o replacements.o tpm.o version.o errlog.o
ec51ad
 KEYS	= shim_cert.h ocsp.* ca.* shim.crt shim.csr shim.p12 shim.pem shim.key shim.cer
ec51ad
 ORIG_SOURCES	= shim.c mok.c netboot.c replacements.c tpm.c errlog.c shim.h version.h $(wildcard include/*.h)
ec51ad
-MOK_OBJS = MokManager.o PasswordCrypt.o crypt_blowfish.o
ec51ad
+MOK_OBJS = MokManager.o PasswordCrypt.o crypt_blowfish.o errlog.o
ec51ad
 ORIG_MOK_SOURCES = MokManager.c PasswordCrypt.c crypt_blowfish.c shim.h $(wildcard include/*.h)
ec51ad
 FALLBACK_OBJS = fallback.o tpm.o errlog.o
ec51ad
 ORIG_FALLBACK_SRCS = fallback.c
ec51ad
-- 
ec51ad
2.26.2
ec51ad