KEYS: trusted: Debugging as a feature
Subsystems (4)
Jarkko Sakkinen
maintainerPATCH v2 1/1 KEYS: trusted: Debugging as a feature
TPM_DEBUG, and other similar flags, are a non-standard way to specify a feature in Linux kernel. Introduce CONFIG_TRUSTED_KEYS_DEBUG for trusted keys, and use it to replace these ad-hoc feature flags.
Given that trusted keys debug dumps can contain sensitive data, harden the feature as follows:
1. In the Kconfig description postulate that pr_debug() statements must be used.
2. Use pr_debug() statements in TPM 1.x driver to print the protocol dump.
Traces, when actually needed, can be easily enabled by providing trusted.dyndbg='+p' in the kernel command-line.
---
v2:
- Implement for all trusted keys backends.
- Add HAVE_TRUSTED_KEYS_DEBUG as it is a good practice despite full coverage.
--- include/keys/trusted-type.h | 18 +++++------- security/keys/trusted-keys/Kconfig | 19 ++++++++++++ security/keys/trusted-keys/trusted_caam.c | 4 +-- security/keys/trusted-keys/trusted_tpm1.c | 36 +++++++++++------------ 4 files changed, 46 insertions(+), 31 deletions(-)
include/keys/trusted-type.h +8 -10
@@ -83,18 +83,16 @@ struct trusted_key_source {extern struct key_type key_type_trusted; -#define TRUSTED_DEBUG 0 - -#if TRUSTED_DEBUG +#ifdef CONFIG_TRUSTED_KEYS_DEBUG static inline void dump_payload (struct trusted_key_payload *p) { -pr_info ("key_len %d\n" , p->key_len); -print_hex_dump (KERN_INFO ,"key " ,DUMP_PREFIX_NONE , -16 ,1 , p->key, p->key_len,0 ); -pr_info ("bloblen %d\n" , p->blob_len); -print_hex_dump (KERN_INFO ,"blob " ,DUMP_PREFIX_NONE , -16 ,1 , p->blob, p->blob_len,0 ); -pr_info ("migratable %d\n" , p->migratable); +pr_debug ("key_len %d\n" , p->key_len); +print_hex_dump_debug ("key " ,DUMP_PREFIX_NONE , +16 ,1 , p->key, p->key_len,0 ); +pr_debug ("bloblen %d\n" , p->blob_len); +print_hex_dump_debug ("blob " ,DUMP_PREFIX_NONE , +16 ,1 , p->blob, p->blob_len,0 ); +pr_debug ("migratable %d\n" , p->migratable); }#else static inline void dump_payload (struct trusted_key_payload *p)
security/keys/trusted-keys/Kconfig +19 -0
@@ -1,10 +1,25 @@ config HAVE_TRUSTED_KEYS bool +config HAVE_TRUSTED_KEYS_DEBUG + bool + +config TRUSTED_KEYS_DEBUG + bool "Debug trusted keys" + depends on HAVE_TRUSTED_KEYS_DEBUG + default n + help + Trusted keys backends and core code that support debug dumps + can opt-in that feature here. Dumps must only use DEBUG + level output, as sensitive data may pass by. In the + kernel-command line traces can be enabled via + trusted.dyndbg='+p'. + config TRUSTED_KEYS_TPM bool "TPM-based trusted keys" depends on TCG_TPM >= TRUSTED_KEYS default y + select HAVE_TRUSTED_KEYS_DEBUG select CRYPTO_HASH_INFO select CRYPTO_LIB_SHA1 select CRYPTO_LIB_UTILS
@@ -23,6 +38,7 @@ config TRUSTED_KEYS_TEE bool "TEE-based trusted keys" depends on TEE >= TRUSTED_KEYS default y + select HAVE_TRUSTED_KEYS_DEBUG select HAVE_TRUSTED_KEYS help Enable use of the Trusted Execution Environment (TEE) as trusted
@@ -33,6 +49,7 @@ config TRUSTED_KEYS_CAAM depends on CRYPTO_DEV_FSL_CAAM_JR >= TRUSTED_KEYS select CRYPTO_DEV_FSL_CAAM_BLOB_GEN default y + select HAVE_TRUSTED_KEYS_DEBUG select HAVE_TRUSTED_KEYS help Enable use of NXP's Cryptographic Accelerator and Assurance Module
@@ -42,6 +59,7 @@ config TRUSTED_KEYS_DCP bool "DCP-based trusted keys" depends on CRYPTO_DEV_MXS_DCP >= TRUSTED_KEYS default y + select HAVE_TRUSTED_KEYS_DEBUG select HAVE_TRUSTED_KEYS help Enable use of NXP's DCP (Data Co-Processor) as trusted key backend.
@@ -50,6 +68,7 @@ config TRUSTED_KEYS_PKWM bool "PKWM-based trusted keys" depends on PSERIES_PLPKS >= TRUSTED_KEYS default y + select HAVE_TRUSTED_KEYS_DEBUG select HAVE_TRUSTED_KEYS help Enable use of IBM PowerVM Key Wrapping Module (PKWM) as a trusted key backend.
security/keys/trusted-keys/trusted_caam.c +2 -2
@@ -28,10 +28,10 @@ static const match_table_t key_tokens = { {opt_err, NULL} }; -#ifdef CAAM_DEBUG +#ifdef CONFIG_TRUSTED_KEYS_DEBUG static inline void dump_options (const struct caam_pkey_info *pkey_info) { -pr_info ("key encryption algo %d\n" , pkey_info->key_enc_algo); +pr_debug ("key encryption algo %d\n" , pkey_info->key_enc_algo); }#else static inline void dump_options (const struct caam_pkey_info *pkey_info)
security/keys/trusted-keys/trusted_tpm1.c +17 -19
@@ -46,38 +46,36 @@ enum { SRK_keytype =4 }; -#define TPM_DEBUG 0 - -#if TPM_DEBUG +#ifdef CONFIG_TRUSTED_KEYS_DEBUG static inline void dump_options (struct trusted_key_options *o) { -pr_info ("sealing key type %d\n" , o->keytype); -pr_info ("sealing key handle %0X\n" , o->keyhandle); -pr_info ("pcrlock %d\n" , o->pcrlock); -pr_info ("pcrinfo %d\n" , o->pcrinfo_len); -print_hex_dump (KERN_INFO ,"pcrinfo " ,DUMP_PREFIX_NONE , -16 ,1 , o->pcrinfo, o->pcrinfo_len,0 ); +pr_debug ("sealing key type %d\n" , o->keytype); +pr_debug ("sealing key handle %0X\n" , o->keyhandle); +pr_debug ("pcrlock %d\n" , o->pcrlock); +pr_debug ("pcrinfo %d\n" , o->pcrinfo_len); +print_hex_dump_debug ("pcrinfo " ,DUMP_PREFIX_NONE , +16 ,1 , o->pcrinfo, o->pcrinfo_len,0 ); }static inline void dump_sess (struct osapsess *s) { -print_hex_dump (KERN_INFO ,"trusted-key: handle " ,DUMP_PREFIX_NONE , -16 ,1 , &s->handle,4 ,0 ); -pr_info ("secret:\n" ); -print_hex_dump (KERN_INFO ,"" ,DUMP_PREFIX_NONE , -16 ,1 , &s->secret,SHA1_DIGEST_SIZE ,0 ); -pr_info ("trusted-key: enonce:\n" ); -print_hex_dump (KERN_INFO ,"" ,DUMP_PREFIX_NONE , -16 ,1 , &s->enonce,SHA1_DIGEST_SIZE ,0 ); +print_hex_dump_debug ("trusted-key: handle " ,DUMP_PREFIX_NONE , +16 ,1 , &s->handle,4 ,0 ); +pr_debug ("secret:\n" ); +print_hex_dump_debug ("" ,DUMP_PREFIX_NONE , +16 ,1 , &s->secret,SHA1_DIGEST_SIZE ,0 ); +pr_debug ("trusted-key: enonce:\n" ); +print_hex_dump_debug ("" ,DUMP_PREFIX_NONE , +16 ,1 , &s->enonce,SHA1_DIGEST_SIZE ,0 ); }static inline void dump_tpm_buf (unsigned char *buf) {int len; -pr_info ("\ntpm buffer\n" ); +pr_debug ("\ntpm buffer\n" ); len =LOAD32 (buf,TPM_SIZE_OFFSET ); -print_hex_dump (KERN_INFO ,"" ,DUMP_PREFIX_NONE ,16 ,1 , buf, len,0 ); +print_hex_dump_debug ("" ,DUMP_PREFIX_NONE ,16 ,1 , buf, len,0 ); }#else static inline void dump_options (struct trusted_key_options *o)
Signature · 1 line
2.47.3
Quoted 72 lines · Jarkko Sakkinen
TPM_DEBUG, and other similar flags, are a non-standard way to specify a feature in Linux kernel. IntroduceCONFIG_TRUSTED_KEYS_DEBUGfor trusted keys, and use it to replace these ad-hoc feature flags.Given that trusted keys debug dumps can contain sensitive data, harden the feature as follows:
1. In the
Kconfigdescription postulate thatpr_debug()statements must be used.
2. Usepr_debug()statements in TPM 1.x driver to print the protocol dump.Traces, when actually needed, can be easily enabled by providing trusted.dyndbg='+p' in the kernel command-line.
Cc Srish Srinivasan <[email protected]>Reported-by Nayna Jain <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>---
v2:
- Implement for all trusted keys backends.
- AddHAVE_TRUSTED_KEYS_DEBUGas it is a good practice despite full coverage.--- include/keys/trusted-type.h | 18 +++++------- security/keys/trusted-keys/Kconfig | 19 ++++++++++++ security/keys/trusted-keys/trusted_caam.c | 4 +-- security/keys/trusted-keys/trusted_tpm1.c | 36 +++++++++++------------ 4 files changed, 46 insertions(+), 31 deletions(-)include/keys/trusted-type.h +8
-10@@ -83,18 +83,16 @@ struct trusted_key_source {extern struct key_type key_type_trusted; -#define TRUSTED_DEBUG 0 - -#if TRUSTED_DEBUG +#ifdef CONFIG_TRUSTED_KEYS_DEBUG static inline void dump_payload (struct trusted_key_payload *p) { -pr_info ("key_len %d\n" , p->key_len); -print_hex_dump (KERN_INFO ,"key " ,DUMP_PREFIX_NONE , -16 ,1 , p->key, p->key_len,0 ); -pr_info ("bloblen %d\n" , p->blob_len); -print_hex_dump (KERN_INFO ,"blob " ,DUMP_PREFIX_NONE , -16 ,1 , p->blob, p->blob_len,0 ); -pr_info ("migratable %d\n" , p->migratable); +pr_debug ("key_len %d\n" , p->key_len); +print_hex_dump_debug ("key " ,DUMP_PREFIX_NONE , +16 ,1 , p->key, p->key_len,0 ); +pr_debug ("bloblen %d\n" , p->blob_len); +print_hex_dump_debug ("blob " ,DUMP_PREFIX_NONE , +16 ,1 , p->blob, p->blob_len,0 ); +pr_debug ("migratable %d\n" , p->migratable); }#else static inline void dump_payload (struct trusted_key_payload *p)security/keys/trusted-keys/Kconfig +3
-0@@ -1,10 +1,25 @@ config HAVE_TRUSTED_KEYS bool +config HAVE_TRUSTED_KEYS_DEBUG + bool +
security/keys/trusted-keys/Kconfig line 16
Quoted 10 lines
security/keys/trusted-keys/Kconfig +10
-0+config TRUSTED_KEYS_DEBUG + bool "Debug trusted keys" + depends on HAVE_TRUSTED_KEYS_DEBUG + default n + help + Trusted keys backends and core code that support debug dumps + can opt-in that feature here. Dumps must only use DEBUG + level output, as sensitive data may pass by. In the + kernel-command line traces can be enabled via + trusted.dyndbg='+p'.
Would it be good idea to add an explicit note/warning:
NOTE: This option is intended for debugging purposes only. Do not enable on production systems as debug output may expose sensitive cryptographic material. If you are unsure, say N.
Apart from this, looks good to me.
Jarkko Sakkinen
maintainerQuoted 85 lines · Nayna Jain
Quoted 69 lines · Jarkko Sakkinen
TPM_DEBUG, and other similar flags, are a non-standard way to specify a feature in Linux kernel. IntroduceCONFIG_TRUSTED_KEYS_DEBUGfor trusted keys, and use it to replace these ad-hoc feature flags.Given that trusted keys debug dumps can contain sensitive data, harden the feature as follows:
1. In the
Kconfigdescription postulate thatpr_debug()statements must be used.
2. Usepr_debug()statements in TPM 1.x driver to print the protocol dump.Traces, when actually needed, can be easily enabled by providing trusted.dyndbg='+p' in the kernel command-line.
Cc Srish Srinivasan <[email protected]>Reported-by Nayna Jain <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>---
v2:
- Implement for all trusted keys backends.
- AddHAVE_TRUSTED_KEYS_DEBUGas it is a good practice despite full coverage.--- include/keys/trusted-type.h | 18 +++++------- security/keys/trusted-keys/Kconfig | 19 ++++++++++++ security/keys/trusted-keys/trusted_caam.c | 4 +-- security/keys/trusted-keys/trusted_tpm1.c | 36 +++++++++++------------ 4 files changed, 46 insertions(+), 31 deletions(-)include/keys/trusted-type.h +8
-10@@ -83,18 +83,16 @@ struct trusted_key_source {extern struct key_type key_type_trusted; -#define TRUSTED_DEBUG 0 - -#if TRUSTED_DEBUG +#ifdef CONFIG_TRUSTED_KEYS_DEBUG static inline void dump_payload (struct trusted_key_payload *p) { -pr_info ("key_len %d\n" , p->key_len); -print_hex_dump (KERN_INFO ,"key " ,DUMP_PREFIX_NONE , -16 ,1 , p->key, p->key_len,0 ); -pr_info ("bloblen %d\n" , p->blob_len); -print_hex_dump (KERN_INFO ,"blob " ,DUMP_PREFIX_NONE , -16 ,1 , p->blob, p->blob_len,0 ); -pr_info ("migratable %d\n" , p->migratable); +pr_debug ("key_len %d\n" , p->key_len); +print_hex_dump_debug ("key " ,DUMP_PREFIX_NONE , +16 ,1 , p->key, p->key_len,0 ); +pr_debug ("bloblen %d\n" , p->blob_len); +print_hex_dump_debug ("blob " ,DUMP_PREFIX_NONE , +16 ,1 , p->blob, p->blob_len,0 ); +pr_debug ("migratable %d\n" , p->migratable); }#else static inline void dump_payload (struct trusted_key_payload *p)security/keys/trusted-keys/Kconfig +3
-0@@ -1,10 +1,25 @@ config HAVE_TRUSTED_KEYS bool +config HAVE_TRUSTED_KEYS_DEBUG + bool +security/keys/trusted-keys/Kconfig line 15
Quoted 10 lines
security/keys/trusted-keys/Kconfig +10
-0+config TRUSTED_KEYS_DEBUG + bool "Debug trusted keys" + depends on HAVE_TRUSTED_KEYS_DEBUG + default n + help + Trusted keys backends and core code that support debug dumps + can opt-in that feature here. Dumps must only use DEBUG + level output, as sensitive data may pass by. In the + kernel-command line traces can be enabled via + trusted.dyndbg='+p'.Would it be good idea to add an explicit note/warning:
Quoted 8 lines
NOTE: This option is intended for debugging purposes only. Do not enable on production systems as debug output may expose sensitive cryptographic material.
If you are unsure, say N.Apart from this, looks good to me.
Reviewed-by Nayna Jain <[email protected]>
Thank, I'll add your tag but would you mind quickly screening v3 again where I add "trusted.debug=0|1". And yes, your suggestion about extra warning makes sense.
Let's make this safe as possible. Mistakes do happen... and then those measures pay off :-)
BR, Jarkko
Jarkko Sakkinen
maintainerQuoted 93 lines · Jarkko Sakkinen
Quoted 92 lines · Nayna Jain
Quoted 69 lines · Jarkko Sakkinen
TPM_DEBUG, and other similar flags, are a non-standard way to specify a feature in Linux kernel. IntroduceCONFIG_TRUSTED_KEYS_DEBUGfor trusted keys, and use it to replace these ad-hoc feature flags.Given that trusted keys debug dumps can contain sensitive data, harden the feature as follows:
1. In the
Kconfigdescription postulate thatpr_debug()statements must be used.
2. Usepr_debug()statements in TPM 1.x driver to print the protocol dump.Traces, when actually needed, can be easily enabled by providing trusted.dyndbg='+p' in the kernel command-line.
Cc Srish Srinivasan <[email protected]>Reported-by Nayna Jain <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>---
v2:
- Implement for all trusted keys backends.
- AddHAVE_TRUSTED_KEYS_DEBUGas it is a good practice despite full coverage.--- include/keys/trusted-type.h | 18 +++++------- security/keys/trusted-keys/Kconfig | 19 ++++++++++++ security/keys/trusted-keys/trusted_caam.c | 4 +-- security/keys/trusted-keys/trusted_tpm1.c | 36 +++++++++++------------ 4 files changed, 46 insertions(+), 31 deletions(-)include/keys/trusted-type.h +8
-10@@ -83,18 +83,16 @@ struct trusted_key_source {extern struct key_type key_type_trusted; -#define TRUSTED_DEBUG 0 - -#if TRUSTED_DEBUG +#ifdef CONFIG_TRUSTED_KEYS_DEBUG static inline void dump_payload (struct trusted_key_payload *p) { -pr_info ("key_len %d\n" , p->key_len); -print_hex_dump (KERN_INFO ,"key " ,DUMP_PREFIX_NONE , -16 ,1 , p->key, p->key_len,0 ); -pr_info ("bloblen %d\n" , p->blob_len); -print_hex_dump (KERN_INFO ,"blob " ,DUMP_PREFIX_NONE , -16 ,1 , p->blob, p->blob_len,0 ); -pr_info ("migratable %d\n" , p->migratable); +pr_debug ("key_len %d\n" , p->key_len); +print_hex_dump_debug ("key " ,DUMP_PREFIX_NONE , +16 ,1 , p->key, p->key_len,0 ); +pr_debug ("bloblen %d\n" , p->blob_len); +print_hex_dump_debug ("blob " ,DUMP_PREFIX_NONE , +16 ,1 , p->blob, p->blob_len,0 ); +pr_debug ("migratable %d\n" , p->migratable); }#else static inline void dump_payload (struct trusted_key_payload *p)security/keys/trusted-keys/Kconfig +3
-0@@ -1,10 +1,25 @@ config HAVE_TRUSTED_KEYS bool +config HAVE_TRUSTED_KEYS_DEBUG + bool +security/keys/trusted-keys/Kconfig line 15
Quoted 10 lines
security/keys/trusted-keys/Kconfig +10
-0+config TRUSTED_KEYS_DEBUG + bool "Debug trusted keys" + depends on HAVE_TRUSTED_KEYS_DEBUG + default n + help + Trusted keys backends and core code that support debug dumps + can opt-in that feature here. Dumps must only use DEBUG + level output, as sensitive data may pass by. In the + kernel-command line traces can be enabled via + trusted.dyndbg='+p'.Would it be good idea to add an explicit note/warning:
NOTE: This option is intended for debugging purposes only. Do not enable on production systems as debug output may expose sensitive cryptographic material.
If you are unsure, say N.Apart from this, looks good to me.
Quoted 8 lines
Quoted 1 line
Reviewed-by Nayna Jain <[email protected]>Thank, I'll add your tag but would you mind quickly screening v3 again where I add "trusted.debug=0|1". And yes, your suggestion about extra warning makes sense.
Let's make this safe as possible. Mistakes do happen... and then those measures pay off :-)
E.g., in 2026 world perfectly realistic scenario is "agentic devops team" (unfortunately), which might debug trusted keys issue, and leave debug flag on. Thus, both warning you suggested and also boot option for good measure do actually leverage risks involved.
BR, Jarkko
Quoted 89 lines · Jarkko Sakkinen
Quoted 88 lines · Nayna Jain
Quoted 69 lines · Jarkko Sakkinen
TPM_DEBUG, and other similar flags, are a non-standard way to specify a feature in Linux kernel. IntroduceCONFIG_TRUSTED_KEYS_DEBUGfor trusted keys, and use it to replace these ad-hoc feature flags.Given that trusted keys debug dumps can contain sensitive data, harden the feature as follows:
1. In the
Kconfigdescription postulate thatpr_debug()statements must be used.
2. Usepr_debug()statements in TPM 1.x driver to print the protocol dump.Traces, when actually needed, can be easily enabled by providing trusted.dyndbg='+p' in the kernel command-line.
Cc Srish Srinivasan <[email protected]>Reported-by Nayna Jain <[email protected]>Signed-off-by Jarkko Sakkinen <[email protected]>---
v2:
- Implement for all trusted keys backends.
- AddHAVE_TRUSTED_KEYS_DEBUGas it is a good practice despite full coverage.--- include/keys/trusted-type.h | 18 +++++------- security/keys/trusted-keys/Kconfig | 19 ++++++++++++ security/keys/trusted-keys/trusted_caam.c | 4 +-- security/keys/trusted-keys/trusted_tpm1.c | 36 +++++++++++------------ 4 files changed, 46 insertions(+), 31 deletions(-)include/keys/trusted-type.h +8
-10@@ -83,18 +83,16 @@ struct trusted_key_source {extern struct key_type key_type_trusted; -#define TRUSTED_DEBUG 0 - -#if TRUSTED_DEBUG +#ifdef CONFIG_TRUSTED_KEYS_DEBUG static inline void dump_payload (struct trusted_key_payload *p) { -pr_info ("key_len %d\n" , p->key_len); -print_hex_dump (KERN_INFO ,"key " ,DUMP_PREFIX_NONE , -16 ,1 , p->key, p->key_len,0 ); -pr_info ("bloblen %d\n" , p->blob_len); -print_hex_dump (KERN_INFO ,"blob " ,DUMP_PREFIX_NONE , -16 ,1 , p->blob, p->blob_len,0 ); -pr_info ("migratable %d\n" , p->migratable); +pr_debug ("key_len %d\n" , p->key_len); +print_hex_dump_debug ("key " ,DUMP_PREFIX_NONE , +16 ,1 , p->key, p->key_len,0 ); +pr_debug ("bloblen %d\n" , p->blob_len); +print_hex_dump_debug ("blob " ,DUMP_PREFIX_NONE , +16 ,1 , p->blob, p->blob_len,0 ); +pr_debug ("migratable %d\n" , p->migratable); }#else static inline void dump_payload (struct trusted_key_payload *p)security/keys/trusted-keys/Kconfig +3
-0@@ -1,10 +1,25 @@ config HAVE_TRUSTED_KEYS bool +config HAVE_TRUSTED_KEYS_DEBUG + bool +security/keys/trusted-keys/Kconfig line 15
Quoted 10 lines
security/keys/trusted-keys/Kconfig +10
-0+config TRUSTED_KEYS_DEBUG + bool "Debug trusted keys" + depends on HAVE_TRUSTED_KEYS_DEBUG + default n + help + Trusted keys backends and core code that support debug dumps + can opt-in that feature here. Dumps must only use DEBUG + level output, as sensitive data may pass by. In the + kernel-command line traces can be enabled via + trusted.dyndbg='+p'.Would it be good idea to add an explicit note/warning:
NOTE: This option is intended for debugging purposes only. Do not enable on production systems as debug output may expose sensitive cryptographic material.
If you are unsure, say N.
Quoted 6 lines
Quoted 3 lines
Apart from this, looks good to me.
Reviewed-by Nayna Jain <[email protected]>Thank, I'll add your tag but would you mind quickly screening v3 again where I add "trusted.debug=0|1". And yes, your suggestion about extra warning makes sense.
Sure Jarkko.. However, I don't see v3 version in my inbox or in linux-integrity. Or you are about to post it soon.
Quoted 3 lines
Let's make this safe as possible. Mistakes do happen... and then those measures pay off :-)
Yes agree.
Quoted 2 lines
BR, Jarkko
Thanks & Regards,
- Nayna