1 // SPDX-License-Identifier: GPL-2.0
3 * Machine keyring routines.
5 * Copyright (c) 2021, Oracle and/or its affiliates.
9 #include "../integrity.h"
11 static bool trust_mok;
13 static __init int machine_keyring_init(void)
17 rc = integrity_init_keyring(INTEGRITY_KEYRING_MACHINE);
21 pr_notice("Machine keyring initialized\n");
24 device_initcall(machine_keyring_init);
26 void __init add_to_machine_keyring(const char *source, const void *data, size_t len)
31 perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW;
32 rc = integrity_load_cert(INTEGRITY_KEYRING_MACHINE, source, data, len, perm);
35 * Some MOKList keys may not pass the machine keyring restrictions.
36 * If the restriction check does not pass and the platform keyring
37 * is configured, try to add it into that keyring instead.
39 if (rc && IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING))
40 rc = integrity_load_cert(INTEGRITY_KEYRING_PLATFORM, source,
44 pr_info("Error adding keys to machine keyring %s\n", source);
48 * Try to load the MokListTrustedRT MOK variable to see if we should trust
49 * the MOK keys within the kernel. It is not an error if this variable
50 * does not exist. If it does not exist, MOK keys should not be trusted
51 * within the machine keyring.
53 static __init bool uefi_check_trust_mok_keys(void)
55 struct efi_mokvar_table_entry *mokvar_entry;
57 mokvar_entry = efi_mokvar_entry_find("MokListTrustedRT");
65 bool __init trust_moklist(void)
67 static bool initialized;
72 if (uefi_check_trust_mok_keys())