Skip to contentSkip to conversation

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

PATCH Applied Ahmad Fatoum 5 participants 30 messages May 13, 2022 – May 19, 2022

Subsystems (9)
lore
Share & tools
lore

Ahmad Fatoum

author maintainer
#0 lore raw

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

Series applies on top of v5.18-rc6. Would be great if this could make it into v5.19.

v9 was here:
https://lore.kernel.org/linux-integrity/[email protected]

Changelog is beneath each individual patch. Compared to v9, only code change is checking whether CAAM can support blobbing at init-time for CAAM revisions < 10 (such as LS1046A) to avoid a cryptic error message at first use.

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

Its blob mechanism can AES encrypt/decrypt user data using a unique never-disclosed device-specific key.

There has been multiple discussions on how to represent this within the kernel:

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

Its blob mechanism can AES encrypt/decrypt user data using a unique never-disclosed device-specific key. There has been multiple discussions on how to represent this within the kernel:

- [RFC] crypto: caam - add red blobifier
Steffen implemented[1] a PoC sysfs driver to start a discussion on how to best integrate the blob mechanism.
Mimi suggested that it could be used to implement trusted keys. Trusted keys back then were a TPM-only feature.

- security/keys/secure_key: Adds the secure key support based on CAAM. Udit Agarwal added[2] a new "secure" key type with the CAAM as backend. The key material stays within the kernel only.
Mimi and James agreed that this needs a generic interface, not specific to CAAM. Mimi suggested trusted keys. Jan noted that this could serve as basis for TEE-backed keys.

- [RFC] drivers: crypto: caam: key: Add caam_tk key type
Franck added[3] a new "caam_tk" key type based on Udit's work. This time it uses CAAM "black blobs" instead of "red blobs", so key material stays within the CAAM and isn't exposed to kernel in plaintext. James voiced the opinion that there should be just one user-facing generic wrap/unwrap key type with multiple possible handlers.
David suggested trusted keys.

- Introduce TEE based Trusted Keys support
Sumit reworked[4] trusted keys to support multiple possible backends with one chosen at boot time and added a new TEE backend along with TPM. This now sits in Jarkko's master branch to be sent out for v5.13

This patch series builds on top of Sumit's rework to have the CAAM as yet another trusted key backend.

The CAAM bits are based on Steffen's initial patch from 2015. His work had been used in the field for some years now, so I preferred not to deviate too much from it.

This series has been tested with dmcrypt[5] on an i.MX6Q/DL, i.MX8M[6] and LS1028[7].

Looking forward to your feedback.

Cheers,
Ahmad

[1]: https://lore.kernel.org/linux-crypto/[email protected]/
[2]: https://lore.kernel.org/linux-integrity/[email protected]/
[3]: https://lore.kernel.org/lkml/[email protected]/
[4]: https://lore.kernel.org/lkml/[email protected]/
[5]: https://lore.kernel.org/linux-integrity/[email protected]/
[6]: https://lore.kernel.org/linux-integrity/DU2PR04MB8630D83FE9BBC0D782C4FAF595089@DU2PR04MB8630.eurprd04.prod.outlook.com/
[7]: https://lore.kernel.org/linux-integrity/[email protected]/

---
To: Jarkko Sakkinen <[email protected]>
To: "Horia Geantă" <[email protected]>
To: Mimi Zohar <[email protected]>
To: Pankaj Gupta <[email protected]>
To: Herbert Xu <[email protected]>
To: "David S. Miller" <[email protected]>
To: James Bottomley <[email protected]>
Cc: David Howells <[email protected]>
Cc: James Morris <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: Steffen Trumtrar <[email protected]>
Cc: Jan Luebbe <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Franck LENORMAND <[email protected]>
Cc: Sumit Garg <[email protected]>
Cc: Andreas Rammhold <[email protected]>
Cc: Tim Harvey <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Ahmad Fatoum (7):
KEYS: trusted: allow use of TEE as backend without TCG_TPM support
KEYS: trusted: allow use of kernel RNG for key material
crypto: caam - determine whether CAAM supports blob encap/decap
crypto: caam - add in-kernel interface for blob generator
KEYS: trusted: Introduce support for NXP CAAM-based trusted keys
doc: trusted-encrypted: describe new CAAM trust source
MAINTAINERS: add KEYS-TRUSTED-CAAM

 .../admin-guide/kernel-parameters.txt         |  11 ++
 .../security/keys/trusted-encrypted.rst       |  60 +++++-
 MAINTAINERS                                   |   9 +
 drivers/crypto/caam/Kconfig                   |   3 +
 drivers/crypto/caam/Makefile                  |   1 +
 drivers/crypto/caam/blob_gen.c                | 182 ++++++++++++++++++
 drivers/crypto/caam/ctrl.c                    |  17 +-
 drivers/crypto/caam/intern.h                  |   1 +
 drivers/crypto/caam/regs.h                    |   4 +-
 include/keys/trusted-type.h                   |   2 +-
 include/keys/trusted_caam.h                   |  11 ++
 include/soc/fsl/caam-blob.h                   | 103 ++++++++++
 security/keys/Kconfig                         |  18 +-
 security/keys/trusted-keys/Kconfig            |  38 ++++
 security/keys/trusted-keys/Makefile           |  10 +-
 security/keys/trusted-keys/trusted_caam.c     |  80 ++++++++
 security/keys/trusted-keys/trusted_core.c     |  45 ++++-
 17 files changed, 563 insertions(+), 32 deletions(-)
 create mode 100644 drivers/crypto/caam/blob_gen.c
 create mode 100644 include/keys/trusted_caam.h
 create mode 100644 include/soc/fsl/caam-blob.h
 create mode 100644 security/keys/trusted-keys/Kconfig
 create mode 100644 security/keys/trusted-keys/trusted_caam.c
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH v10 1/7 KEYS: trusted: allow use of TEE as backend without TCG_TPM support

With recent rework, trusted keys are no longer limited to TPM as trust source. The Kconfig symbol is unchanged however leading to a few issues:

- TCG_TPM is required, even if only TEE is to be used
- Enabling TCG_TPM, but excluding it from available trusted sources is not possible
- TEE=m && TRUSTED_KEYS=y will lead to TEE support being silently dropped, which is not the best user experience

Remedy these issues by introducing two new boolean Kconfig symbols:
TRUSTED_KEYS_TPM and TRUSTED_KEYS_TEE with the appropriate dependencies.

Any new code depending on the TPM trusted key backend in particular or symbols exported by it will now need to explicitly state that it

  depends on TRUSTED_KEYS && TRUSTED_KEYS_TPM

The latter to ensure the dependency is built and the former to ensure it's reachable for module builds. There are no such users yet.

---
v9 -> v10:
- added Michael's and John's Tested-by
v8 -> v9:
- no changes
v7 -> v8:
- add Pankaj's Reviewed-by and Tested-by
v6 -> v7:
- s/Tested-By/Tested-by/
v5 -> v6:
- Rebased on asym_tpm removal
v4 -> v5:
- collected Jarkko's Reviewed-by
v3 -> v4:
- rebased on top of Andreas' regression fix and pulled it back into series
v2 -> v3:
- factored this patch out as a fix for backporting
v1 -> v2:
- Move rest of TPM-related selects from TRUSTED_KEYS to TRUSTED_KEYS_TPM (Sumit)
- Remove left-over line in Makefile (Sumit)
- added Fixes: tag
- adjust commit message to reference the regression reported by Andreas
- have ASYMMETRIC_TPM_KEY_SUBTYPE depend on TRUSTED_KEYS_TPM, because it references global symbols that are exported by the trusted key TPM backend.

[1]: https://lore.kernel.org/linux-integrity/f8285eb0135ba30c9d846cf9dd395d1f5f8b1efc.1624364386.git-series.a.fatoum@pengutronix.de/
[2]: https://lore.kernel.org/linux-integrity/20210719091335.vwfebcpkf4pag3wm@wrt/T/#t

To: Jarkko Sakkinen <[email protected]>
To: James Morris <[email protected]>
To: "Serge E. Hallyn" <[email protected]>
To: James Bottomley <[email protected]>
To: Mimi Zohar <[email protected]>
To: Sumit Garg <[email protected]>
To: David Howells <[email protected]>
To: Herbert Xu <[email protected]>
To: "David S. Miller" <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Pankaj Gupta <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 security/keys/Kconfig                     | 18 ++++++--------
 security/keys/trusted-keys/Kconfig        | 29 +++++++++++++++++++++++
 security/keys/trusted-keys/Makefile       |  8 +++----
 security/keys/trusted-keys/trusted_core.c |  4 ++--
 4 files changed, 42 insertions(+), 17 deletions(-)
 create mode 100644 security/keys/trusted-keys/Kconfig
security/keys/Kconfig +7 -11
index 0e30b361e1c1..abb03a1b2a5c 100644
@@ -70,23 +70,19 @@ config BIG_KEYS
 
 config TRUSTED_KEYS
 	tristate "TRUSTED KEYS"
-	depends on KEYS && TCG_TPM
-	select CRYPTO
-	select CRYPTO_HMAC
-	select CRYPTO_SHA1
-	select CRYPTO_HASH_INFO
-	select ASN1_ENCODER
-	select OID_REGISTRY
-	select ASN1
+	depends on KEYS
 	help
 	  This option provides support for creating, sealing, and unsealing
 	  keys in the kernel. Trusted keys are random number symmetric keys,
-	  generated and RSA-sealed by the TPM. The TPM only unseals the keys,
-	  if the boot PCRs and other criteria match.  Userspace will only ever
-	  see encrypted blobs.
+	  generated and sealed by a trust source selected at kernel boot-time.
+	  Userspace will only ever see encrypted blobs.
 
 	  If you are unsure as to whether this is required, answer N.
 
+if TRUSTED_KEYS
+source "security/keys/trusted-keys/Kconfig"
+endif
+
 config ENCRYPTED_KEYS
 	tristate "ENCRYPTED KEYS"
 	depends on KEYS
