add platform/firmware keys support for kernel verification by IMA
Subsystems (9)
v2 cover add platform/firmware keys support for kernel verification by IMA
On secure boot enabled systems, a verified kernel may need to kexec additional kernels. For example, it may be used as a bootloader needing to kexec a target kernel or it may need to kexec a crashdump kernel. In such cases, it may want to verify the signature of the next kernel image.
It is possible that the new kernel image is signed with third party keys which are stored as platform or firmware keys in the 'db' variable. The kernel, however, can not directly verify these platform keys, and an administrator may therefore not want to trust them for arbitrary usage. In order to differentiate platform keys from other keys and provide the necessary separation of trust the kernel needs an additional keyring to store platform/firmware keys.
The secure boot key database is expected to store the keys as EFI Signature List(ESL). The patch set uses David Howells and Josh Boyer's patch to access and parse the ESL to extract the certificates and load them onto the platform keyring.
The last patch in this patch set adds support for IMA-appraisal to verify the kexec'ed kernel image based on keys stored in the platform keyring.
Changelog:
v0:
- The original patches loaded the certificates onto the secondary trusted keyring. This patch set defines a new keyring named ".platform" and adds the certificates to this new keyring
- removed CONFIG EFI_SIGNATURE_LIST_PARSER and LOAD_UEFI_KEYS
- moved files from certs/ to security/integrity/platform_certs/
v2:
- fixed the checkpatch warnings and other formatting as suggested by Mimi Zohar
- fixed coding style as suggested by Serge Hallyn in Patch "ima: Support platform keyring for kernel appraisal"
Dave Howells (2):
efi: Add EFI signature data types
efi: Add an EFI signature blob parser
Josh Boyer (2):
efi: Import certificates from UEFI Secure Boot
efi: Allow the "db" UEFI variable to be suppressed
Nayna Jain (3):
integrity: Define a trusted platform keyring
integrity: Load certs to the platform keyring
ima: Support platform keyring for kernel appraisal
include/linux/efi.h | 34 ++++ security/integrity/Kconfig | 11 ++ security/integrity/Makefile | 5 + security/integrity/digsig.c | 115 ++++++++---- security/integrity/ima/ima_appraise.c | 13 +- security/integrity/integrity.h | 23 ++- security/integrity/platform_certs/efi_parser.c | 108 ++++++++++++ security/integrity/platform_certs/load_uefi.c | 196 +++++++++++++++++++++ .../integrity/platform_certs/platform_keyring.c | 62 +++++++ 9 files changed, 528 insertions(+), 39 deletions(-) create mode 100644 security/integrity/platform_certs/efi_parser.c create mode 100644 security/integrity/platform_certs/load_uefi.c create mode 100644 security/integrity/platform_certs/platform_keyring.c
Signature · 1 line
2.13.6
PATCH v2 1/7 integrity: Define a trusted platform keyring
On secure boot enabled systems, a verified kernel may need to kexec additional kernels. For example, it may be used as a bootloader needing to kexec a target kernel or it may need to kexec a crashdump kernel. In such cases, it may want to verify the signature of the next kernel image.
It is further possible that the kernel image is signed with third party keys which are stored as platform or firmware keys in the 'db' variable. The kernel, however, can not directly verify these platform keys, and an administrator may therefore not want to trust them for arbitrary usage. In order to differentiate platform keys from other keys and provide the necessary separation of trust, the kernel needs an additional keyring to store platform keys.
This patch creates the new keyring called ".platform" to isolate keys provided by platform from keys by kernel. These keys are used to facilitate signature verification during kexec. Since the scope of this keyring is only the platform/firmware keys, it cannot be updated from userspace.
This keyring can be enabled by setting CONFIG_INTEGRITY_PLATFORM_KEYRING.
--- security/integrity/Kconfig | 11 +++++ security/integrity/Makefile | 1 + security/integrity/digsig.c | 48 +++++++++++++++------- security/integrity/integrity.h | 3 +- .../integrity/platform_certs/platform_keyring.c | 39 ++++++++++++++++++ 5 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 security/integrity/platform_certs/platform_keyring.c
security/integrity/Kconfig +11 -0
@@ -51,6 +51,17 @@ config INTEGRITY_TRUSTED_KEYRING .evm keyrings be signed by a key on the system trusted keyring. +config INTEGRITY_PLATFORM_KEYRING + bool "Provide keyring for platform/firmware trusted keys" + depends on INTEGRITY_ASYMMETRIC_KEYS + depends on SYSTEM_BLACKLIST_KEYRING + depends on EFI + help + Provide a separate, distinct keyring for platform trusted keys, which + the kernel automatically populates during initialization from values + provided by the platform for verifying the kexec'ed kerned image + and, possibly, the initramfs signature. + config INTEGRITY_AUDIT bool "Enables integrity auditing support " depends on AUDIT
security/integrity/Makefile +1 -0
@@ -9,6 +9,7 @@ integrity-y := iint.o integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o +integrity-$(CONFIG_INTEGRITY_PLATFORM_KEYRING) += platform_certs/platform_keyring.o subdir-$(CONFIG_IMA) += ima obj-$(CONFIG_IMA) += ima/
security/integrity/digsig.c +34 -14
72 lines not on this page · raw message
security/integrity/integrity.h +2 -1
@@ -142,7 +142,8 @@ int integrity_kernel_read(struct file *file, loff_t offset,#define INTEGRITY_KEYRING_EVM 0#define INTEGRITY_KEYRING_IMA 1#define INTEGRITY_KEYRING_MODULE 2 -#define INTEGRITY_KEYRING_MAX 3 +#define INTEGRITY_KEYRING_PLATFORM 3 +#define INTEGRITY_KEYRING_MAX 4extern struct dentry *integrity_dir;
security/integrity/platform_certs/platform_keyring.c new file +39 -0
@@ -0,0 +1,39 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Platform keyring for firmware/platform keys +* +* Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public Licence +* as published by the Free Software Foundation; either version +* 2 of the Licence, or (at your option) any later version. +*/ + +#include <linux/export.h> +#include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/cred.h> +#include <linux/err.h> +#include <linux/slab.h> +#include "../integrity.h" + +/* +* Create the trusted keyrings. +*/ +static __init int platform_keyring_init (void ) +{ +int rc; + + rc =integrity_init_keyring (INTEGRITY_KEYRING_PLATFORM ); +if (rc) +return rc; + +pr_notice ("Platform Keyring initialized\n" ); +return 0 ; +} + +/* +* Must be initialised before we try and load the keys into the keyring. +*/ +device_initcall (platform_keyring_init);
Signature · 1 line
2.13.6
PATCH v2 1/7 integrity: Define a trusted platform keyring
On secure boot enabled systems, a verified kernel may need to kexec additional kernels. For example, it may be used as a bootloader needing to kexec a target kernel or it may need to kexec a crashdump kernel. In such cases, it may want to verify the signature of the next kernel image.
It is further possible that the kernel image is signed with third party keys which are stored as platform or firmware keys in the 'db' variable. The kernel, however, can not directly verify these platform keys, and an administrator may therefore not want to trust them for arbitrary usage. In order to differentiate platform keys from other keys and provide the necessary separation of trust, the kernel needs an additional keyring to store platform keys.
This patch creates the new keyring called ".platform" to isolate keys provided by platform from keys by kernel. These keys are used to facilitate signature verification during kexec. Since the scope of this keyring is only the platform/firmware keys, it cannot be updated from userspace.
This keyring can be enabled by setting CONFIG_INTEGRITY_PLATFORM_KEYRING.
--- security/integrity/Kconfig | 11 +++++ security/integrity/Makefile | 1 + security/integrity/digsig.c | 48 +++++++++++++++------- security/integrity/integrity.h | 3 +- .../integrity/platform_certs/platform_keyring.c | 35 ++++++++++++++++ 5 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 security/integrity/platform_certs/platform_keyring.c
security/integrity/Kconfig +11 -0
@@ -51,6 +51,17 @@ config INTEGRITY_TRUSTED_KEYRING .evm keyrings be signed by a key on the system trusted keyring. +config INTEGRITY_PLATFORM_KEYRING + bool "Provide keyring for platform/firmware trusted keys" + depends on INTEGRITY_ASYMMETRIC_KEYS + depends on SYSTEM_BLACKLIST_KEYRING + depends on EFI + help + Provide a separate, distinct keyring for platform trusted keys, which + the kernel automatically populates during initialization from values + provided by the platform for verifying the kexec'ed kerned image + and, possibly, the initramfs signature. + config INTEGRITY_AUDIT bool "Enables integrity auditing support " depends on AUDIT
security/integrity/Makefile +1 -0
@@ -9,6 +9,7 @@ integrity-y := iint.o integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o +integrity-$(CONFIG_INTEGRITY_PLATFORM_KEYRING) += platform_certs/platform_keyring.o subdir-$(CONFIG_IMA) += ima obj-$(CONFIG_IMA) += ima/
security/integrity/digsig.c +34 -14
72 lines not on this page · raw message
security/integrity/integrity.h +2 -1
@@ -142,7 +142,8 @@ int integrity_kernel_read(struct file *file, loff_t offset,#define INTEGRITY_KEYRING_EVM 0#define INTEGRITY_KEYRING_IMA 1#define INTEGRITY_KEYRING_MODULE 2 -#define INTEGRITY_KEYRING_MAX 3 +#define INTEGRITY_KEYRING_PLATFORM 3 +#define INTEGRITY_KEYRING_MAX 4extern struct dentry *integrity_dir;
security/integrity/platform_certs/platform_keyring.c new file +35 -0
@@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Platform keyring for firmware/platform keys +* +* Copyright IBM Corporation, 2018 +* Author(s): Nayna Jain <[email protected]> +*/ + +#include <linux/export.h> +#include <linux/kernel.h> +#include <linux/sched.h> +#include <linux/cred.h> +#include <linux/err.h> +#include <linux/slab.h> +#include "../integrity.h" + +/* +* Create the trusted keyrings. +*/ +static __init int platform_keyring_init (void ) +{ +int rc; + + rc =integrity_init_keyring (INTEGRITY_KEYRING_PLATFORM ); +if (rc) +return rc; + +pr_notice ("Platform Keyring initialized\n" ); +return 0 ; +} + +/* +* Must be initialised before we try and load the keys into the keyring. +*/ +device_initcall (platform_keyring_init);
Signature · 1 line
2.13.6
Re: [PATCH v2 1/7] integrity: Define a trusted platform keyring
Quoted 25 lines · Nayna Jain
On secure boot enabled systems, a verified kernel may need to kexec additional kernels. For example, it may be used as a bootloader needing to kexec a target kernel or it may need to kexec a crashdump kernel. In such cases, it may want to verify the signature of the next kernel image.
It is further possible that the kernel image is signed with third party keys which are stored as platform or firmware keys in the 'db' variable. The kernel, however, can not directly verify these platform keys, and an administrator may therefore not want to trust them for arbitrary usage. In order to differentiate platform keys from other keys and provide the necessary separation of trust, the kernel needs an additional keyring to store platform keys.
This patch creates the new keyring called ".platform" to isolate keys provided by platform from keys by kernel. These keys are used to facilitate signature verification during kexec. Since the scope of this keyring is only the platform/firmware keys, it cannot be updated from userspace.
This keyring can be enabled by setting
CONFIG_INTEGRITY_PLATFORM_KEYRING.Signed-off-by Nayna Jain <[email protected]>Reviewed-by Mimi Zohar <[email protected]>Acked-by Serge Hallyn <[email protected]>
Quoted 8 lines
--- security/integrity/Kconfig | 11 +++++ security/integrity/Makefile | 1 + security/integrity/digsig.c | 48 +++++++++++++++------- security/integrity/integrity.h | 3 +- .../integrity/platform_certs/platform_keyring.c | 35 ++++++++++++++++ 5 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 security/integrity/platform_certs/platform_keyring.c
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
Re: [PATCH v2 1/7] integrity: Define a trusted platform keyring
In reply to Nayna JainQuoted 20 lines · Nayna Jain
On secure boot enabled systems, a verified kernel may need to kexec additional kernels. For example, it may be used as a bootloader needing to kexec a target kernel or it may need to kexec a crashdump kernel. In such cases, it may want to verify the signature of the next kernel image.
It is further possible that the kernel image is signed with third party keys which are stored as platform or firmware keys in the 'db' variable. The kernel, however, can not directly verify these platform keys, and an administrator may therefore not want to trust them for arbitrary usage. In order to differentiate platform keys from other keys and provide the necessary separation of trust, the kernel needs an additional keyring to store platform keys.
This patch creates the new keyring called ".platform" to isolate keys provided by platform from keys by kernel. These keys are used to facilitate signature verification during kexec. Since the scope of this keyring is only the platform/firmware keys, it cannot be updated from userspace.
Quoted 5 lines
This keyring can be enabled by setting
CONFIG_INTEGRITY_PLATFORM_KEYRING.Signed-off-by Nayna Jain <[email protected]>Reviewed-by Mimi Zohar <[email protected]>Acked-by Serge Hallyn <[email protected]>
Signature · 2 lines
James Morris <[email protected]>
PATCH v2 2/7 integrity: Load certs to the platform keyring
In reply to Nayna JainThe patch refactors integrity_load_x509(), making it a wrapper for a new function named integrity_add_key(). This patch also defines a new function named integrity_load_cert() for loading the platform keys.
--- security/integrity/digsig.c | 71 ++++++++++++++-------- security/integrity/integrity.h | 20 ++++++ .../integrity/platform_certs/platform_keyring.c | 23 +++++++ 3 files changed, 90 insertions(+), 24 deletions(-)
security/integrity/digsig.c +47 -24
@@ -82,8 +82,7 @@ static int __integrity_init_keyring(const unsigned int id, key_perm_t perm, keyring[id] =keyring_alloc (keyring_name[id],KUIDT_INIT (0 ),KGIDT_INIT (0 ), cred, perm, -KEY_ALLOC_NOT_IN_QUOTA , - restriction,NULL ); +KEY_ALLOC_NOT_IN_QUOTA , restriction,NULL );if (IS_ERR (keyring[id])) { err =PTR_ERR (keyring[id]); pr_info("Can't allocate %s keyring (%d)\n",
@@ -124,16 +123,38 @@ int __init integrity_init_keyring(const unsigned int id)return err; } -int __init integrity_load_x509 (const unsigned int id,const char *path) +int __init integrity_add_key (const unsigned int id,const void *data, +off_t size,key_perm_t perm) {key_ref_t key; -void *data; -loff_t size; -int rc; +int rc =0 ;if (!keyring[id])return -EINVAL ; + key =key_create_or_update (make_key_ref (keyring[id],1 ),"asymmetric" , +NULL , data, size, perm, +KEY_ALLOC_NOT_IN_QUOTA ); +if (IS_ERR (key)) { + rc =PTR_ERR (key); +pr_err ("Problem loading X.509 certificate %d\n" , rc); + }else { +pr_notice ("Loaded X.509 cert '%s'\n" , +key_ref_to_ptr (key)->description); +key_ref_put (key); + } + +return rc; + +} + +int __init integrity_load_x509 (const unsigned int id,const char *path) +{ +void *data; +loff_t size; +int rc; +key_perm_t perm; + rc =kernel_read_file_from_path (path, &data, &size,0 ,READING_X509_CERTIFICATE );if (rc <0 ) {
@@ -141,23 +162,25 @@ int __init integrity_load_x509(const unsigned int id, const char *path)return rc; } - key =key_create_or_update (make_key_ref (keyring[id],1 ), -"asymmetric" , -NULL , - data, - size, - ((KEY_POS_ALL & ~KEY_POS_SETATTR ) | -KEY_USR_VIEW |KEY_USR_READ ), -KEY_ALLOC_NOT_IN_QUOTA ); -if (IS_ERR (key)) { - rc =PTR_ERR (key); -pr_err ("Problem loading X.509 certificate (%d): %s\n" , - rc, path); - }else { -pr_notice ("Loaded X.509 cert '%s': %s\n" , -key_ref_to_ptr (key)->description, path); -key_ref_put (key); - } + perm = (KEY_POS_ALL & ~KEY_POS_SETATTR ) |KEY_USR_VIEW |KEY_USR_READ ; + +pr_info ("Loading X.509 certificate: %s\n" , path); + rc =integrity_add_key (id, (const void *)data, size, perm); +vfree (data); -return 0 ; +return rc; +} + +int __init integrity_load_cert (const unsigned int id,const char *source, +const void *data,size_t len,key_perm_t perm) +{ +int rc; + +if (!data) +return -EINVAL ; + +pr_info ("Loading X.509 certificate: %s\n" , source); + rc =integrity_add_key (id, data, len, perm); + +return rc; }
security/integrity/integrity.h +20 -0
@@ -154,6 +154,8 @@ int integrity_digsig_verify(const unsigned int id, const char *sig, int siglen,int __init integrity_init_keyring (const unsigned int id);int __init integrity_load_x509 (const unsigned int id,const char *path); +int __init integrity_load_cert (const unsigned int id,const char *source, +const void *data,size_t len,key_perm_t perm);#else static inline int integrity_digsig_verify(const unsigned int id,
@@ -167,6 +169,14 @@ static inline int integrity_init_keyring(const unsigned int id) {return 0 ; } + +static inline int __init integrity_load_cert (const unsigned int id, +const char *source, +const void *data,size_t len, +key_perm_t perm) +{ +return 0 ; +}#endif /* CONFIG_INTEGRITY_SIGNATURE */ #ifdef CONFIG_INTEGRITY_ASYMMETRIC_KEYS
@@ -223,3 +233,13 @@ integrity_audit_log_start(struct audit_context *ctx, gfp_t gfp_mask, int type) }#endif + +#ifdef CONFIG_INTEGRITY_PLATFORM_KEYRING +void __init add_to_platform_keyring (const char *source,const void *data, +size_t len); +#else +static inline void __init add_to_platform_keyring (const char *source, +const void *data,size_t len) +{ +} +#endif
security/integrity/platform_certs/platform_keyring.c +23 -0
@@ -18,6 +18,29 @@#include <linux/slab.h> #include "../integrity.h" +/** +* add_to_platform_keyring - Add to platform keyring without validation. +* @source: Source of key +* @data: The blob holding the key +* @len: The length of the data blob +* +* Add a key to the platform keyring without checking its trust chain. This +* is available only during kernel initialisation. +*/ +void __init add_to_platform_keyring (const char *source,const void *data, +size_t len) +{ +key_perm_t perm; +int rc; + + perm = (KEY_POS_ALL & ~KEY_POS_SETATTR ) |KEY_USR_VIEW ; + + rc =integrity_load_cert (INTEGRITY_KEYRING_PLATFORM , source, data, len, + perm); +if (rc) +pr_info ("Error adding keys to platform keyring %s\n" , source); +} +/* * Create the trusted keyrings. */
Signature · 1 line
2.13.6
Re: [PATCH v2 2/7] integrity: Load certs to the platform keyring
Quoted 7 lines · Nayna Jain
The patch refactors
integrity_load_x509(), making it a wrapper for a new function namedintegrity_add_key(). This patch also defines a new function namedintegrity_load_cert()for loading the platform keys.Signed-off-by Nayna Jain <[email protected]>Reviewed-by Mimi Zohar <[email protected]>Acked-by Serge Hallyn <[email protected]>
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH v2 2/7] integrity: Load certs to the platform keyring
In reply to Nayna JainQuoted 4 lines · Nayna Jain
The patch refactors
integrity_load_x509(), making it a wrapper for a new function namedintegrity_add_key(). This patch also defines a new function namedintegrity_load_cert()for loading the platform keys.
Quoted 8 lines
Signed-off-by Nayna Jain <[email protected]>Reviewed-by Mimi Zohar <[email protected]>Acked-by Serge Hallyn <[email protected]>--- security/integrity/digsig.c | 71 ++++++++++++++-------- security/integrity/integrity.h | 20 ++++++ .../integrity/platform_certs/platform_keyring.c | 23 +++++++ 3 files changed, 90 insertions(+), 24 deletions(-)
Signature · 2 lines
Thiago Jung Bauermann IBM Linux Technology Center
PATCH v2 3/7 efi: Add EFI signature data types
In reply to Nayna JainFrom: Dave Howells <[email protected]>
Add the data types that are used for containing hashes, keys and certificates for cryptographic verification along with their corresponding type GUIDs.
---
Changelog:
v0:
- No changes
include/linux/efi.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
include/linux/efi.h +25 -0
@@ -663,6 +663,10 @@ void efi_native_runtime_setup(void);#define EFI_IMAGE_SECURITY_DATABASE_GUID EFI_GUID(0xd719b2cb, 0x3d3a, 0x4596, 0xa3, 0xbc, 0xda, 0xd0, 0x0e, 0x67, 0x65, 0x6f)#define EFI_SHIM_LOCK_GUID EFI_GUID(0x605dab50, 0xe046, 0x4300, 0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23) +#define EFI_CERT_SHA256_GUID EFI_GUID(0xc1c41626, 0x504c, 0x4092, 0xac, 0xa9, 0x41, 0xf9, 0x36, 0x93, 0x43, 0x28) +#define EFI_CERT_X509_GUID EFI_GUID(0xa5c059a1, 0x94e4, 0x4aa7, 0x87, 0xb5, 0xab, 0x15, 0x5c, 0x2b, 0xf0, 0x72) +#define EFI_CERT_X509_SHA256_GUID EFI_GUID(0x3bd2a492, 0x96c0, 0x4079, 0xb4, 0x20, 0xfc, 0xf9, 0x8e, 0xf1, 0x03, 0xed) +/* * This GUID is used to pass to the kernel proper the struct screen_info * structure that was populated by the stub based on the GOP protocol instance
@@ -934,6 +938,27 @@ typedef struct {efi_memory_desc_t entry[0 ]; } efi_memory_attributes_table_t; +typedef struct { +efi_guid_t signature_owner; +u8 signature_data[]; +}efi_signature_data_t ; + +typedef struct { +efi_guid_t signature_type; +u32 signature_list_size; +u32 signature_header_size; +u32 signature_size; +u8 signature_header[]; +/* efi_signature_data_t signatures[][] */ +}efi_signature_list_t ; + +typedef u8 efi_sha256_hash_t [32 ]; + +typedef struct { +efi_sha256_hash_t to_be_signed_hash; +efi_time_t time_of_revocation; +}efi_cert_x509_sha256_t ; +/* * All runtime access to EFI goes through this structure: */
Signature · 1 line
2.13.6
Re: [PATCH v2 3/7] efi: Add EFI signature data types
Quoted 9 lines · Nayna Jain
From: Dave Howells <[email protected]>
Add the data types that are used for containing hashes, keys and certificates for cryptographic verification along with their corresponding type GUIDs.
Signed-off-by David Howells <[email protected]>Acked-by Nayna Jain <[email protected]>Acked-by Serge Hallyn <[email protected]>
Signature · 2 lines
James Morris <[email protected]>
PATCH v2 4/7 efi: Add an EFI signature blob parser
In reply to Nayna JainFrom: Dave Howells <[email protected]>
Add a function to parse an EFI signature blob looking for elements of interest. A list is made up of a series of sublists, where all the elements in a sublist are of the same type, but sublists can be of different types.
For each sublist encountered, the function pointed to by the get_handler_for_guid argument is called with the type specifier GUID and returns either a pointer to a function to handle elements of that type or NULL if the type is not of interest.
If the sublist is of interest, each element is passed to the handler function in turn.
---
Changelog:
v0:
- removed the CONFIG EFI_SIGNATURE_LIST_PARSER
- moved efi_parser.c from certs to security/integrity/platform_certs directory
v2:
- Fixed the checkpatch.pl warnings
include/linux/efi.h | 9 +++ security/integrity/Makefile | 3 +- security/integrity/platform_certs/efi_parser.c | 108 +++++++++++++++++++++++++ 3 files changed, 119 insertions(+), 1 deletion(-) create mode 100644 security/integrity/platform_certs/efi_parser.c
include/linux/efi.h +9 -0
@@ -1141,6 +1141,15 @@ extern int efi_memattr_apply_permissions(struct mm_struct *mm,char *__init efi_md_typeattr_format (char *buf,size_t size,const efi_memory_desc_t *md); + +typedef void (*efi_element_handler_t )(const char *source, +const void *element_data, +size_t element_size); +extern int __init parse_efi_signature_list ( +const char *source, +const void *data,size_t size, +efi_element_handler_t (*get_handler_for_guid)(const efi_guid_t *)); +/** * efi_range_is_wc - check the WC bit on an address range * @start: starting kvirt address
security/integrity/Makefile +2 -1
@@ -9,7 +9,8 @@ integrity-y := iint.o integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o -integrity-$(CONFIG_INTEGRITY_PLATFORM_KEYRING) += platform_certs/platform_keyring.o +integrity-$(CONFIG_INTEGRITY_PLATFORM_KEYRING) += platform_certs/platform_keyring.o \ + platform_certs/efi_parser.o subdir-$(CONFIG_IMA) += ima obj-$(CONFIG_IMA) += ima/
security/integrity/platform_certs/efi_parser.c new file +108 -0
108 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH v2 5/7 efi: Import certificates from UEFI Secure Boot
In reply to Nayna JainFrom: Josh Boyer <[email protected]>
New Patch Description:
======================
Secure Boot stores a list of allowed certificates in the 'db' variable. This patch imports those certificates into the platform keyring. The shim UEFI bootloader has a similar certificate list stored in the 'MokListRT' variable. We import those as well.
Secure Boot also maintains a list of disallowed certificates in the 'dbx' variable. We load those certificates into the system blacklist keyring and forbid any kernel signed with those from loading.
Original Patch Description:
============================
Secure Boot stores a list of allowed certificates in the 'db' variable. This imports those certificates into the system trusted keyring. This allows for a third party signing certificate to be used in conjunction with signed modules. By importing the public certificate into the 'db' variable, a user can allow a module signed with that certificate to load. The shim UEFI bootloader has a similar certificate list stored in the 'MokListRT' variable. We import those as well.
Secure Boot also maintains a list of disallowed certificates in the 'dbx' variable. We load those certificates into the newly introduced system blacklist keyring and forbid any module signed with those from loading and forbid the use within the kernel of any key with a matching hash.
This facility is enabled by setting CONFIG_LOAD_UEFI_KEYS.
---
Changelog:
v0:
- This patch replaces the loading of certificates onto the secondary keyring with platform keyring
- removed the CONFIG LOAD_UEFI_KEYS
- moved the file load_uefi.o from certs to security/integrity/platform_certs
v2:
- Fixed the checkpatch.pl warnings
security/integrity/Makefile | 5 +- security/integrity/platform_certs/load_uefi.c | 171 ++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 security/integrity/platform_certs/load_uefi.c
security/integrity/Makefile +4 -1
@@ -10,7 +10,10 @@ integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o integrity-$(CONFIG_INTEGRITY_PLATFORM_KEYRING) += platform_certs/platform_keyring.o \ - platform_certs/efi_parser.o + platform_certs/efi_parser.o \ + platform_certs/load_uefi.o +obj-$(CONFIG_LOAD_UEFI_KEYS) += platform_certs/load_uefi.o +$(obj)/load_uefi.o: KBUILD_CFLAGS += -fshort-wchar subdir-$(CONFIG_IMA) += ima obj-$(CONFIG_IMA) += ima/
security/integrity/platform_certs/load_uefi.c new file +171 -0
171 lines not on this page · raw message
Signature · 1 line
2.13.6
James Morris
maintainerRe: [PATCH v2 5/7] efi: Import certificates from UEFI Secure Boot
Quoted 32 lines · Nayna Jain
security/integrity/platform_certs/load_uefi.c new file +31
-0+/* +* Blacklist an X509 TBS hash. +*/ +static __init void uefi_blacklist_x509_tbs (const char *source, +const void *data,size_t len) +{ +char *hash, *p; + + hash =kmalloc (4 + len *2 +1 ,GFP_KERNEL ); +if (!hash) +return ; + p =memcpy (hash,"tbs:" ,4 ); + p +=4 ; +bin2hex (p, data, len); + p += len *2 ; + *p =0 ; + +mark_hash_blacklisted (hash); +kfree (hash); +} + +/* +* Blacklist the hash of an executable. +*/ +static __init void uefi_blacklist_binary (const char *source, +const void *data,size_t len) +{ +char *hash, *p; + + hash =kmalloc (4 + len *2 +1 ,GFP_KERNEL ); +if (!hash)
security/integrity/platform_certs/load_uefi.c line 90
Quoted 10 lines
security/integrity/platform_certs/load_uefi.c new file +10
-0+return ; + p =memcpy (hash,"bin:" ,4 ); + p +=4 ; +bin2hex (p, data, len); + p += len *2 ; + *p =0 ; + +mark_hash_blacklisted (hash); +kfree (hash); +}
These could be refactored into one function.
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH v2 5/7] efi: Import certificates from UEFI Secure Boot
Quoted 37 lines · James Morris
Quoted 35 lines · Nayna Jain
security/integrity/platform_certs/load_uefi.c new file +35
-0+/* +* Blacklist an X509 TBS hash. +*/ +static __init void uefi_blacklist_x509_tbs (const char *source, +const void *data,size_t len) +{ +char *hash, *p; + + hash =kmalloc (4 + len *2 +1 ,GFP_KERNEL ); +if (!hash) +return ; + p =memcpy (hash,"tbs:" ,4 ); + p +=4 ; +bin2hex (p, data, len); + p += len *2 ; + *p =0 ; + +mark_hash_blacklisted (hash); +kfree (hash); +} + +/* +* Blacklist the hash of an executable. +*/ +static __init void uefi_blacklist_binary (const char *source, +const void *data,size_t len) +{ +char *hash, *p; + + hash =kmalloc (4 + len *2 +1 ,GFP_KERNEL ); +if (!hash) +return ; + p =memcpy (hash,"bin:" ,4 ); + p +=4 ; +bin2hex (p, data, len);
Quoted 10 lines
security/integrity/platform_certs/load_uefi.c line 69
Quoted 7 lines
security/integrity/platform_certs/load_uefi.c new file +6
-0+ p += len *2 ; + *p =0 ; + +mark_hash_blacklisted (hash); +kfree (hash); +}These could be refactored into one function.
Thanks James for reviewing.
Yes, the code should be refactored. However, I think making it a single function would require adding a new field to the function callback definitions as well. Probably, a simpler approach would be to define a common function uefi_blacklist_hash(...) which can then be used by the two functions uefi_blacklist_x509_tbs(...) and uefi_blacklist_binary(...). These two functions now act as wrapper functions. Below is the example code:
+/*
+ * Blacklist a hash.
+ */
+static __init void uefi_blacklist_hash(const char *source, const void *data, + size_t len, char *type, size_t type_len) +{
+ char *hash, *p;
+
+ hash = kmalloc(type_len + len * 2 + 1, GFP_KERNEL);
+ if (!hash)
+ return;
+ p = memcpy(hash, type, type_len);
+ p += type_len;
+ bin2hex(p, data, len);
+ p += len * 2;
+ *p = 0;
+
+ mark_hash_blacklisted(hash);
+ kfree(hash);
+}
+
+/*
+ * Blacklist an X509 TBS hash.
+ */
+static __init void uefi_blacklist_x509_tbs(const char *source,
+ const void *data, size_t len) +{
+ uefi_blacklist_hash(source, data, len, "tbs:" , 4);
+}
+
+/*
+ * Blacklist the hash of an executable.
+ */
+static __init void uefi_blacklist_binary(const char *source,
+ const void *data, size_t len) +{
+ uefi_blacklist_hash(source, data, len, "bin:" , 4);
+}
Thanks & Regards,
- Nayna
PATCH v2 5/7 efi: Import certificates from UEFI Secure Boot
In reply to Nayna JainFrom: Josh Boyer <[email protected]>
Secure Boot stores a list of allowed certificates in the 'db' variable. This patch imports those certificates into the platform keyring. The shim UEFI bootloader has a similar certificate list stored in the 'MokListRT' variable. We import those as well.
Secure Boot also maintains a list of disallowed certificates in the 'dbx' variable. We load those certificates into the system blacklist keyring and forbid any kernel signed with those from loading.
---
Changelog:
v2a:
- refactored uefi_blacklist_x509_tbs() and uefi_blacklist_binary()
v2:
- Fixed the checkpatch.pl warnings
v0:
- This patch replaces the loading of certificates onto the secondary keyring with platform keyring
- removed the CONFIG LOAD_UEFI_KEYS
- moved the file load_uefi.o from certs to security/integrity/platform_certs
security/integrity/Makefile | 5 +- security/integrity/platform_certs/load_uefi.c | 169 ++++++++++++++++++++++++++ 2 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 security/integrity/platform_certs/load_uefi.c
security/integrity/Makefile +4 -1
@@ -10,7 +10,10 @@ integrity-$(CONFIG_INTEGRITY_AUDIT) += integrity_audit.o integrity-$(CONFIG_INTEGRITY_SIGNATURE) += digsig.o integrity-$(CONFIG_INTEGRITY_ASYMMETRIC_KEYS) += digsig_asymmetric.o integrity-$(CONFIG_INTEGRITY_PLATFORM_KEYRING) += platform_certs/platform_keyring.o \ - platform_certs/efi_parser.o + platform_certs/efi_parser.o \ + platform_certs/load_uefi.o +obj-$(CONFIG_LOAD_UEFI_KEYS) += platform_certs/load_uefi.o +$(obj)/load_uefi.o: KBUILD_CFLAGS += -fshort-wchar subdir-$(CONFIG_IMA) += ima obj-$(CONFIG_IMA) += ima/
security/integrity/platform_certs/load_uefi.c new file +169 -0
169 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH v2 6/7 efi: Allow the "db" UEFI variable to be suppressed
In reply to Nayna JainFrom: Josh Boyer <[email protected]>
If a user tells shim to not use the certs/hashes in the UEFI db variable for verification purposes, shim will set a UEFI variable called MokIgnoreDB. Have the uefi import code look for this and ignore the db variable if it is found.
---
Changelog:
v0:
- No changes
v2:
- Fixed the checkpatch.pl warnings
security/integrity/platform_certs/load_uefi.c | 45 +++++++++++++++++++++------ 1 file changed, 35 insertions(+), 10 deletions(-)
security/integrity/platform_certs/load_uefi.c +35 -10
@@ -16,6 +16,26 @@ static efi_guid_t efi_cert_x509_sha256_guid __initdata =static efi_guid_t efi_cert_sha256_guid__initdata =EFI_CERT_SHA256_GUID ;/* +* Look to see if a UEFI variable called MokIgnoreDB exists and return true if +* it does. +* +* This UEFI variable is set by the shim if a user tells the shim to not use +* the certs/hashes in the UEFI db variable for verification purposes. If it +* is set, we should ignore the db variable also and the true return indicates +* this. +*/ +static __init bool uefi_check_ignore_db (void ) +{ +efi_status_t status; +unsigned int db =0 ; +unsigned long size =sizeof (db); +efi_guid_t guid =EFI_SHIM_LOCK_GUID ; + + status = efi.get_variable (L"MokIgnoreDB" , &guid,NULL , &size, &db); +return status ==EFI_SUCCESS ; +} + +/* * Get a certificate list blob from the named EFI variable. */ static __init void *get_cert_list(efi_char16_t *name, efi_guid_t *guid,
@@ -116,7 +136,9 @@ static __init efi_element_handler_t get_handler_for_dbx(const efi_guid_t * }/* -* Load the certs contained in the UEFI databases +* Load the certs contained in the UEFI databases into the secondary trusted +* keyring and the UEFI blacklisted X.509 cert SHA256 hashes into the blacklist +* keyring. */ static int __init load_uefi_certs (void ) {
@@ -132,15 +154,18 @@ static int __init load_uefi_certs(void)/* Get db, MokListRT, and dbx. They might not exist, so it isn't * an error if we can't get them. */ - db =get_cert_list (L"db" , &secure_var, &dbsize); -if (!db) { -pr_err ("Couldn't get UEFI db list\n" ); - }else { - rc =parse_efi_signature_list ("UEFI:db" , - db, dbsize, get_handler_for_db); -if (rc) -pr_err ("Couldn't parse db signatures: %d\n" , rc); -kfree (db); +if (!uefi_check_ignore_db ()) { + db =get_cert_list (L"db" , &secure_var, &dbsize); +if (!db) { +pr_err ("MODSIGN: Couldn't get UEFI db list\n" ); + }else { + rc =parse_efi_signature_list ("UEFI:db" , + db, dbsize, get_handler_for_db); +if (rc) +pr_err ("Couldn't parse db signatures: %d\n" , + rc); +kfree (db); + } } mok =get_cert_list (L"MokListRT" , &mok_var, &moksize);
Signature · 1 line
2.13.6
Re: [PATCH v2 6/7] efi: Allow the "db" UEFI variable to be suppressed
Quoted 11 lines · Nayna Jain
From: Josh Boyer <[email protected]>
If a user tells shim to not use the
certs/hashesin the UEFI db variable for verification purposes, shim will set a UEFI variable called MokIgnoreDB. Have the uefi import code look for this and ignore the db variable if it is found.Signed-off-by Josh Boyer <[email protected]>Signed-off-by David Howells <[email protected]>Acked-by Nayna Jain <[email protected]>Acked-by Serge Hallyn <[email protected]>
Signature · 2 lines
James Morris <[email protected]>
PATCH v2 7/7 ima: Support platform keyring for kernel appraisal
In reply to Nayna JainOn secure boot enabled systems, the bootloader verifies the kernel image and possibly the initramfs signatures based on a set of keys. A soft reboot(kexec) of the system, with the same kernel image and initramfs, requires access to the original keys to verify the signatures.
This patch allows IMA-appraisal access to those original keys, now loaded on the platform keyring, needed for verifying the kernel image and initramfs signatures.
- replace 'rc' with 'xattr_len' when calling integrity_digsig_verify() with INTEGRITY_KEYRING_IMA for readability
---
Changelog:
v2:
- replace 'rc' with 'xattr_len' when calling integrity_digsig_verify() with INTEGRITY_KEYRING_IMA for readability
security/integrity/ima/ima_appraise.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
security/integrity/ima/ima_appraise.c +11 -2
@@ -289,12 +289,21 @@ int ima_appraise_measurement(enum ima_hooks func,case EVM_IMA_XATTR_DIGSIG :set_bit (IMA_DIGSIG , &iint->atomic_flags); rc =integrity_digsig_verify (INTEGRITY_KEYRING_IMA , - (const char *)xattr_value, rc, + (const char *)xattr_value, + xattr_len, iint->ima_hash->digest, iint->ima_hash->length);if (rc == -EOPNOTSUPP ) { status =INTEGRITY_UNKNOWN ; - }else if (rc) { +break ; + } +if (rc && func ==KEXEC_KERNEL_CHECK ) + rc =integrity_digsig_verify (INTEGRITY_KEYRING_PLATFORM , + (const char *)xattr_value, + xattr_len, + iint->ima_hash->digest, + iint->ima_hash->length); +if (rc) { cause ="invalid-signature" ; status =INTEGRITY_FAIL ; }else {
Signature · 1 line
2.13.6
Re: [PATCH v2 7/7] ima: Support platform keyring for kernel appraisal
Quoted 10 lines · Nayna Jain
On secure boot enabled systems, the bootloader verifies the kernel image and possibly the initramfs signatures based on a set of keys. A soft reboot(kexec) of the system, with the same kernel image and initramfs, requires access to the original keys to verify the signatures.
This patch allows IMA-appraisal access to those original keys, now loaded on the platform keyring, needed for verifying the kernel image and initramfs signatures.
Quoted 6 lines
Signed-off-by Nayna Jain <[email protected]>Reviewed-by Mimi Zohar <[email protected]>Acked-by Serge Hallyn <[email protected]>- replace 'rc' with '
xattr_len' when callingintegrity_digsig_verify()withINTEGRITY_KEYRING_IMAfor readabilitySuggested-by Serge Hallyn <[email protected]>
Signature · 2 lines
James Morris <[email protected]>
Re: [PATCH v2 7/7] ima: Support platform keyring for kernel appraisal
In reply to Nayna JainHello,
Quoted 40 lines · Nayna Jain
On secure boot enabled systems, the bootloader verifies the kernel image and possibly the initramfs signatures based on a set of keys. A soft reboot(kexec) of the system, with the same kernel image and initramfs, requires access to the original keys to verify the signatures.
This patch allows IMA-appraisal access to those original keys, now loaded on the platform keyring, needed for verifying the kernel image and initramfs signatures.
Signed-off-by Nayna Jain <[email protected]>Reviewed-by Mimi Zohar <[email protected]>Acked-by Serge Hallyn <[email protected]>- replace 'rc' with '
xattr_len' when callingintegrity_digsig_verify()withINTEGRITY_KEYRING_IMAfor readabilitySuggested-by Serge Hallyn <[email protected]>---
Changelog:v2:
- replace 'rc' with 'xattr_len' when callingintegrity_digsig_verify()withINTEGRITY_KEYRING_IMAfor readabilitysecurity/integrity/ima/ima_appraise.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)security/integrity/ima/ima_appraise.c +2
-1@@ -289,12 +289,21 @@ int ima_appraise_measurement(enum ima_hooks func,case EVM_IMA_XATTR_DIGSIG :set_bit (IMA_DIGSIG , &iint->atomic_flags); rc =integrity_digsig_verify (INTEGRITY_KEYRING_IMA , - (const char *)xattr_value, rc, + (const char *)xattr_value, + xattr_len, iint->ima_hash->digest, iint->ima_hash->length);if (rc = -EOPNOTSUPP ) {
security/integrity/ima/ima_appraise.c int ima_appraise_measurement(enum ima_hooks func, · line 305
Quoted 10 lines
security/integrity/ima/ima_appraise.c +8
-1status =INTEGRITY_UNKNOWN ; - }else if (rc) { +break ; + } +if (rc && func =KEXEC_KERNEL_CHECK ) + rc =integrity_digsig_verify (INTEGRITY_KEYRING_PLATFORM , + (const char *)xattr_value, + xattr_len, + iint->ima_hash->digest, + iint->ima_hash->length);
If CONFIG_INTEGRITY_PLATFORM_KEYRING=n the second call to integrity_digsig_verify() above will always fail, and the audit message of failed signature verifications for KEXEC_KERNEL will always log the same rc value, which is whatever request_key() returns when asked to look for an inexistent keyring.
Here is a patch which only performs the second try if the platform keyring is enabled.
From d5fb94ab9eb13f6294f8dc44d1344cb85dfa41b8 Mon Sep 17 00:00:00 2001
From: Thiago Jung Bauermann <[email protected]>
Date: Wed, 12 Dec 2018 16:02:09 -0200
Subject: [PATCH] ima: Only use the platform keyring if it's enabled
--- security/integrity/ima/ima_appraise.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
security/integrity/ima/ima_appraise.c +2 -1
@@ -297,7 +297,8 @@ int ima_appraise_measurement(enum ima_hooks func, status =INTEGRITY_UNKNOWN ;break ; } -if (rc && func =KEXEC_KERNEL_CHECK ) +if (IS_ENABLED (CONFIG_INTEGRITY_PLATFORM_KEYRING ) && rc && + func =KEXEC_KERNEL_CHECK ) rc = integrity_digsig_verify(INTEGRITY_KEYRING_PLATFORM, (const char *)xattr_value, xattr_len,
Mimi Zohar
maintainerRe: [PATCH v2 7/7] ima: Support platform keyring for kernel appraisal
On Wed, 2018-12-12 at 16:14 -0200, Thiago Jung Bauermann wrote:
[snip]
Quoted 3 lines
Subject: [PATCH] ima: Only use the platform keyring if it's enabled
Signed-off-by Thiago Jung Bauermann <[email protected]>
Good catch! Thanks.
Mimi
Quoted 18 lines
--- security/integrity/ima/ima_appraise.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)security/integrity/ima/ima_appraise.c +2
-1@@ -297,7 +297,8 @@ int ima_appraise_measurement(enum ima_hooks func, status =INTEGRITY_UNKNOWN ;break ; } -if (rc && func =KEXEC_KERNEL_CHECK ) +if (IS_ENABLED (CONFIG_INTEGRITY_PLATFORM_KEYRING ) && rc && + func =KEXEC_KERNEL_CHECK ) rc = integrity_digsig_verify(INTEGRITY_KEYRING_PLATFORM, (const char *)xattr_value, xattr_len,
Re: [PATCH v2 7/7] ima: Support platform keyring for kernel appraisal
In reply to Nayna JainQuoted 19 lines · Nayna Jain
On secure boot enabled systems, the bootloader verifies the kernel image and possibly the initramfs signatures based on a set of keys. A soft reboot(kexec) of the system, with the same kernel image and initramfs, requires access to the original keys to verify the signatures.
This patch allows IMA-appraisal access to those original keys, now loaded on the platform keyring, needed for verifying the kernel image and initramfs signatures.
Signed-off-by Nayna Jain <[email protected]>Reviewed-by Mimi Zohar <[email protected]>Acked-by Serge Hallyn <[email protected]>- replace 'rc' with '
xattr_len' when callingintegrity_digsig_verify()withINTEGRITY_KEYRING_IMAfor readabilitySuggested-by Serge Hallyn <[email protected]>---
Changelog:
Quoted 6 lines
v2:
- replace 'rc' with 'xattr_len' when callingintegrity_digsig_verify()withINTEGRITY_KEYRING_IMAfor readabilitysecurity/integrity/ima/ima_appraise.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
With the change to only access the platform keyring when it is enabled:
--
Thiago Jung Bauermann
IBM Linux Technology Center
Mimi Zohar
maintainerHi Nayna,
Quoted 14 lines · Nayna Jain
On secure boot enabled systems, a verified kernel may need to kexec additional kernels. For example, it may be used as a bootloader needing to kexec a target kernel or it may need to kexec a crashdump kernel. In such cases, it may want to verify the signature of the next kernel image.
It is possible that the new kernel image is signed with third party keys which are stored as platform or firmware keys in the 'db' variable. The kernel, however, can not directly verify these platform keys, and an administrator may therefore not want to trust them for arbitrary usage. In order to differentiate platform keys from other keys and provide the necessary separation of trust the kernel needs an additional keyring to store platform/firmware keys.
Quoted 8 lines
The secure boot key database is expected to store the keys as EFI Signature List(ESL). The patch set uses David Howells and Josh Boyer's patch to access and parse the ESL to extract the certificates and load them onto the platform keyring.
The last patch in this patch set adds support for IMA-appraisal to verify the kexec'ed kernel image based on keys stored in the platform keyring.
Thanks! This patch set is now in the #next-integrity branch.
https://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity.git/
Mimi