Skip to contentSkip to conversation

KEYS: trusted: Protocol debugging as a feature

PATCH Superseded Jarkko Sakkinen 1 participant 2 messages Mar 23 – Mar 24

Subsystems (3)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH 1/1 KEYS: trusted: Protocol debugging as a feature

TPM_DEBUG is a non-standard way to specify a feature in Linux kernel. Introduce CONFIG_TRUSTED_KEYS_DEBUG, and use it to replace TPM_DEBUG in TPM 1.x trusted keys.

Given that protocol bus could 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 can be enabled e.g., by providing trusted.dyndbg='+p' for the kernel command-line.

---
 security/keys/trusted-keys/Kconfig        | 10 +++++++
 security/keys/trusted-keys/trusted_tpm1.c | 36 +++++++++++------------
 2 files changed, 27 insertions(+), 19 deletions(-)
security/keys/trusted-keys/Kconfig +10 -0
index 9e00482d886a..0e53bef1343d 100644
@@ -1,6 +1,16 @@
 config HAVE_TRUSTED_KEYS
 	bool
 
+config TRUSTED_KEYS_DEBUG
+	bool "Debug trusted keys protocol"
+	depends on HAVE_TRUSTED_KEYS
+	default n
+	help
+	  Drivers that support debugging the protocol dump, can opt-in that
+	  feature here. Protocol dump 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
security/keys/trusted-keys/trusted_tpm1.c +17 -19
index c865c97aa1b4..8fe889c7cdd1 100644
@@ -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
author maintainer
#1 lore raw
Quoted 11 lines · Jarkko Sakkinen

TPM_DEBUG is a non-standard way to specify a feature in Linux kernel. Introduce CONFIG_TRUSTED_KEYS_DEBUG, and use it to replace TPM_DEBUG in TPM 1.x trusted keys.

Given that protocol bus could 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.

Quoted 8 lines

Traces can be enabled e.g., by providing trusted.dyndbg='+p' for the kernel command-line.

---

I'm posting a v2 update with HAVE_* flag and a bit wider scope.

BR, Jarkko