Path: blob/master/security/integrity/platform_certs/keyring_handler.c
26424 views
// SPDX-License-Identifier: GPL-2.012#include <linux/kernel.h>3#include <linux/sched.h>4#include <linux/cred.h>5#include <linux/err.h>6#include <linux/efi.h>7#include <linux/slab.h>8#include <keys/asymmetric-type.h>9#include <keys/system_keyring.h>10#include "../integrity.h"11#include "keyring_handler.h"1213static efi_guid_t efi_cert_x509_guid __initdata = EFI_CERT_X509_GUID;14static efi_guid_t efi_cert_x509_sha256_guid __initdata =15EFI_CERT_X509_SHA256_GUID;16static efi_guid_t efi_cert_sha256_guid __initdata = EFI_CERT_SHA256_GUID;1718/*19* Blacklist an X509 TBS hash.20*/21static __init void uefi_blacklist_x509_tbs(const char *source,22const void *data, size_t len)23{24mark_hash_blacklisted(data, len, BLACKLIST_HASH_X509_TBS);25}2627/*28* Blacklist the hash of an executable.29*/30static __init void uefi_blacklist_binary(const char *source,31const void *data, size_t len)32{33mark_hash_blacklisted(data, len, BLACKLIST_HASH_BINARY);34}3536/*37* Add an X509 cert to the revocation list.38*/39static __init void uefi_revocation_list_x509(const char *source,40const void *data, size_t len)41{42add_key_to_revocation_list(data, len);43}4445/*46* Return the appropriate handler for particular signature list types found in47* the UEFI db tables.48*/49__init efi_element_handler_t get_handler_for_db(const efi_guid_t *sig_type)50{51if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0)52return add_to_platform_keyring;53return NULL;54}5556/*57* Return the appropriate handler for particular signature list types found in58* the MokListRT tables.59*/60__init efi_element_handler_t get_handler_for_mok(const efi_guid_t *sig_type)61{62if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0) {63if (IS_ENABLED(CONFIG_INTEGRITY_MACHINE_KEYRING) &&64imputed_trust_enabled())65return add_to_machine_keyring;66else67return add_to_platform_keyring;68}69return NULL;70}7172__init efi_element_handler_t get_handler_for_ca_keys(const efi_guid_t *sig_type)73{74if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0)75return add_to_machine_keyring;7677return NULL;78}7980__init efi_element_handler_t get_handler_for_code_signing_keys(const efi_guid_t *sig_type)81{82if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0)83return add_to_secondary_keyring;8485return NULL;86}8788/*89* Return the appropriate handler for particular signature list types found in90* the UEFI dbx and MokListXRT tables.91*/92__init efi_element_handler_t get_handler_for_dbx(const efi_guid_t *sig_type)93{94if (efi_guidcmp(*sig_type, efi_cert_x509_sha256_guid) == 0)95return uefi_blacklist_x509_tbs;96if (efi_guidcmp(*sig_type, efi_cert_sha256_guid) == 0)97return uefi_blacklist_binary;98if (efi_guidcmp(*sig_type, efi_cert_x509_guid) == 0)99return uefi_revocation_list_x509;100return NULL;101}102103104