security/keys/trusted-keys/Kconfig new file +29 -0
new file mode 100644
index 000000000000..fc4abd581abb
@@ -0,0 +1,29 @@
+config TRUSTED_KEYS_TPM
+	bool "TPM-based trusted keys"
+	depends on TCG_TPM >= TRUSTED_KEYS
+	default y
+	select CRYPTO
+	select CRYPTO_HMAC
+	select CRYPTO_SHA1
+	select CRYPTO_HASH_INFO
+	select ASN1_ENCODER
+	select OID_REGISTRY
+	select ASN1
+	help
+	  Enable use of the Trusted Platform Module (TPM) as trusted key
+	  backend. Trusted keys are random number symmetric keys,
+	  which will be generated and RSA-sealed by the TPM.
+	  The TPM only unseals the keys, if the boot PCRs and other
+	  criteria match.
+
+config TRUSTED_KEYS_TEE
+	bool "TEE-based trusted keys"
+	depends on TEE >= TRUSTED_KEYS
+	default y
+	help
+	  Enable use of the Trusted Execution Environment (TEE) as trusted
+	  key backend.
+
+if !TRUSTED_KEYS_TPM && !TRUSTED_KEYS_TEE
+comment "No trust source selected!"
+endif
security/keys/trusted-keys/Makefile +4 -4
index feb8b6c3cc79..2e2371eae4d5 100644
@@ -5,10 +5,10 @@
 
 obj-$(CONFIG_TRUSTED_KEYS) += trusted.o
 trusted-y += trusted_core.o
-trusted-y += trusted_tpm1.o
+trusted-$(CONFIG_TRUSTED_KEYS_TPM) += trusted_tpm1.o
 
 $(obj)/trusted_tpm2.o: $(obj)/tpm2key.asn1.h
-trusted-y += trusted_tpm2.o
-trusted-y += tpm2key.asn1.o
+trusted-$(CONFIG_TRUSTED_KEYS_TPM) += trusted_tpm2.o
+trusted-$(CONFIG_TRUSTED_KEYS_TPM) += tpm2key.asn1.o
 
-trusted-$(CONFIG_TEE) += trusted_tee.o
+trusted-$(CONFIG_TRUSTED_KEYS_TEE) += trusted_tee.o
security/keys/trusted-keys/trusted_core.c +2 -2
index 9b9d3ef79cbe..7cdbd16aed30 100644
@@ -27,10 +27,10 @@ module_param_named(source, trusted_key_source, charp, 0);
 MODULE_PARM_DESC(source, "Select trusted keys source (tpm or tee)");
 
 static const struct trusted_key_source trusted_key_sources[] = {
-#if IS_REACHABLE(CONFIG_TCG_TPM)
+#if defined(CONFIG_TRUSTED_KEYS_TPM)
 	{ "tpm", &trusted_key_tpm_ops },
 #endif
-#if IS_REACHABLE(CONFIG_TEE)
+#if defined(CONFIG_TRUSTED_KEYS_TEE)
 	{ "tee", &trusted_key_tee_ops },
 #endif
 };
Signature · 1 line
2.30.2
author maintainer
#2 lore raw

PATCH v10 2/7 KEYS: trusted: allow use of kernel RNG for key material

In reply to Ahmad Fatoum

The two existing trusted key sources don't make use of the kernel RNG, but instead let the hardware doing the sealing/unsealing also generate the random key material. However, both users and future backends may want to place less trust into the quality of the trust source's random number generator and instead reuse the kernel entropy pool, which can be seeded from multiple entropy sources.

Make this possible by adding a new trusted.rng parameter, that will force use of the kernel RNG. In its absence, it's up to the trust source to decide, which random numbers to use, maintaining the existing behavior.

---
v9 -> v10:
- added Michael's and John's Tested-by
v8 -> v9:
- No changes
v7 -> v8:
- add Pankaj's Tested-by
v6 -> v7:
- No changes
v5 -> v6:
- Squash with follow-up patch enabling trust sources to use kernel RNG if they don't define their own .get_random
- Collected Jarkko's Reviewed-by
v4 -> v5:
- Changed trusted.kernel_rng bool option into a string trusted.rng option (Jarkko)
- Typo fix in commit message (Jarkko)
v3 -> v4:
- Collected Acked-by's, Reviewed-by's and Tested-by
v2 -> v3:
- No change
v1 -> v2:
- Allow users to force use of kernel RNG (Jarkko)

To: James Bottomley <[email protected]>
To: Jarkko Sakkinen <[email protected]>
To: Mimi Zohar <[email protected]>
To: David Howells <[email protected]>
Cc: James Morris <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: "Horia Geantă" <[email protected]>
Cc: Pankaj Gupta <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Jan Luebbe <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Franck LENORMAND <[email protected]>
Cc: Sumit Garg <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 .../admin-guide/kernel-parameters.txt         | 10 ++++++
 .../security/keys/trusted-encrypted.rst       | 20 ++++++-----
 include/keys/trusted-type.h                   |  2 +-
 security/keys/trusted-keys/trusted_core.c     | 35 ++++++++++++++++++-
 4 files changed, 57 insertions(+), 10 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +10 -0
index 3f1cc5e317ed..4deed1908a75 100644
@@ -5963,6 +5963,16 @@
 			first trust source as a backend which is initialized
 			successfully during iteration.
 
+	trusted.rng=	[KEYS]
+			Format: <string>
+			The RNG used to generate key material for trusted keys.
+			Can be one of:
+			- "kernel"
+			- the same value as trusted.source: "tpm" or "tee"
+			- "default"
+			If not specified, "default" is used. In this case,
+			the RNG's choice is left to each individual trust source.
+
 	tsc=		Disable clocksource stability checks for TSC.
 			Format: <string>
 			[x86] reliable: mark tsc clocksource as reliable, this
Documentation/security/keys/trusted-encrypted.rst +12 -8
index f614dad7de12..2fe6fd1a2bbd 100644
@@ -87,22 +87,26 @@ Key Generation
 Trusted Keys
 ------------
 
-New keys are created from random numbers generated in the trust source. They
-are encrypted/decrypted using a child key in the storage key hierarchy.
-Encryption and decryption of the child key must be protected by a strong
-access control policy within the trust source.
+New keys are created from random numbers. They are encrypted/decrypted using
+a child key in the storage key hierarchy. Encryption and decryption of the
+child key must be protected by a strong access control policy within the
+trust source. The random number generator in use differs according to the
+selected trust source:
 
-  *  TPM (hardware device) based RNG
+  *  TPM: hardware device based RNG
 
-     Strength of random numbers may vary from one device manufacturer to
-     another.
+     Keys are generated within the TPM. Strength of random numbers may vary
+     from one device manufacturer to another.
 
-  *  TEE (OP-TEE based on Arm TrustZone) based RNG
+  *  TEE: OP-TEE based on Arm TrustZone based RNG
 
      RNG is customizable as per platform needs. It can either be direct output
      from platform specific hardware RNG or a software based Fortuna CSPRNG
      which can be seeded via multiple entropy sources.
 
+Users may override this by specifying ``trusted.rng=kernel`` on the kernel
+command-line to override the used RNG with the kernel's random number pool.
+
 Encrypted Keys
 --------------
 
