[PATCH v5 11/12] integrity: Trust MOK keys if MokListTrustedRT found
From: Eric Snowberg
Date: Tue Sep 07 2021 - 12:03:49 EST
A new Machine Owner Key (MOK) variable called MokListTrustedRT has been
introduced in shim. When this UEFI variable is set, it indicates the
end-user has made the decision themself that they wish to trust MOK keys
within the Linux trust boundary. It is not an error if this variable
does not exist. If it does not exist, the MOK keys should not be trusted
within the kernel.
MOK variables are mirrored from Boot Services to Runtime Services. When
shim sees the new MokTML BS variable, it will create a new variable
(before Exit Boot Services is called) called MokListTrustedRT without
EFI_VARIABLE_NON_VOLATILE set. Following Exit Boot Services, UEFI
variables can only be set and created with SetVariable if both
EFI_VARIABLE_RUNTIME_ACCESS & EFI_VARIABLE_NON_VOLATILE are set.
Therefore, this can not be defeated by simply creating a
MokListTrustedRT variable from Linux, the existence of
EFI_VARIABLE_NON_VOLATILE will cause uefi_check_trust_machine_keys to
return false.
Signed-off-by: Eric Snowberg <eric.snowberg@xxxxxxxxxx>
---
v1: Initial version
v2: Removed mok_keyring_trust_setup function
v4: Unmodified from v2
v5: Rename to machine keyring
---
.../platform_certs/machine_keyring.c | 27 +++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/security/integrity/platform_certs/machine_keyring.c b/security/integrity/platform_certs/machine_keyring.c
index 948ec6c738c8..635ab2b9e289 100644
--- a/security/integrity/platform_certs/machine_keyring.c
+++ b/security/integrity/platform_certs/machine_keyring.c
@@ -5,6 +5,7 @@
* Copyright (c) 2021, Oracle and/or its affiliates.
*/
+#include <linux/efi.h>
#include "../integrity.h"
static __init int machine_keyring_init(void)
@@ -40,3 +41,29 @@ void __init add_to_machine_keyring(const char *source, const void *data, size_t
if (rc)
pr_info("Error adding keys to machine keyring %s\n", source);
}
+
+/*
+ * Try to load the MokListTrustedRT UEFI variable to see if we should trust
+ * the mok keys within the kernel. It is not an error if this variable
+ * does not exist. If it does not exist, mok keys should not be trusted
+ * within the machine keyring.
+ */
+static __init bool uefi_check_trust_mok_keys(void)
+{
+ efi_status_t status;
+ unsigned int mtrust = 0;
+ unsigned long size = sizeof(mtrust);
+ efi_guid_t guid = EFI_SHIM_LOCK_GUID;
+ u32 attr;
+
+ status = efi.get_variable(L"MokListTrustedRT", &guid, &attr, &size, &mtrust);
+
+ /*
+ * The EFI_VARIABLE_NON_VOLATILE check is to verify MokListTrustedRT
+ * was set thru shim mirrioring and not by a user from the host os.
+ * According to the UEFI spec, once EBS is performed, SetVariable()
+ * will succeed only when both EFI_VARIABLE_RUNTIME_ACCESS &
+ * EFI_VARIABLE_NON_VOLATILE are set.
+ */
+ return (status == EFI_SUCCESS && (!(attr & EFI_VARIABLE_NON_VOLATILE)));
+}
--
2.18.4