Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KEYS: trusted: Introduce support for NXP CAAM-based trusted keys

The Cryptographic Acceleration and Assurance Module (CAAM) is an IP core
built into many newer i.MX and QorIQ SoCs by NXP.

The CAAM does crypto acceleration, hardware number generation and
has a blob mechanism for encapsulation/decapsulation of sensitive material.

This blob mechanism depends on a device specific random 256-bit One Time
Programmable Master Key that is fused in each SoC at manufacturing
time. This key is unreadable and can only be used by the CAAM for AES
encryption/decryption of user data.

This makes it a suitable backend (source) for kernel trusted keys.

Previous commits generalized trusted keys to support multiple backends
and added an API to access the CAAM blob mechanism. Based on these,
provide the necessary glue to use the CAAM for trusted keys.

Reviewed-by: David Gstir <david@sigma-star.at>
Reviewed-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Tested-by: Tim Harvey <tharvey@gateworks.com>
Tested-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Tested-by: Pankaj Gupta <pankaj.gupta@nxp.com>
Tested-by: Michael Walle <michael@walle.cc> # on ls1028a (non-E and E)
Tested-by: John Ernberg <john.ernberg@actia.se> # iMX8QXP
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>

authored by

Ahmad Fatoum and committed by
Jarkko Sakkinen
e9c5048c 007c3ff1

+109 -2
+1
Documentation/admin-guide/kernel-parameters.txt
··· 5958 5958 sources: 5959 5959 - "tpm" 5960 5960 - "tee" 5961 + - "caam" 5961 5962 If not specified then it defaults to iterating through 5962 5963 the trust source list starting with TPM and assigns the 5963 5964 first trust source as a backend which is initialized
+11
include/keys/trusted_caam.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-only */ 2 + /* 3 + * Copyright (C) 2021 Pengutronix, Ahmad Fatoum <kernel@pengutronix.de> 4 + */ 5 + 6 + #ifndef __CAAM_TRUSTED_KEY_H 7 + #define __CAAM_TRUSTED_KEY_H 8 + 9 + extern struct trusted_key_ops trusted_key_caam_ops; 10 + 11 + #endif
+10 -1
security/keys/trusted-keys/Kconfig
··· 24 24 Enable use of the Trusted Execution Environment (TEE) as trusted 25 25 key backend. 26 26 27 - if !TRUSTED_KEYS_TPM && !TRUSTED_KEYS_TEE 27 + config TRUSTED_KEYS_CAAM 28 + bool "CAAM-based trusted keys" 29 + depends on CRYPTO_DEV_FSL_CAAM_JR >= TRUSTED_KEYS 30 + select CRYPTO_DEV_FSL_CAAM_BLOB_GEN 31 + default y 32 + help 33 + Enable use of NXP's Cryptographic Accelerator and Assurance Module 34 + (CAAM) as trusted key backend. 35 + 36 + if !TRUSTED_KEYS_TPM && !TRUSTED_KEYS_TEE && !TRUSTED_KEYS_CAAM 28 37 comment "No trust source selected!" 29 38 endif
+2
security/keys/trusted-keys/Makefile
··· 12 12 trusted-$(CONFIG_TRUSTED_KEYS_TPM) += tpm2key.asn1.o 13 13 14 14 trusted-$(CONFIG_TRUSTED_KEYS_TEE) += trusted_tee.o 15 + 16 + trusted-$(CONFIG_TRUSTED_KEYS_CAAM) += trusted_caam.o
+80
security/keys/trusted-keys/trusted_caam.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright (C) 2021 Pengutronix, Ahmad Fatoum <kernel@pengutronix.de> 4 + */ 5 + 6 + #include <keys/trusted_caam.h> 7 + #include <keys/trusted-type.h> 8 + #include <linux/build_bug.h> 9 + #include <linux/key-type.h> 10 + #include <soc/fsl/caam-blob.h> 11 + 12 + static struct caam_blob_priv *blobifier; 13 + 14 + #define KEYMOD "SECURE_KEY" 15 + 16 + static_assert(MAX_KEY_SIZE + CAAM_BLOB_OVERHEAD <= CAAM_BLOB_MAX_LEN); 17 + static_assert(MAX_BLOB_SIZE <= CAAM_BLOB_MAX_LEN); 18 + 19 + static int trusted_caam_seal(struct trusted_key_payload *p, char *datablob) 20 + { 21 + int ret; 22 + struct caam_blob_info info = { 23 + .input = p->key, .input_len = p->key_len, 24 + .output = p->blob, .output_len = MAX_BLOB_SIZE, 25 + .key_mod = KEYMOD, .key_mod_len = sizeof(KEYMOD) - 1, 26 + }; 27 + 28 + ret = caam_encap_blob(blobifier, &info); 29 + if (ret) 30 + return ret; 31 + 32 + p->blob_len = info.output_len; 33 + return 0; 34 + } 35 + 36 + static int trusted_caam_unseal(struct trusted_key_payload *p, char *datablob) 37 + { 38 + int ret; 39 + struct caam_blob_info info = { 40 + .input = p->blob, .input_len = p->blob_len, 41 + .output = p->key, .output_len = MAX_KEY_SIZE, 42 + .key_mod = KEYMOD, .key_mod_len = sizeof(KEYMOD) - 1, 43 + }; 44 + 45 + ret = caam_decap_blob(blobifier, &info); 46 + if (ret) 47 + return ret; 48 + 49 + p->key_len = info.output_len; 50 + return 0; 51 + } 52 + 53 + static int trusted_caam_init(void) 54 + { 55 + int ret; 56 + 57 + blobifier = caam_blob_gen_init(); 58 + if (IS_ERR(blobifier)) 59 + return PTR_ERR(blobifier); 60 + 61 + ret = register_key_type(&key_type_trusted); 62 + if (ret) 63 + caam_blob_gen_exit(blobifier); 64 + 65 + return ret; 66 + } 67 + 68 + static void trusted_caam_exit(void) 69 + { 70 + unregister_key_type(&key_type_trusted); 71 + caam_blob_gen_exit(blobifier); 72 + } 73 + 74 + struct trusted_key_ops trusted_key_caam_ops = { 75 + .migratable = 0, /* non-migratable */ 76 + .init = trusted_caam_init, 77 + .seal = trusted_caam_seal, 78 + .unseal = trusted_caam_unseal, 79 + .exit = trusted_caam_exit, 80 + };
+5 -1
security/keys/trusted-keys/trusted_core.c
··· 9 9 #include <keys/user-type.h> 10 10 #include <keys/trusted-type.h> 11 11 #include <keys/trusted_tee.h> 12 + #include <keys/trusted_caam.h> 12 13 #include <keys/trusted_tpm.h> 13 14 #include <linux/capability.h> 14 15 #include <linux/err.h> ··· 30 29 31 30 static char *trusted_key_source; 32 31 module_param_named(source, trusted_key_source, charp, 0); 33 - MODULE_PARM_DESC(source, "Select trusted keys source (tpm or tee)"); 32 + MODULE_PARM_DESC(source, "Select trusted keys source (tpm, tee or caam)"); 34 33 35 34 static const struct trusted_key_source trusted_key_sources[] = { 36 35 #if defined(CONFIG_TRUSTED_KEYS_TPM) ··· 38 37 #endif 39 38 #if defined(CONFIG_TRUSTED_KEYS_TEE) 40 39 { "tee", &trusted_key_tee_ops }, 40 + #endif 41 + #if defined(CONFIG_TRUSTED_KEYS_CAAM) 42 + { "caam", &trusted_key_caam_ops }, 41 43 #endif 42 44 }; 43 45