include/keys/trusted-type.h +1 -1
index d89fa2579ac0..4eb64548a74f 100644
@@ -64,7 +64,7 @@ struct trusted_key_ops {
 	/* Unseal a key. */
 	int (*unseal)(struct trusted_key_payload *p, char *datablob);
 
-	/* Get a randomized key. */
+	/* Optional: Get a randomized key. */
 	int (*get_random)(unsigned char *key, size_t key_len);
 
 	/* Exit key interface. */
security/keys/trusted-keys/trusted_core.c +34 -1
index 7cdbd16aed30..9235fb7d0ec9 100644
@@ -16,12 +16,17 @@
 #include <linux/key-type.h>
 #include <linux/module.h>
 #include <linux/parser.h>
+#include <linux/random.h>
 #include <linux/rcupdate.h>
 #include <linux/slab.h>
 #include <linux/static_call.h>
 #include <linux/string.h>
 #include <linux/uaccess.h>
 
+static char *trusted_rng = "default";
+module_param_named(rng, trusted_rng, charp, 0);
+MODULE_PARM_DESC(rng, "Select trusted key RNG");
+
 static char *trusted_key_source;
 module_param_named(source, trusted_key_source, charp, 0);
 MODULE_PARM_DESC(source, "Select trusted keys source (tpm or tee)");
@@ -312,8 +317,14 @@ struct key_type key_type_trusted = {
 };
 EXPORT_SYMBOL_GPL(key_type_trusted);
 
+static int kernel_get_random(unsigned char *key, size_t key_len)
+{
+	return get_random_bytes_wait(key, key_len) ?: key_len;
+}
+
 static int __init init_trusted(void)
 {
+	int (*get_random)(unsigned char *key, size_t key_len);
 	int i, ret = 0;
 
 	for (i = 0; i < ARRAY_SIZE(trusted_key_sources); i++) {
@@ -322,6 +333,28 @@ static int __init init_trusted(void)
 			    strlen(trusted_key_sources[i].name)))
 			continue;
 
+		/*
+		 * We always support trusted.rng="kernel" and "default" as
+		 * well as trusted.rng=$trusted.source if the trust source
+		 * defines its own get_random callback.
+		 */
+		get_random = trusted_key_sources[i].ops->get_random;
+		if (trusted_rng && strcmp(trusted_rng, "default")) {
+			if (!strcmp(trusted_rng, "kernel")) {
+				get_random = kernel_get_random;
+			} else if (strcmp(trusted_rng, trusted_key_sources[i].name) ||
+				   !get_random) {
+				pr_warn("Unsupported RNG. Supported: kernel");
+				if (get_random)
+					pr_cont(", %s", trusted_key_sources[i].name);
+				pr_cont(", default\n");
+				return -EINVAL;
+			}
+		}
+
+		if (!get_random)
+			get_random = kernel_get_random;
+
 		static_call_update(trusted_key_init,
 				   trusted_key_sources[i].ops->init);
 		static_call_update(trusted_key_seal,
@@ -329,7 +362,7 @@ static int __init init_trusted(void)
 		static_call_update(trusted_key_unseal,
 				   trusted_key_sources[i].ops->unseal);
 		static_call_update(trusted_key_get_random,
-				   trusted_key_sources[i].ops->get_random);
+				   get_random);
 		static_call_update(trusted_key_exit,
 				   trusted_key_sources[i].ops->exit);
 		migratable = trusted_key_sources[i].ops->migratable;
Signature · 1 line
2.30.2
maintainer
#3 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Quoted 7 lines · Ahmad Fatoum

static int __init init_trusted(void)
{

security/keys/trusted-keys/trusted_core.c +1 -0
+       int (*get_random)(unsigned char *key, size_t key_len);
        int i, ret = 0;
 
        for (i = 0; i < ARRAY_SIZE(trusted_key_sources); i++) {

security/keys/trusted-keys/trusted_core.c static int __init init_trusted(void) · line 340

Quoted 8 lines
security/keys/trusted-keys/trusted_core.c +5 -0
@@ -322,6 +333,28 @@ static int __init init_trusted(void)
                            strlen(trusted_key_sources[i].name)))
                        continue;
 
+               /*
+                * We always support trusted.rng="kernel" and "default" as
+                * well as trusted.rng=$trusted.source if the trust source
+                * defines its own get_random callback.
+                */

While TEE trusted keys support was upstreamed, there was a lot of discussion about using kernel RNG. One of the concerns was lack of or insuffiencent entropy during early boot on embedded devices. This concern needs to be clearly documented in both Documentation/admin- guide/kernel-parameters.txt and Documentation/security/keys/trusted- encrypted.rst.

thanks,

Mimi

Quoted 19 lines
security/keys/trusted-keys/trusted_core.c +17 -0
+               get_random = trusted_key_sources[i].ops->get_random;
+               if (trusted_rng && strcmp(trusted_rng, "default")) {
+                       if (!strcmp(trusted_rng, "kernel")) {
+                               get_random = kernel_get_random;
+                       } else if (strcmp(trusted_rng, trusted_key_sources[i].name) ||
+                                  !get_random) {
+                               pr_warn("Unsupported RNG. Supported: kernel");
+                               if (get_random)
+                                       pr_cont(", %s", trusted_key_sources[i].name);
+                               pr_cont(", default\n");
+                               return -EINVAL;
+                       }
+               }
+
+               if (!get_random)
+                       get_random = kernel_get_random;
+
                static_call_update(trusted_key_init,
                                   trusted_key_sources[i].ops->init);
author maintainer
#4 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Hello Mimi,

[Cc'ing RNG maintainers in case they want to chime in]

Quoted 11 lines · Mimi Zohar
Quoted 10 lines · Ahmad Fatoum

static int __init init_trusted(void)
{

security/keys/trusted-keys/trusted_core.c +1 -0
+       int (*get_random)(unsigned char *key, size_t key_len);
        int i, ret = 0;
 
        for (i = 0; i < ARRAY_SIZE(trusted_key_sources); i++) {
@@ -322,6 +333,28 @@ static int __init init_trusted(void)
                            strlen(trusted_key_sources[i].name)))
                        continue;
 
Quoted 12 lines

security/keys/trusted-keys/trusted_core.c static int __init init_trusted(void) · line 340

Quoted 5 lines
security/keys/trusted-keys/trusted_core.c +5 -0
+               /*
+                * We always support trusted.rng="kernel" and "default" as
+                * well as trusted.rng=$trusted.source if the trust source
+                * defines its own get_random callback.
+                */

While TEE trusted keys support was upstreamed, there was a lot of discussion about using kernel RNG. One of the concerns was lack of or insuffiencent entropy during early boot on embedded devices. This concern needs to be clearly documented in both Documentation/admin- guide/kernel-parameters.txt and Documentation/security/keys/trusted- encrypted.rst.

If a user decides to use kernel RNG for trusted keys, wait_for_random_bytes() called first thing in the used get_random_bytes_wait() will (quoting documentation) "wait for the input pool to be seeded and thus [is] guaranteed to supply cryptographically secure random numbers."

Does this address your concerns about Kernel RNG use?

Thanks,
Ahmad

Quoted 26 lines

thanks,

Mimi

Quoted 19 lines
security/keys/trusted-keys/trusted_core.c +17 -0
+               get_random = trusted_key_sources[i].ops->get_random;
+               if (trusted_rng && strcmp(trusted_rng, "default")) {
+                       if (!strcmp(trusted_rng, "kernel")) {
+                               get_random = kernel_get_random;
+                       } else if (strcmp(trusted_rng, trusted_key_sources[i].name) ||
+                                  !get_random) {
+                               pr_warn("Unsupported RNG. Supported: kernel");
+                               if (get_random)
+                                       pr_cont(", %s", trusted_key_sources[i].name);
+                               pr_cont(", default\n");
+                               return -EINVAL;
+                       }
+               }
+
+               if (!get_random)
+                       get_random = kernel_get_random;
+
                static_call_update(trusted_key_init,
                                   trusted_key_sources[i].ops->init);
Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#5 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Hi Ahmad,

Quoted 3 lines · Ahmad Fatoum

Hello Mimi,

[Cc'ing RNG maintainers in case they want to chime in]

Thanks for adding me to this thread.

Quoted 25 lines · Mimi Zohar
Quoted 11 lines · Ahmad Fatoum
Quoted 10 lines

static int __init init_trusted(void)
{

security/keys/trusted-keys/trusted_core.c +1 -0
+       int (*get_random)(unsigned char *key, size_t key_len);
        int i, ret = 0;
 
        for (i = 0; i < ARRAY_SIZE(trusted_key_sources); i++) {
@@ -322,6 +333,28 @@ static int __init init_trusted(void)
                            strlen(trusted_key_sources[i].name)))
                        continue;
 
Quoted 12 lines

security/keys/trusted-keys/trusted_core.c static int __init init_trusted(void) · line 340

Quoted 5 lines
security/keys/trusted-keys/trusted_core.c +5 -0
+               /*
+                * We always support trusted.rng="kernel" and "default" as
+                * well as trusted.rng=$trusted.source if the trust source
+                * defines its own get_random callback.
+                */

While TEE trusted keys support was upstreamed, there was a lot of discussion about using kernel RNG. One of the concerns was lack of or insuffiencent entropy during early boot on embedded devices. This concern needs to be clearly documented in both Documentation/admin- guide/kernel-parameters.txt and Documentation/security/keys/trusted- encrypted.rst.

Quoted 6 lines

If a user decides to use kernel RNG for trusted keys, wait_for_random_bytes() called first thing in the used get_random_bytes_wait() will (quoting documentation) "wait for the input pool to be seeded and thus [is] guaranteed to supply cryptographically secure random numbers."

Does this address your concerns about Kernel RNG use?

Indeed if get_random_bytes_wait() or wait_for_random_bytes() is called, then the RNG will just block until it's accumulated 256 bits of estimated entropy. The RNG will also make use of whatever hwrng or cpu rng capabilities are available, and mix those in to augment its own output.

Jason

#6 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

In reply to Mimi Zohar
Quoted 11 lines · Mimi Zohar
Quoted 10 lines · Ahmad Fatoum

static int __init init_trusted(void)
{

security/keys/trusted-keys/trusted_core.c +1 -0
+       int (*get_random)(unsigned char *key, size_t key_len);
        int i, ret = 0;
 
        for (i = 0; i < ARRAY_SIZE(trusted_key_sources); i++) {
@@ -322,6 +333,28 @@ static int __init init_trusted(void)
                            strlen(trusted_key_sources[i].name)))
                        continue;
 
Quoted 12 lines

security/keys/trusted-keys/trusted_core.c static int __init init_trusted(void) · line 340

Quoted 5 lines
security/keys/trusted-keys/trusted_core.c +5 -0
+               /*
+                * We always support trusted.rng="kernel" and "default" as
+                * well as trusted.rng=$trusted.source if the trust source
+                * defines its own get_random callback.
+                */

While TEE trusted keys support was upstreamed, there was a lot of discussion about using kernel RNG. One of the concerns was lack of or insuffiencent entropy during early boot on embedded devices. This concern needs to be clearly documented in both Documentation/admin- guide/kernel-parameters.txt and Documentation/security/keys/trusted- encrypted.rst.

Sounds like FUD. Use get_random_bytes_wait(), and you'll be fine.

Jason

maintainer
#7 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Quoted 25 lines · Jason A. Donenfeld
Quoted 11 lines · Mimi Zohar
Quoted 10 lines · Ahmad Fatoum

static int __init init_trusted(void)
{

security/keys/trusted-keys/trusted_core.c +1 -0
+       int (*get_random)(unsigned char *key, size_t key_len);
        int i, ret = 0;
 
        for (i = 0; i < ARRAY_SIZE(trusted_key_sources); i++) {
@@ -322,6 +333,28 @@ static int __init init_trusted(void)
                            strlen(trusted_key_sources[i].name)))
                        continue;
 
Quoted 12 lines

security/keys/trusted-keys/trusted_core.c static int __init init_trusted(void) · line 340

Quoted 5 lines
security/keys/trusted-keys/trusted_core.c +5 -0
+               /*
+                * We always support trusted.rng="kernel" and "default" as
+                * well as trusted.rng=$trusted.source if the trust source
+                * defines its own get_random callback.
+                */

While TEE trusted keys support was upstreamed, there was a lot of discussion about using kernel RNG. One of the concerns was lack of or insuffiencent entropy during early boot on embedded devices. This concern needs to be clearly documented in both Documentation/admin- guide/kernel-parameters.txt and Documentation/security/keys/trusted- encrypted.rst.

Quoted 1 line

Sounds like FUD. Use get_random_bytes_wait(), and you'll be fine.

As per the original discussion, there's also certification requirements [1].

Mimi

[1] https://lkml.org/lkml/2019/10/9/53

#8 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Hi Mimi,

Quoted 26 lines · Mimi Zohar
Quoted 25 lines · Jason A. Donenfeld
Quoted 23 lines · Mimi Zohar
Quoted 7 lines · Ahmad Fatoum

static int __init init_trusted(void)
{

security/keys/trusted-keys/trusted_core.c +1 -0
+       int (*get_random)(unsigned char *key, size_t key_len);
        int i, ret = 0;
 
        for (i = 0; i < ARRAY_SIZE(trusted_key_sources); i++) {

security/keys/trusted-keys/trusted_core.c static int __init init_trusted(void) · line 340

Quoted 8 lines
security/keys/trusted-keys/trusted_core.c +5 -0
@@ -322,6 +333,28 @@ static int __init init_trusted(void)
                            strlen(trusted_key_sources[i].name)))
                        continue;
 
+               /*
+                * We always support trusted.rng="kernel" and "default" as
+                * well as trusted.rng=$trusted.source if the trust source
+                * defines its own get_random callback.
+                */

While TEE trusted keys support was upstreamed, there was a lot of discussion about using kernel RNG. One of the concerns was lack of or insuffiencent entropy during early boot on embedded devices. This concern needs to be clearly documented in both Documentation/admin- guide/kernel-parameters.txt and Documentation/security/keys/trusted- encrypted.rst.

Quoted 4 lines
Quoted 1 line

Sounds like FUD. Use get_random_bytes_wait(), and you'll be fine.

As per the original discussion, there's also certification requirements [1].

As per countless conversations on this mailing list -- which I really really really hope you will not attempt to drown me in again -- I'm not too keen on the certification requirements. Let's just leave that conversation there.

There *is* a cryptographic design reason why you might want certain keys generated on a TPM rather than in the kernel though: so that the keys can be marked as unexportable and never leave the hardware. In that case -- I assume -- the kernel just operates on a handle to the key, rather than possessing the key material itself. And this is probably a good thing. (On the other hand, people who think the TPM might be backdoored may prefer the kernel's open source RNG, which in theory is in a position to aggregate entropy from many sources, so that one being backdoored isn't a problem. So maybe that's the purpose of having this switch?)

So to the extent that this driver (I haven't looked deeply at it) is doing the thing where a TPM generates the key and just returns a handle to it, that sounds good. But if actually you're implementing some wrapper around a hardware rng, it'd be convenient if there was instead a hw_random driver for this, so it can be one of the many sources that the kernel rng aggregates.

Apologies in advance if I've missed the mark here; I'm not very familiar with this thread or what it's driving at. If the simple question was just "is get_random_bytes_wait() good to use?" the answer is just "yes" and I can disappear and stop confusing things. :)

Jason

maintainer
#9 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Quoted 57 lines · Jason A. Donenfeld

Hi Mimi,

Quoted 26 lines · Mimi Zohar
Quoted 25 lines · Jason A. Donenfeld
Quoted 23 lines · Mimi Zohar
Quoted 7 lines · Ahmad Fatoum

static int __init init_trusted(void)
{

security/keys/trusted-keys/trusted_core.c +1 -0
+       int (*get_random)(unsigned char *key, size_t key_len);
        int i, ret = 0;
 
        for (i = 0; i < ARRAY_SIZE(trusted_key_sources); i++) {

security/keys/trusted-keys/trusted_core.c static int __init init_trusted(void) · line 340

Quoted 8 lines
security/keys/trusted-keys/trusted_core.c +5 -0
@@ -322,6 +333,28 @@ static int __init init_trusted(void)
                            strlen(trusted_key_sources[i].name)))
                        continue;
 
+               /*
+                * We always support trusted.rng="kernel" and "default" as
+                * well as trusted.rng=$trusted.source if the trust source
+                * defines its own get_random callback.
+                */

While TEE trusted keys support was upstreamed, there was a lot of discussion about using kernel RNG. One of the concerns was lack of or insuffiencent entropy during early boot on embedded devices. This concern needs to be clearly documented in both Documentation/admin- guide/kernel-parameters.txt and Documentation/security/keys/trusted- encrypted.rst.

Quoted 4 lines
Quoted 1 line

Sounds like FUD. Use get_random_bytes_wait(), and you'll be fine.

As per the original discussion, there's also certification requirements [1].

As per countless conversations on this mailing list -- which I really really really hope you will not attempt to drown me in again -- I'm not too keen on the certification requirements. Let's just leave that conversation there.

There *is* a cryptographic design reason why you might want certain keys generated on a TPM rather than in the kernel though: so that the keys can be marked as unexportable and never leave the hardware. In that case -- I assume -- the kernel just operates on a handle to the key, rather than possessing the key material itself. And this is probably a good thing. (On the other hand, people who think the TPM might be backdoored may prefer the kernel's open source RNG, which in theory is in a position to aggregate entropy from many sources, so that one being backdoored isn't a problem. So maybe that's the purpose of having this switch?)

So to the extent that this driver (I haven't looked deeply at it) is doing the thing where a TPM generates the key and just returns a handle to it, that sounds good. But if actually you're implementing some wrapper around a hardware rng, it'd be convenient if there was instead a hw_random driver for this, so it can be one of the many sources that the kernel rng aggregates.

Quoted 4 lines

Apologies in advance if I've missed the mark here; I'm not very familiar with this thread or what it's driving at. If the simple question was just "is get_random_bytes_wait() good to use?" the answer is just "yes" and I can disappear and stop confusing things. :)

My apologies for your having been brought into this discussion without
having properly reviewed and summarized the previous thread. As you
saw there is a long history.

Jarrko, Ahmad, "Trusted" keys, by definition, are based on the TPM RNG. If CAAM trusted key support wants to use kernel RNG by default, that's fine. However defining and allowing a boot command line option to use kernel RNG instead of the TPM RNG, needs to be configurable.

thanks,

Mimi

author maintainer
#10 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Hello Mimi,

Quoted 10 lines · Mimi Zohar
Quoted 8 lines · Jason A. Donenfeld

Hi Mimi,

Quoted 1 line · Mimi Zohar

On Tue, 2022-05-17 at 19:38 +0200, Jason A. Donenfeld wrote:

Apologies in advance if I've missed the mark here; I'm not very familiar with this thread or what it's driving at. If the simple question was just "is get_random_bytes_wait() good to use?" the answer is just "yes" and I can disappear and stop confusing things. :)

Quoted 8 lines

My apologies for your having been brought into this discussion without
having properly reviewed and summarized the previous thread. As you
saw there is a long history.

Jarrko, Ahmad, "Trusted" keys, by definition, are based on the TPM RNG. If CAAM trusted key support wants to use kernel RNG by default, that's fine. However defining and allowing a boot command line option to use kernel RNG instead of the TPM RNG, needs to be configurable.

The use of kernel RNG for TPM Trusted Keys is already opt-in. The default is trusted.rng=default, which maintains existing behavior. Users who want to use kernel RNG instead need to explicitly specify trusted.rng=kernel.

What more is needed?

Cheers,
Ahmad

Quoted 6 lines

thanks,

Mimi

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#11 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

In reply to Ahmad Fatoum

Documentation/admin-guide/kernel-parameters.txt line 5975

Quoted 10 lines · Ahmad Fatoum
Documentation/admin-guide/kernel-parameters.txt +10 -0
+	trusted.rng=	[KEYS]
+			Format: <string>
+			The RNG used to generate key material for trusted keys.
+			Can be one of:
+			- "kernel"
+			- the same value as trusted.source: "tpm" or "tee"
+			- "default"
+			If not specified, "default" is used. In this case,
+			the RNG's choice is left to each individual trust source.
+

As a general mechanism, I object to this. The kernel's RNG must be trusted in the first place for key material. That's the whole point of it.

However, it sounds like you're not proposing a general mechanism, but
just something particular to this "trusted keys" business. In that case, this should be a module flag, and thus not documented here, but rather
some place namespaced to your trusted keys stuff. "trusted_keys.preferred_rng={whatever}"

Jason

author maintainer
#12 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Hello Jason,

Quoted 16 lines · Jason A. Donenfeld

Documentation/admin-guide/kernel-parameters.txt line 5975

Quoted 10 lines · Ahmad Fatoum
Documentation/admin-guide/kernel-parameters.txt +10 -0
+	trusted.rng=	[KEYS]
+			Format: <string>
+			The RNG used to generate key material for trusted keys.
+			Can be one of:
+			- "kernel"
+			- the same value as trusted.source: "tpm" or "tee"
+			- "default"
+			If not specified, "default" is used. In this case,
+			the RNG's choice is left to each individual trust source.
+

As a general mechanism, I object to this. The kernel's RNG must be trusted in the first place for key material. That's the whole point of it.

Quoted 2 lines

However, it sounds like you're not proposing a general mechanism, but just something particular to this "trusted keys" business.

The two currently upstream trust sources (trusted key backends) each provide their own RNG callback. This series adds a third backend that uses kernel RNG and additionally provides users of the two existing trust sources the option to benefit from kernel RNG as well.

Quoted 2 lines

this should be a module flag, and thus not documented here, but rather
some place namespaced to your trusted keys stuff. "trusted_keys.preferred_rng={whatever}"

The trusted keys module is trusted.ko and directly before my added lines is the trusted.source= documentation, so I think this is already at the correct place.

Thanks,
Ahmad

Quoted 3 lines

Jason

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
#13 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Hi Ahmad,

Quoted 27 lines · Ahmad Fatoum

Hello Jason,

Quoted 16 lines · Jason A. Donenfeld

Documentation/admin-guide/kernel-parameters.txt line 5975

Quoted 10 lines · Ahmad Fatoum
Documentation/admin-guide/kernel-parameters.txt +10 -0
+	trusted.rng=	[KEYS]
+			Format: <string>
+			The RNG used to generate key material for trusted keys.
+			Can be one of:
+			- "kernel"
+			- the same value as trusted.source: "tpm" or "tee"
+			- "default"
+			If not specified, "default" is used. In this case,
+			the RNG's choice is left to each individual trust source.
+

As a general mechanism, I object to this. The kernel's RNG must be trusted in the first place for key material. That's the whole point of it.

Quoted 2 lines

However, it sounds like you're not proposing a general mechanism, but just something particular to this "trusted keys" business.

The two currently upstream trust sources (trusted key backends) each provide their own RNG callback. This series adds a third backend that uses kernel RNG and additionally provides users of the two existing trust sources the option to benefit from kernel RNG as well.

Quoted 5 lines
Quoted 2 lines

this should be a module flag, and thus not documented here, but rather
some place namespaced to your trusted keys stuff. "trusted_keys.preferred_rng={whatever}"

The trusted keys module is trusted.ko and directly before my added lines is the trusted.source= documentation, so I think this is already at the correct place.

My apologies; I should have looked at the file itself instead of just relying on git line context. You're right, the module itself is called trusted.ko. This is confusing (shouldn't it be trusted_keys or something?) , but what you propose sounds consistent from a namespacing perspective with what's already there.

Jason

author maintainer
#14 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Hello Jason,

Quoted 8 lines · Jason A. Donenfeld
Quoted 2 lines · Ahmad Fatoum

The trusted keys module is trusted.ko and directly before my added lines is the trusted.source= documentation, so I think this is already at the correct place.

My apologies; I should have looked at the file itself instead of just relying on git line context. You're right, the module itself is called trusted.ko. This is confusing (shouldn't it be trusted_keys or something?)

Encrypted keys are encrypted-keys.ko, so ye, trusted.ko is a bit unfortunate..

Quoted 2 lines

, but what you propose sounds consistent from a namespacing perspective with what's already there.

Thanks!
Ahmad

Quoted 3 lines

Jason

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#15 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

In reply to Jason A. Donenfeld
Quoted 12 lines · Jason A. Donenfeld
Quoted 10 lines · Ahmad Fatoum

+       trusted.rng=    [KEYS]
+                       Format: <string>
+                       The RNG used to generate key material for trusted keys. +                       Can be one of:
+                       - "kernel"
+                       - the same value as trusted.source: "tpm" or "tee" +                       - "default"
+                       If not specified, "default" is used. In this case, +                       the RNG's choice is left to each individual trust source. +

Quoted 3 lines

As a general mechanism, I object to this. The kernel's RNG must be trusted in the first place for key material. That's the whole point of it.

I would relax this a bit: kernel's RNG must be implicitly must be trusted. If the parameter is used, you make an explicit choice that you are aware of the trust.

If this was opt-out parameter, instead of opt-in, I would get your argument.

Quoted 4 lines

However, it sounds like you're not proposing a general mechanism, but
just something particular to this "trusted keys" business. In that case, this should be a module flag, and thus not documented here, but rather
some place namespaced to your trusted keys stuff. "trusted_keys.preferred_rng={whatever}"

However, I think this a good proposal. Let's make it a module parameter instead.

Quoted 1 line

Jason

BR, Jarkko

#16 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

Hi Jarkko,

Quoted 13 lines · Jarkko Sakkinen
Quoted 12 lines · Jason A. Donenfeld
Quoted 10 lines · Ahmad Fatoum

+       trusted.rng=    [KEYS]
+                       Format: <string>
+                       The RNG used to generate key material for trusted keys. +                       Can be one of:
+                       - "kernel"
+                       - the same value as trusted.source: "tpm" or "tee" +                       - "default"
+                       If not specified, "default" is used. In this case, +                       the RNG's choice is left to each individual trust source. +

Quoted 5 lines
Quoted 3 lines

As a general mechanism, I object to this. The kernel's RNG must be trusted in the first place for key material. That's the whole point of it.

I would relax this a bit: kernel's RNG must be implicitly must be

Sorry, I didn't mean to seem unrelaxed. What I meant was that as a general mechanism, it doesn't make sense, but it isn't a general mechanism, it's a particular one for trusted_keys, which led me to question why it seemed to have such a general name like "trusted.rng". Ahmad pointed out that the trusted prefix actually isn't general. It's what trusted_keys compiles its module as. So just a misunderstanding. It appears to be a module param after all. Sorry for the noise!

Jason

author maintainer
#17 lore raw

Re: [PATCH v10 2/7] KEYS: trusted: allow use of kernel RNG for key material

In reply to Jarkko Sakkinen

Hello Jarkko,

Quoted 24 lines · Jarkko Sakkinen
Quoted 12 lines · Jason A. Donenfeld
Quoted 10 lines · Ahmad Fatoum

+       trusted.rng=    [KEYS]
+                       Format: <string>
+                       The RNG used to generate key material for trusted keys. +                       Can be one of:
+                       - "kernel"
+                       - the same value as trusted.source: "tpm" or "tee" +                       - "default"
+                       If not specified, "default" is used. In this case, +                       the RNG's choice is left to each individual trust source. +

Quoted 3 lines

As a general mechanism, I object to this. The kernel's RNG must be trusted in the first place for key material. That's the whole point of it.

I would relax this a bit: kernel's RNG must be implicitly must be trusted. If the parameter is used, you make an explicit choice that you are aware of the trust.

If this was opt-out parameter, instead of opt-in, I would get your argument.

Quoted 7 lines
Quoted 4 lines

However, it sounds like you're not proposing a general mechanism, but
just something particular to this "trusted keys" business. In that case, this should be a module flag, and thus not documented here, but rather
some place namespaced to your trusted keys stuff. "trusted_keys.preferred_rng={whatever}"

However, I think this a good proposal. Let's make it a module parameter instead.

It's already a module parameter.

Quoted 4 lines
Quoted 2 lines

Jason

BR, Jarkko

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
author maintainer
#18 lore raw

PATCH v10 3/7 crypto: caam - determine whether CAAM supports blob encap/decap

In reply to Ahmad Fatoum

Depending on SoC variant, a CAAM may be available, but with some futures fused out. The LS1028A (non-E) SoC is one such SoC and while it indicates BLOB support, BLOB operations will ultimately fail, because there is no AES support. Add a new blob_present member to reflect whether both BLOB support and the AES support it depends on is available.

These will be used in a follow-up commit to allow blob driver initialization to error out on SoCs without the necessary hardware support instead of failing at runtime with a cryptic

caam_jr 8020000.jr: 20000b0f: CCB: desc idx 11: : Invalid CHA selected.

---
v9 -> v10:
- added Michael's Tested-by
- Check for AES support on CAAM era < 10, as LS1046A/LSA1012A have such CAAMs, which can be partially disabled.
v8 -> v9:
- New patch

To: "Horia Geantă" <[email protected]>
To: Pankaj Gupta <[email protected]>
To: Herbert Xu <[email protected]>
To: "David S. Miller" <[email protected]>
Cc: James Bottomley <[email protected]>
Cc: Jarkko Sakkinen <[email protected]>
Cc: Mimi Zohar <[email protected]>
Cc: David Howells <[email protected]>
Cc: James Morris <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: Jan Luebbe <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Franck LENORMAND <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Sumit Garg <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 drivers/crypto/caam/ctrl.c   | 17 +++++++++++++++--
 drivers/crypto/caam/intern.h |  1 +
 drivers/crypto/caam/regs.h   |  4 +++-
 3 files changed, 19 insertions(+), 3 deletions(-)
drivers/crypto/caam/ctrl.c +15 -2
index ca0361b2dbb0..38c4d88a9d03 100644
@@ -820,12 +820,25 @@ static int caam_probe(struct platform_device *pdev)
 		return -ENOMEM;
 	}
 
-	if (ctrlpriv->era < 10)
+	comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ls);
+	ctrlpriv->blob_present = !!(comp_params & CTPR_LS_BLOB);
+
+	/*
+	 * Some SoCs like the LS1028A (non-E) indicate CTPR_LS_BLOB support,
+	 * but fail when actually using it due to missing AES support, so
+	 * check both here.
+	 */
+	if (ctrlpriv->era < 10) {
 		rng_vid = (rd_reg32(&ctrl->perfmon.cha_id_ls) &
 			   CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT;
-	else
+		ctrlpriv->blob_present = ctrlpriv->blob_present &&
+			(rd_reg32(&ctrl->perfmon.cha_num_ls) & CHA_ID_LS_AES_MASK);
+	} else {
 		rng_vid = (rd_reg32(&ctrl->vreg.rng) & CHA_VER_VID_MASK) >>
 			   CHA_VER_VID_SHIFT;
+		ctrlpriv->blob_present = ctrlpriv->blob_present &&
+			(rd_reg32(&ctrl->vreg.aesa) & CHA_VER_MISC_AES_NUM_MASK);
+	}
 
 	/*
 	 * If SEC has RNG version >= 4 and RNG state handle has not been
drivers/crypto/caam/intern.h +1 -0
index 7d45b21bd55a..e92210e2ab76 100644
@@ -92,6 +92,7 @@ struct caam_drv_private {
 	 */
 	u8 total_jobrs;		/* Total Job Rings in device */
 	u8 qi_present;		/* Nonzero if QI present in device */
+	u8 blob_present;	/* Nonzero if BLOB support present in device */
 	u8 mc_en;		/* Nonzero if MC f/w is active */
 	int secvio_irq;		/* Security violation interrupt number */
 	int virt_en;		/* Virtualization enabled in CAAM */
drivers/crypto/caam/regs.h +3 -1
index 3738625c0250..66d6dad841bb 100644
@@ -320,7 +320,8 @@ struct version_regs {
 #define CHA_VER_VID_MASK	(0xffull << CHA_VER_VID_SHIFT)
 
 /* CHA Miscellaneous Information - AESA_MISC specific */
-#define CHA_VER_MISC_AES_GCM	BIT(1 + CHA_VER_MISC_SHIFT)
+#define CHA_VER_MISC_AES_NUM_MASK	GENMASK(7, 0)
+#define CHA_VER_MISC_AES_GCM		BIT(1 + CHA_VER_MISC_SHIFT)
 
 /* CHA Miscellaneous Information - PKHA_MISC specific */
 #define CHA_VER_MISC_PKHA_NO_CRYPT	BIT(7 + CHA_VER_MISC_SHIFT)
@@ -414,6 +415,7 @@ struct caam_perfmon {
 #define CTPR_MS_PG_SZ_MASK	0x10
 #define CTPR_MS_PG_SZ_SHIFT	4
 	u32 comp_parms_ms;	/* CTPR - Compile Parameters Register	*/
+#define CTPR_LS_BLOB           BIT(1)
 	u32 comp_parms_ls;	/* CTPR - Compile Parameters Register	*/
 	u64 rsvd1[2];
 
Signature · 1 line
2.30.2
maintainer Reviewed-by on v10 3/7
#19 lore raw

RE: [EXT] [PATCH v10 3/7] crypto: caam - determine whether CAAM supports blob encap/decap

Quoted 148 lines

-----Original Message-----
From: Ahmad Fatoum <[email protected]>
Sent: Friday, May 13, 2022 8:27 PM
To: Horia Geanta <[email protected]>; Pankaj Gupta <[email protected]>; Herbert Xu <[email protected]>; David S. Miller <[email protected]>
Cc: [email protected]; Michael Walle <[email protected]>; Ahmad Fatoum <[email protected]>; James Bottomley <[email protected]>; Jarkko Sakkinen <[email protected]>; Mimi Zohar <[email protected]>; David Howells <[email protected]>; James Morris <[email protected]>; Eric Biggers <[email protected]>; Serge E. Hallyn <[email protected]>; Jan Luebbe <[email protected]>; David Gstir <[email protected]>; Richard Weinberger <[email protected]>; Franck Lenormand <[email protected]>; Matthias Schiffer <[email protected]>; Sumit Garg <[email protected]>; John Ernberg <[email protected]>; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [EXT] [PATCH v10 3/7] crypto: caam - determine whether CAAM supports blob encap/decap

Caution: EXT Email

Depending on SoC variant, a CAAM may be available, but with some futures fused out. The LS1028A (non-E) SoC is one such SoC and while it indicates BLOB support, BLOB operations will ultimately fail, because there is no AES support. Add a new blob_present member to reflect whether both BLOB support and the AES support it depends on is available.

These will be used in a follow-up commit to allow blob driver initialization to error out on SoCs without the necessary hardware support instead of failing at runtime with a cryptic

caam_jr 8020000.jr: 20000b0f: CCB: desc idx 11: : Invalid CHA selected.

---
v9 -> v10:
- added Michael's Tested-by
- Check for AES support on CAAM era < 10, as LS1046A/LSA1012A have such CAAMs, which can be partially disabled.
v8 -> v9:
- New patch

To: "Horia Geantă" <[email protected]>
To: Pankaj Gupta <[email protected]>
To: Herbert Xu <[email protected]>
To: "David S. Miller" <[email protected]>
Cc: James Bottomley <[email protected]>
Cc: Jarkko Sakkinen <[email protected]>
Cc: Mimi Zohar <[email protected]>
Cc: David Howells <[email protected]>
Cc: James Morris <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: Jan Luebbe <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Franck LENORMAND <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Sumit Garg <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 drivers/crypto/caam/ctrl.c   | 17 +++++++++++++++--
 drivers/crypto/caam/intern.h |  1 +
 drivers/crypto/caam/regs.h   |  4 +++-
 3 files changed, 19 insertions(+), 3 deletions(-)
drivers/crypto/caam/ctrl.c index renamed from drivers/crypto/caam/ctrl.c +0 -0

ca0361b2dbb0..38c4d88a9d03 100644

drivers/crypto/caam/ctrl.c +15 -2
@@ -820,12 +820,25 @@ static int caam_probe(struct platform_device
 *pdev)
                return -ENOMEM;
        }
 
-       if (ctrlpriv->era < 10)
+       comp_params = rd_reg32(&ctrl->perfmon.comp_parms_ls);
+       ctrlpriv->blob_present = !!(comp_params & CTPR_LS_BLOB);
+
+       /*
+        * Some SoCs like the LS1028A (non-E) indicate CTPR_LS_BLOB support,
+        * but fail when actually using it due to missing AES support, so
+        * check both here.
+        */
+       if (ctrlpriv->era < 10) {
                rng_vid = (rd_reg32(&ctrl->perfmon.cha_id_ls) &
                           CHA_ID_LS_RNG_MASK) >> CHA_ID_LS_RNG_SHIFT;
-       else
+               ctrlpriv->blob_present = ctrlpriv->blob_present &&
+                       (rd_reg32(&ctrl->perfmon.cha_num_ls) &
 CHA_ID_LS_AES_MASK);
+       } else {
                rng_vid = (rd_reg32(&ctrl->vreg.rng) & CHA_VER_VID_MASK) >>
                           CHA_VER_VID_SHIFT;
+               ctrlpriv->blob_present = ctrlpriv->blob_present &&
+                       (rd_reg32(&ctrl->vreg.aesa) &
 CHA_VER_MISC_AES_NUM_MASK);
+       }

/*
* If SEC has RNG version >= 4 and RNG state handle has not been diff --
git a/drivers/crypto/caam/intern.h b/drivers/crypto/caam/intern.h index 7d45b21bd55a..e92210e2ab76 100644

drivers/crypto/caam/intern.h +1 -0
@@ -92,6 +92,7 @@ struct caam_drv_private {
         */
        u8 total_jobrs;         /* Total Job Rings in device */
        u8 qi_present;          /* Nonzero if QI present in device */
+       u8 blob_present;        /* Nonzero if BLOB support present in device */
        u8 mc_en;               /* Nonzero if MC f/w is active */
        int secvio_irq;         /* Security violation interrupt number */
        int virt_en;            /* Virtualization enabled in CAAM */
drivers/crypto/caam/regs.h index renamed from drivers/crypto/caam/regs.h +0 -0

3738625c0250..66d6dad841bb 100644

drivers/crypto/caam/regs.h +3 -2
@@ -320,7 +320,8 @@ struct version_regs {
 #define CHA_VER_VID_MASK       (0xffull << CHA_VER_VID_SHIFT)
 
 /* CHA Miscellaneous Information - AESA_MISC specific */
-#define CHA_VER_MISC_AES_GCM   BIT(1 + CHA_VER_MISC_SHIFT)
+#define CHA_VER_MISC_AES_NUM_MASK      GENMASK(7, 0)
+#define CHA_VER_MISC_AES_GCM           BIT(1 + CHA_VER_MISC_SHIFT)
 
 /* CHA Miscellaneous Information - PKHA_MISC specific */
 #define CHA_VER_MISC_PKHA_NO_CRYPT     BIT(7 + CHA_VER_MISC_SHIFT)
@@ -414,6 +415,7 @@ struct caam_perfmon {
 #define CTPR_MS_PG_SZ_MASK     0x10
 #define CTPR_MS_PG_SZ_SHIFT    4
        u32 comp_parms_ms;      /* CTPR - Compile Parameters Register   */
+#define CTPR_LS_BLOB           BIT(1)
        u32 comp_parms_ls;      /* CTPR - Compile Parameters Register   */
        u64 rsvd1[2];
 
--

2.30.2

author maintainer
#20 lore raw

PATCH v10 4/7 crypto: caam - add in-kernel interface for blob generator

In reply to Ahmad Fatoum

The NXP Cryptographic Acceleration and Assurance Module (CAAM) can be used to protect user-defined data across system reboot:

- When the system is fused and boots into secure state, the master key is a unique never-disclosed device-specific key
- random key is encrypted by key derived from master key
- data is encrypted using the random key
- encrypted data and its encrypted random key are stored alongside
- This blob can now be safely stored in non-volatile memory

On next power-on:
- blob is loaded into CAAM
- CAAM writes decrypted data either into memory or key register

Add functions to realize encrypting and decrypting into memory alongside the CAAM driver.

They will be used in a later commit as a source for the trusted key seal/unseal mechanism.

---
v9 -> v10:
- added Michael's and John's Tested-by
v8 -> v9:
- Improve kernel-doc with ``literal`` formatting and &struct/func() references
- Have caam_blob_gen_init return -ENODEV in absence of job ring or blobbing support with appropriate info messages
v7 -> v8:
- remove unneeded new line in kernel doc (Jarkko)
- Make comments parse as kernel-doc and fix associated warnings
- add Pankaj's Tested-by
v6 -> v7:
- Added more verbose comment on how CAAM_BLOB_DESC_BYTES_MAX adds up.
- remove error message on kzalloc failure (checkpatch)
- Replaced buffer arguments with structure containing them (Pankaj)
v5 -> v6:
- Dropped caam_blob_alloc_desc() in favor of kzalloc() with fixed size. This simplifies code and wastes at most 12 bytes which are freed at the end of the function anyway.
- Factored out common code between caam_encap_blob and caam_decap_blob as both functions were largely identical
- use append_seq_(in|out)_ptr_intlen for both encap/decap as a result
- use reverse christmas tree order for caam_process_blob variable definitions.
v4 -> v5:
- Collected Reviewed-by's and Tested-by's
- Note in CAAM patch what CAAM is (Jarkko)
v3 -> v4:
- Collected Acked-by's, Reviewed-by's and Tested-by
- Fixed typo spotted by David
v2 -> v3:
- No change
v1 -> v2:
- Enforce maximum keymod size (Horia)
- Use append_seq_(in|out)_ptr_intlen instead of append_seq_(in|out)_ptr (Horia)
- Make blobifier handle private to CAAM glue code file (Horia)

To: "Horia Geantă" <[email protected]>
To: Pankaj Gupta <[email protected]>
To: Herbert Xu <[email protected]>
To: "David S. Miller" <[email protected]>
Cc: James Bottomley <[email protected]>
Cc: Jarkko Sakkinen <[email protected]>
Cc: Mimi Zohar <[email protected]>
Cc: David Howells <[email protected]>
Cc: James Morris <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: Jan Luebbe <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Franck LENORMAND <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Sumit Garg <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 drivers/crypto/caam/Kconfig    |   3 +
 drivers/crypto/caam/Makefile   |   1 +
 drivers/crypto/caam/blob_gen.c | 182 +++++++++++++++++++++++++++++++++
 include/soc/fsl/caam-blob.h    | 103 +++++++++++++++++++
 4 files changed, 289 insertions(+)
 create mode 100644 drivers/crypto/caam/blob_gen.c
 create mode 100644 include/soc/fsl/caam-blob.h
drivers/crypto/caam/Kconfig +3 -0
index 84ea7cba5ee5..ea9f8b1ae981 100644
@@ -151,6 +151,9 @@ config CRYPTO_DEV_FSL_CAAM_RNG_API
 	  Selecting this will register the SEC4 hardware rng to
 	  the hw_random API for supplying the kernel entropy pool.
 
+config CRYPTO_DEV_FSL_CAAM_BLOB_GEN
+	bool
+
 endif # CRYPTO_DEV_FSL_CAAM_JR
 
 endif # CRYPTO_DEV_FSL_CAAM
drivers/crypto/caam/Makefile +1 -0
index 3570286eb9ce..25f7ae5a4642 100644
@@ -21,6 +21,7 @@ caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += caamalg_qi.o
 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_AHASH_API) += caamhash.o
 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_RNG_API) += caamrng.o
 caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_PKC_API) += caampkc.o pkc_desc.o
+caam_jr-$(CONFIG_CRYPTO_DEV_FSL_CAAM_BLOB_GEN) += blob_gen.o
 
 caam-$(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI) += qi.o
 ifneq ($(CONFIG_CRYPTO_DEV_FSL_CAAM_CRYPTO_API_QI),)
drivers/crypto/caam/blob_gen.c new file +182 -0

182 lines not on this page · raw message

include/soc/fsl/caam-blob.h new file +103 -0

103 lines not on this page · raw message

Signature · 1 line
2.30.2
author maintainer
#21 lore raw

PATCH v10 5/7 KEYS: trusted: Introduce support for NXP CAAM-based trusted keys

In reply to Ahmad Fatoum

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.

---
v9 -> v10:
- added Michael's and John's Tested-by
v8 -> v9:
- remove diagnostic on caam_blob_gen_init() failure as more relevant messages are now printed by caam_blob_gen_init() itself
v7 -> v8:
- add Jarkko's Reviewed-by
v6 -> v7:
- Split off MAINTAINERS and documentation chanes into separate patches (Jarkko)
- Use new struct caam_blob_info API (Pankaj)
v5 -> v6:
- Rename caam_trusted_key_ops to trusted_key_caam_ops for symmetry with other trust sources (Pankaj)
- Collected Pankaj's Reviewed-by
v4 -> v5:
- Collected Reviewed-by's and Tested-by's
- Changed modifier to SECURE_KEY for compatibility with linux-imx (Matthias)
v3 -> v4:
- Collected Acked-by's, Reviewed-by's and Tested-by
v2 -> v3:
- add MAINTAINERS entry
v1 -> v2:
- Extend trusted keys documentation for CAAM

To: Jonathan Corbet <[email protected]>
To: David Howells <[email protected]>
To: Jarkko Sakkinen <[email protected]>
To: James Bottomley <[email protected]>
To: Mimi Zohar <[email protected]>
Cc: James Morris <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: "Horia Geantă" <[email protected]>
Cc: Pankaj Gupta <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Jan Luebbe <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Franck LENORMAND <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Sumit Garg <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 .../admin-guide/kernel-parameters.txt         |  1 +
 include/keys/trusted_caam.h                   | 11 +++
 security/keys/trusted-keys/Kconfig            | 11 ++-
 security/keys/trusted-keys/Makefile           |  2 +
 security/keys/trusted-keys/trusted_caam.c     | 80 +++++++++++++++++++
 security/keys/trusted-keys/trusted_core.c     |  6 +-
 6 files changed, 109 insertions(+), 2 deletions(-)
 create mode 100644 include/keys/trusted_caam.h
 create mode 100644 security/keys/trusted-keys/trusted_caam.c
Documentation/admin-guide/kernel-parameters.txt +1 -0
index 4deed1908a75..9afb7046ce97 100644
@@ -5958,6 +5958,7 @@
 			sources:
 			- "tpm"
 			- "tee"
+			- "caam"
 			If not specified then it defaults to iterating through
 			the trust source list starting with TPM and assigns the
 			first trust source as a backend which is initialized
include/keys/trusted_caam.h new file +11 -0
new file mode 100644
index 000000000000..73fe2f32f65e
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2021 Pengutronix, Ahmad Fatoum <[email protected]>
+ */
+
+#ifndef __CAAM_TRUSTED_KEY_H
+#define __CAAM_TRUSTED_KEY_H
+
+extern struct trusted_key_ops trusted_key_caam_ops;
+
+#endif
security/keys/trusted-keys/Kconfig +10 -1
index fc4abd581abb..dbfdd8536468 100644
@@ -24,6 +24,15 @@ config TRUSTED_KEYS_TEE
 	  Enable use of the Trusted Execution Environment (TEE) as trusted
 	  key backend.
 
-if !TRUSTED_KEYS_TPM && !TRUSTED_KEYS_TEE
+config TRUSTED_KEYS_CAAM
+	bool "CAAM-based trusted keys"
+	depends on CRYPTO_DEV_FSL_CAAM_JR >= TRUSTED_KEYS
+	select CRYPTO_DEV_FSL_CAAM_BLOB_GEN
+	default y
+	help
+	  Enable use of NXP's Cryptographic Accelerator and Assurance Module
+	  (CAAM) as trusted key backend.
+
+if !TRUSTED_KEYS_TPM && !TRUSTED_KEYS_TEE && !TRUSTED_KEYS_CAAM
 comment "No trust source selected!"
 endif
security/keys/trusted-keys/Makefile +2 -0
index 2e2371eae4d5..735aa0bc08ef 100644
@@ -12,3 +12,5 @@ trusted-$(CONFIG_TRUSTED_KEYS_TPM) += trusted_tpm2.o
 trusted-$(CONFIG_TRUSTED_KEYS_TPM) += tpm2key.asn1.o
 
 trusted-$(CONFIG_TRUSTED_KEYS_TEE) += trusted_tee.o
+
+trusted-$(CONFIG_TRUSTED_KEYS_CAAM) += trusted_caam.o
security/keys/trusted-keys/trusted_caam.c new file +80 -0

80 lines not on this page · raw message

security/keys/trusted-keys/trusted_core.c +5 -1
index 9235fb7d0ec9..c6fc50d67214 100644
@@ -9,6 +9,7 @@
 #include <keys/user-type.h>
 #include <keys/trusted-type.h>
 #include <keys/trusted_tee.h>
+#include <keys/trusted_caam.h>
 #include <keys/trusted_tpm.h>
 #include <linux/capability.h>
 #include <linux/err.h>
@@ -29,7 +30,7 @@ MODULE_PARM_DESC(rng, "Select trusted key RNG");
 
 static char *trusted_key_source;
 module_param_named(source, trusted_key_source, charp, 0);
-MODULE_PARM_DESC(source, "Select trusted keys source (tpm or tee)");
+MODULE_PARM_DESC(source, "Select trusted keys source (tpm, tee or caam)");
 
 static const struct trusted_key_source trusted_key_sources[] = {
 #if defined(CONFIG_TRUSTED_KEYS_TPM)
@@ -38,6 +39,9 @@ static const struct trusted_key_source trusted_key_sources[] = {
 #if defined(CONFIG_TRUSTED_KEYS_TEE)
 	{ "tee", &trusted_key_tee_ops },
 #endif
+#if defined(CONFIG_TRUSTED_KEYS_CAAM)
+	{ "caam", &trusted_key_caam_ops },
+#endif
 };
 
 DEFINE_STATIC_CALL_NULL(trusted_key_init, *trusted_key_sources[0].ops->init);
Signature · 1 line
2.30.2
author maintainer
#22 lore raw

PATCH v10 6/7 doc: trusted-encrypted: describe new CAAM trust source

In reply to Ahmad Fatoum

Update documentation for trusted key use with the Cryptographic Acceleration and Assurance Module (CAAM), an IP on NXP SoCs.

---
v9 -> v10:
- no change
v8 -> v9:
- add Jarkko's Reviewed-by
v7 -> v8:
- add Pankaj's Reviewed-by
v6 -> v7:
- docs update split off as new Patch (Jarkko)
- fixed typo in "Trusted Keys usage: CAAM" section

To: Jonathan Corbet <[email protected]>
To: David Howells <[email protected]>
To: Jarkko Sakkinen <[email protected]>
To: James Bottomley <[email protected]>
To: Mimi Zohar <[email protected]>
Cc: James Morris <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: "Horia Geantă" <[email protected]>
Cc: Pankaj Gupta <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Jan Luebbe <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Franck LENORMAND <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: Sumit Garg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 .../security/keys/trusted-encrypted.rst       | 40 ++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)
Documentation/security/keys/trusted-encrypted.rst +39 -1
index 2fe6fd1a2bbd..0bfb4c339748 100644
@@ -35,6 +35,13 @@ safe.
          Rooted to Hardware Unique Key (HUK) which is generally burnt in on-chip
          fuses and is accessible to TEE only.
 
+     (3) CAAM (Cryptographic Acceleration and Assurance Module: IP on NXP SoCs)
+
+         When High Assurance Boot (HAB) is enabled and the CAAM is in secure
+         mode, trust is rooted to the OTPMK, a never-disclosed 256-bit key
+         randomly generated and fused into each SoC at manufacturing time.
+         Otherwise, a common fixed test key is used instead.
+
   *  Execution isolation
 
      (1) TPM
@@ -46,6 +53,10 @@ safe.
          Customizable set of operations running in isolated execution
          environment verified via Secure/Trusted boot process.
 
+     (3) CAAM
+
+         Fixed set of operations running in isolated execution environment.
+
   * Optional binding to platform integrity state
 
      (1) TPM
@@ -63,6 +74,11 @@ safe.
          Relies on Secure/Trusted boot process for platform integrity. It can
          be extended with TEE based measured boot process.
 
+     (3) CAAM
+
+         Relies on the High Assurance Boot (HAB) mechanism of NXP SoCs
+         for platform integrity.
+
   *  Interfaces and APIs
 
      (1) TPM
@@ -74,10 +90,13 @@ safe.
          TEEs have well-documented, standardized client interface and APIs. For
          more details refer to ``Documentation/staging/tee.rst``.
 
+     (3) CAAM
+
+         Interface is specific to silicon vendor.
 
   *  Threat model
 
-     The strength and appropriateness of a particular TPM or TEE for a given
+     The strength and appropriateness of a particular trust source for a given
      purpose must be assessed when using them to protect security-relevant data.
 
 
@@ -104,6 +123,12 @@ selected trust source:
      from platform specific hardware RNG or a software based Fortuna CSPRNG
      which can be seeded via multiple entropy sources.
 
+  *  CAAM: Kernel RNG
+
+     The normal kernel random number generator is used. To seed it from the
+     CAAM HWRNG, enable CRYPTO_DEV_FSL_CAAM_RNG_API and ensure the device
+     is probed.
+
 Users may override this by specifying ``trusted.rng=kernel`` on the kernel
 command-line to override the used RNG with the kernel's random number pool.
 
@@ -193,6 +218,19 @@ Usage::
 specific to TEE device implementation.  The key length for new keys is always
 in bytes. Trusted Keys can be 32 - 128 bytes (256 - 1024 bits).
 
+Trusted Keys usage: CAAM
+------------------------
+
+Usage::
+
+    keyctl add trusted name "new keylen" ring
+    keyctl add trusted name "load hex_blob" ring
+    keyctl print keyid
+
+"keyctl print" returns an ASCII hex copy of the sealed key, which is in a
+CAAM-specific format.  The key length for new keys is always in bytes.
+Trusted Keys can be 32 - 128 bytes (256 - 1024 bits).
+
 Encrypted Keys usage
 --------------------
 
Signature · 1 line
2.30.2
author maintainer
#23 lore raw

PATCH v10 7/7 MAINTAINERS: add KEYS-TRUSTED-CAAM

In reply to Ahmad Fatoum

Create a maintainer entry for CAAM trusted keys in the Linux keyring.

---
v9 -> v10:
- add Jarkko's Acked-by
v8 -> v9:
- rewrite commit message (Jarkko)
v7 -> v8:
- add Pankaj's Reviewed-by
v6 -> v7:
- split off as separate patch (Jarkko)

To: Jarkko Sakkinen <[email protected]>
To: James Bottomley <[email protected]>
To: Mimi Zohar <[email protected]>
To: David Howells <[email protected]>
Cc: James Morris <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: "Horia Geantă" <[email protected]>
Cc: Pankaj Gupta <[email protected]>
Cc: Herbert Xu <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Jan Luebbe <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Franck LENORMAND <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: Sumit Garg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

---
 MAINTAINERS | 9 +++++++++
 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
index e8c52d0192a6..4a56129bd7d2 100644
@@ -10856,6 +10856,15 @@ S:	Supported
 F:	include/keys/trusted_tee.h
 F:	security/keys/trusted-keys/trusted_tee.c
 
+KEYS-TRUSTED-CAAM
+M:	Ahmad Fatoum <[email protected]>
+R:	Pengutronix Kernel Team <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Maintained
+F:	include/keys/trusted_caam.h
+F:	security/keys/trusted-keys/trusted_caam.c
+
 KEYS/KEYRINGS
 M:	David Howells <[email protected]>
 M:	Jarkko Sakkinen <[email protected]>
Signature · 1 line
2.30.2
maintainer
#24 lore raw
In reply to Ahmad Fatoum
Quoted 130 lines · Ahmad Fatoum

Series applies on top of v5.18-rc6. Would be great if this could make it into v5.19.

v9 was here:
https://lore.kernel.org/linux-integrity/[email protected]

Changelog is beneath each individual patch. Compared to v9, only code change is checking whether CAAM can support blobbing at init-time for CAAM revisions < 10 (such as LS1046A) to avoid a cryptic error message at first use.

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

Its blob mechanism can AES encrypt/decrypt user data using a unique never-disclosed device-specific key.

There has been multiple discussions on how to represent this within the kernel:

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

Its blob mechanism can AES encrypt/decrypt user data using a unique never-disclosed device-specific key. There has been multiple discussions on how to represent this within the kernel:

- [RFC] crypto: caam - add red blobifier
Steffen implemented[1] a PoC sysfs driver to start a discussion on how to best integrate the blob mechanism.
Mimi suggested that it could be used to implement trusted keys. Trusted keys back then were a TPM-only feature.

- security/keys/secure_key: Adds the secure key support based on CAAM. Udit Agarwal added[2] a new "secure" key type with the CAAM as backend. The key material stays within the kernel only.
Mimi and James agreed that this needs a generic interface, not specific to CAAM. Mimi suggested trusted keys. Jan noted that this could serve as basis for TEE-backed keys.

- [RFC] drivers: crypto: caam: key: Add caam_tk key type
Franck added[3] a new "caam_tk" key type based on Udit's work. This time it uses CAAM "black blobs" instead of "red blobs", so key material stays within the CAAM and isn't exposed to kernel in plaintext. James voiced the opinion that there should be just one user-facing generic wrap/unwrap key type with multiple possible handlers.
David suggested trusted keys.

- Introduce TEE based Trusted Keys support
Sumit reworked[4] trusted keys to support multiple possible backends with one chosen at boot time and added a new TEE backend along with TPM. This now sits in Jarkko's master branch to be sent out for v5.13

This patch series builds on top of Sumit's rework to have the CAAM as yet another trusted key backend.

The CAAM bits are based on Steffen's initial patch from 2015. His work had been used in the field for some years now, so I preferred not to deviate too much from it.

This series has been tested with dmcrypt[5] on an i.MX6Q/DL, i.MX8M[6] and LS1028[7].

Looking forward to your feedback.

Cheers,
Ahmad

[1]: https://lore.kernel.org/linux-crypto/[email protected]/
[2]: https://lore.kernel.org/linux-integrity/[email protected]/
[3]: https://lore.kernel.org/lkml/[email protected]/
[4]: https://lore.kernel.org/lkml/[email protected]/
[5]: https://lore.kernel.org/linux-integrity/[email protected]/
[6]: https://lore.kernel.org/linux-integrity/DU2PR04MB8630D83FE9BBC0D782C4FAF595089@DU2PR04MB8630.eurprd04.prod.outlook.com/
[7]: https://lore.kernel.org/linux-integrity/[email protected]/

---
To: Jarkko Sakkinen <[email protected]>
To: "Horia Geantă" <[email protected]>
To: Mimi Zohar <[email protected]>
To: Pankaj Gupta <[email protected]>
To: Herbert Xu <[email protected]>
To: "David S. Miller" <[email protected]>
To: James Bottomley <[email protected]>
Cc: David Howells <[email protected]>
Cc: James Morris <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: Steffen Trumtrar <[email protected]>
Cc: Jan Luebbe <[email protected]>
Cc: David Gstir <[email protected]>
Cc: Eric Biggers <[email protected]>
Cc: Richard Weinberger <[email protected]>
Cc: Franck LENORMAND <[email protected]>
Cc: Sumit Garg <[email protected]>
Cc: Andreas Rammhold <[email protected]>
Cc: Tim Harvey <[email protected]>
Cc: Matthias Schiffer <[email protected]>
Cc: Michael Walle <[email protected]>
Cc: John Ernberg <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Ahmad Fatoum (7):
KEYS: trusted: allow use of TEE as backend without TCG_TPM support
KEYS: trusted: allow use of kernel RNG for key material
crypto: caam - determine whether CAAM supports blob encap/decap
crypto: caam - add in-kernel interface for blob generator
KEYS: trusted: Introduce support for NXP CAAM-based trusted keys
doc: trusted-encrypted: describe new CAAM trust source
MAINTAINERS: add KEYS-TRUSTED-CAAM

 .../admin-guide/kernel-parameters.txt         |  11 ++
 .../security/keys/trusted-encrypted.rst       |  60 +++++-
 MAINTAINERS                                   |   9 +
 drivers/crypto/caam/Kconfig                   |   3 +
 drivers/crypto/caam/Makefile                  |   1 +
 drivers/crypto/caam/blob_gen.c                | 182 ++++++++++++++++++
 drivers/crypto/caam/ctrl.c                    |  17 +-
 drivers/crypto/caam/intern.h                  |   1 +
 drivers/crypto/caam/regs.h                    |   4 +-
 include/keys/trusted-type.h                   |   2 +-
 include/keys/trusted_caam.h                   |  11 ++
 include/soc/fsl/caam-blob.h                   | 103 ++++++++++
 security/keys/Kconfig                         |  18 +-
 security/keys/trusted-keys/Kconfig            |  38 ++++
 security/keys/trusted-keys/Makefile           |  10 +-
Quoted 12 lines
 security/keys/trusted-keys/trusted_caam.c     |  80 ++++++++
 security/keys/trusted-keys/trusted_core.c     |  45 ++++-
 17 files changed, 563 insertions(+), 32 deletions(-)
 create mode 100644 drivers/crypto/caam/blob_gen.c
 create mode 100644 include/keys/trusted_caam.h
 create mode 100644 include/soc/fsl/caam-blob.h
 create mode 100644 security/keys/trusted-keys/Kconfig
 create mode 100644 security/keys/trusted-keys/trusted_caam.c
Signature · 1 line
2.30.2

I can probably pick these unless objections?

BR, Jarkko

author maintainer
#25 lore raw

Hello Herbert,

Quoted 2 lines · Jarkko Sakkinen

On Fri, May 13, 2022 at 04:56:58PM +0200, Ahmad Fatoum wrote:
I can probably pick these unless objections?

Pankaj has given his Reviewed-by for the CAAM parts he co-maintains, is it ok for this to go in via Jarkko's tree?

Note that applying this series on top of jarkko/linux-tpmdd.git has a trivial conflict when merged with herbert/cryptodev-2.6.git:
Two independently added Kconfig options need to coexist in drivers/crypto/caam/Kconfig.

I can resend my series rebased if needed.

Cheers,
Ahmad

Quoted 3 lines

BR, Jarkko

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#26 lore raw
Quoted 14 lines · Ahmad Fatoum

Hello Herbert,

Quoted 2 lines · Jarkko Sakkinen

On Fri, May 13, 2022 at 04:56:58PM +0200, Ahmad Fatoum wrote:
I can probably pick these unless objections?

Pankaj has given his Reviewed-by for the CAAM parts he co-maintains, is it ok for this to go in via Jarkko's tree?

Note that applying this series on top of jarkko/linux-tpmdd.git has a trivial conflict when merged with herbert/cryptodev-2.6.git:
Two independently added Kconfig options need to coexist in drivers/crypto/caam/Kconfig.

Quoted 10 lines

I can resend my series rebased if needed.

Cheers,
Ahmad

Quoted 3 lines

BR, Jarkko

This came up:

https://lore.kernel.org/keyrings/[email protected]/

BR, Jarkko

author maintainer
#27 lore raw
Quoted 21 lines · Jarkko Sakkinen
Quoted 20 lines · Ahmad Fatoum

Hello Herbert,

Quoted 2 lines · Jarkko Sakkinen

On Fri, May 13, 2022 at 04:56:58PM +0200, Ahmad Fatoum wrote:
I can probably pick these unless objections?

Pankaj has given his Reviewed-by for the CAAM parts he co-maintains, is it ok for this to go in via Jarkko's tree?

Note that applying this series on top of jarkko/linux-tpmdd.git has a trivial conflict when merged with herbert/cryptodev-2.6.git:
Two independently added Kconfig options need to coexist in drivers/crypto/caam/Kconfig.

I can resend my series rebased if needed.

Cheers,
Ahmad

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

BR, Jarkko

This came up:

https://lore.kernel.org/keyrings/[email protected]/

And it turned out to be a misunderstanding. Or do you think there is still anything to do there?

Thanks,
Ahmad

Quoted 3 lines

BR, Jarkko

Signature · 4 lines
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
maintainer
#28 lore raw
Quoted 29 lines · Ahmad Fatoum
Quoted 28 lines · Jarkko Sakkinen
Quoted 14 lines · Ahmad Fatoum

Hello Herbert,

Quoted 2 lines · Jarkko Sakkinen

On Fri, May 13, 2022 at 04:56:58PM +0200, Ahmad Fatoum wrote:
I can probably pick these unless objections?

Pankaj has given his Reviewed-by for the CAAM parts he co-maintains, is it ok for this to go in via Jarkko's tree?

Note that applying this series on top of jarkko/linux-tpmdd.git has a trivial conflict when merged with herbert/cryptodev-2.6.git:
Two independently added Kconfig options need to coexist in drivers/crypto/caam/Kconfig.

Quoted 10 lines

I can resend my series rebased if needed.

Cheers,
Ahmad

Quoted 3 lines

BR, Jarkko

This came up:

Quoted 7 lines
Quoted 1 line

https://lore.kernel.org/keyrings/[email protected]/

And it turned out to be a misunderstanding. Or do you think there is still anything to do there?

Thanks,
Ahmad

Oops, you're right, sorry.

Yeah, I guess I can pick these patches now.

BR, Jarkko

maintainer Applied
#29 lore raw
Quoted 35 lines · Jarkko Sakkinen
Quoted 34 lines · Ahmad Fatoum
Quoted 21 lines · Jarkko Sakkinen
Quoted 20 lines · Ahmad Fatoum

Hello Herbert,

Quoted 2 lines · Jarkko Sakkinen

On Fri, May 13, 2022 at 04:56:58PM +0200, Ahmad Fatoum wrote:
I can probably pick these unless objections?

Pankaj has given his Reviewed-by for the CAAM parts he co-maintains, is it ok for this to go in via Jarkko's tree?

Note that applying this series on top of jarkko/linux-tpmdd.git has a trivial conflict when merged with herbert/cryptodev-2.6.git:
Two independently added Kconfig options need to coexist in drivers/crypto/caam/Kconfig.

I can resend my series rebased if needed.

Cheers,
Ahmad

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

BR, Jarkko

This came up:

https://lore.kernel.org/keyrings/[email protected]/

And it turned out to be a misunderstanding. Or do you think there is still anything to do there?

Quoted 6 lines
Quoted 2 lines

Thanks,
Ahmad

Oops, you're right, sorry.

Yeah, I guess I can pick these patches now.

Applied:

https://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git/log/?h=next

BR, Jarkko