Path: blob/master/security/integrity/platform_certs/machine_keyring.c
26424 views
// SPDX-License-Identifier: GPL-2.01/*2* Machine keyring routines.3*4* Copyright (c) 2021, Oracle and/or its affiliates.5*/67#include <linux/efi.h>8#include "../integrity.h"910static __init int machine_keyring_init(void)11{12int rc;1314rc = integrity_init_keyring(INTEGRITY_KEYRING_MACHINE);15if (rc)16return rc;1718pr_notice("Machine keyring initialized\n");19return 0;20}21device_initcall(machine_keyring_init);2223void __init add_to_machine_keyring(const char *source, const void *data, size_t len)24{25key_perm_t perm;26int rc;2728perm = (KEY_POS_ALL & ~KEY_POS_SETATTR) | KEY_USR_VIEW;29rc = integrity_load_cert(INTEGRITY_KEYRING_MACHINE, source, data, len, perm);3031/*32* Some MOKList keys may not pass the machine keyring restrictions.33* If the restriction check does not pass and the platform keyring34* is configured, try to add it into that keyring instead.35*/36if (rc && efi_enabled(EFI_BOOT) &&37IS_ENABLED(CONFIG_INTEGRITY_PLATFORM_KEYRING))38rc = integrity_load_cert(INTEGRITY_KEYRING_PLATFORM, source,39data, len, perm);4041if (rc)42pr_info("Error adding keys to machine keyring %s\n", source);43}4445/*46* Try to load the MokListTrustedRT MOK variable to see if we should trust47* the MOK keys within the kernel. It is not an error if this variable48* does not exist. If it does not exist, MOK keys should not be trusted49* within the machine keyring.50*/51static __init bool uefi_check_trust_mok_keys(void)52{53struct efi_mokvar_table_entry *mokvar_entry;5455mokvar_entry = efi_mokvar_entry_find("MokListTrustedRT");5657if (mokvar_entry)58return true;5960return false;61}6263static bool __init trust_moklist(void)64{65static bool initialized;66static bool trust_mok;6768if (!initialized) {69initialized = true;70trust_mok = false;7172if (uefi_check_trust_mok_keys())73trust_mok = true;74}7576return trust_mok;77}7879/*80* Provides platform specific check for trusting imputed keys before loading81* on .machine keyring. UEFI systems enable this trust based on a variable,82* and for other platforms, it is always enabled.83*/84bool __init imputed_trust_enabled(void)85{86if (efi_enabled(EFI_BOOT))87return trust_moklist();8889return true;90}919293