1 // SPDX-License-Identifier: GPL-2.0
3 #include <linux/kernel.h>
4 #include <linux/sched.h>
5 #include <linux/cred.h>
8 #include <linux/slab.h>
9 #include <keys/asymmetric-type.h>
10 #include <keys/system_keyring.h>
11 #include "../integrity.h"
12 #include "keyring_handler.h"
14 static efi_guid_t efi_cert_x509_guid __initdata = EFI_CERT_X509_GUID;
15 static efi_guid_t efi_cert_x509_sha256_guid __initdata =
16 EFI_CERT_X509_SHA256_GUID;
17 static efi_guid_t efi_cert_sha256_guid __initdata = EFI_CERT_SHA256_GUID;
20 * Blacklist an X509 TBS hash.
22 static __init void uefi_blacklist_x509_tbs(const char *source,
23 const void *data, size_t len)
25 mark_hash_blacklisted(data, len, BLACKLIST_HASH_X509_TBS);
29 * Blacklist the hash of an executable.
31 static __init void uefi_blacklist_binary(const char *source,
32 const void *data, size_t len)
34 mark_hash_blacklisted(data, len, BLACKLIST_HASH_BINARY);
38 * Add an X509 cert to the revocation list.
40 static __init void uefi_revocation_list_x509(const char *source,
41 const void *data, size_t len)
43 add_key_to_revocation_list(data, len);
47 * Return the appropriate handler for particular signature list types found in
50 __init efi_element_handler_t get_handler_for_db(const efi_guid_t *sig_type)
52 if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0)
53 return add_to_platform_keyring;
58 * Return the appropriate handler for particular signature list types found in
59 * the MokListRT tables.
61 __init efi_element_handler_t get_handler_for_mok(const efi_guid_t *sig_type)
63 if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0) {
64 if (IS_ENABLED(CONFIG_INTEGRITY_MACHINE_KEYRING) && trust_moklist())
65 return add_to_machine_keyring;
67 return add_to_platform_keyring;
73 * Return the appropriate handler for particular signature list types found in
74 * the UEFI dbx and MokListXRT tables.
76 __init efi_element_handler_t get_handler_for_dbx(const efi_guid_t *sig_type)
78 if (efi_guidcmp(*sig_type, efi_cert_x509_sha256_guid) == 0)
79 return uefi_blacklist_x509_tbs;
80 if (efi_guidcmp(*sig_type, efi_cert_sha256_guid) == 0)
81 return uefi_blacklist_binary;
82 if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0)
83 return uefi_revocation_list_x509;