Skip to contentSkip to conversation

KEYS: trusted: Re-orchestrate tpm2_read_public() calls

PATCH Superseded Jarkko Sakkinen 2 participants 6 messages Dec 4, 2025 – Dec 7, 2025

Subsystems (4)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH 1/1 KEYS: trusted: Re-orchestrate tpm2_read_public() calls

tpm2_load_cmd() and tpm2_unseal_cmd() use the same parent, and calls to tpm_buf_append_name() cause the exact same TPM2_ReadPublic command to be sent to the chip, causing unnecessary traffic.

1. Export tpm2_read_public in order to make it callable from 'trusted_tpm2'.
2. Re-orchestrate tpm2_seal_trusted() and tpm2_unseal_trusted() in order to halve the name resolutions required:
2a. Move tpm2_read_public() calls into trusted_tpm2.
2b. Pass TPM name to tpm_buf_append_name().
2c. Rework tpm_buf_append_name() to use the pre-resolved name.

---
 drivers/char/tpm/tpm2-cmd.c               |   3 +-
 drivers/char/tpm/tpm2-sessions.c          |  95 +++++------------
 include/linux/tpm.h                       |  10 +-
 security/keys/trusted-keys/trusted_tpm2.c | 124 ++++++++++++++--------
 4 files changed, 118 insertions(+), 114 deletions(-)
drivers/char/tpm/tpm2-cmd.c +2 -1
index 3a77be7ebf4a..1f561ad3bdcf 100644
@@ -202,7 +202,8 @@ int tpm2_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
 	}
 
 	if (!disable_pcr_integrity) {
-		rc = tpm_buf_append_name(chip, &buf, pcr_idx, NULL);
+		rc = tpm_buf_append_name(chip, &buf, pcr_idx, (u8 *)&pcr_idx,
+					 sizeof(u32));
 		if (rc) {
 			tpm_buf_destroy(&buf);
 			return rc;
drivers/char/tpm/tpm2-sessions.c +28 -67

153 lines not on this page · raw message

include/linux/tpm.h +9 -1
index 202da079d500..319ba75dd79a 100644
@@ -530,7 +530,7 @@ static inline struct tpm2_auth *tpm2_chip_auth(struct tpm_chip *chip)
 }
 
 int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf,
-			u32 handle, u8 *name);
+			u32 handle, u8 *name, u16 name_size);
 void tpm_buf_append_hmac_session(struct tpm_chip *chip, struct tpm_buf *buf,
 				 u8 attributes, u8 *passphrase,
 				 int passphraselen);
@@ -544,6 +544,7 @@ int tpm_buf_fill_hmac_session(struct tpm_chip *chip, struct tpm_buf *buf);
 int tpm_buf_check_hmac_response(struct tpm_chip *chip, struct tpm_buf *buf,
 				int rc);
 void tpm2_end_auth_session(struct tpm_chip *chip);
+int tpm2_read_public(struct tpm_chip *chip, u32 handle, void *name);
 #else
 #include <linux/unaligned.h>
 
@@ -567,6 +568,13 @@ static inline int tpm_buf_check_hmac_response(struct tpm_chip *chip,
 {
 	return rc;
 }
+
+static inline int tpm2_read_public(struct tpm_chip *chip, u32 handle,
+				   void *name)
+{
+	memcpy(name, &handle, sizeof(u32));
+	return sizeof(u32);
+}
 #endif	/* CONFIG_TCG_TPM2_HMAC */
 
 #endif
security/keys/trusted-keys/trusted_tpm2.c +79 -45

212 lines not on this page · raw message

Signature · 1 line
2.52.0
author maintainer
#1 lore raw
Quoted 4 lines · Jarkko Sakkinen

tpm2_load_cmd() and tpm2_unseal_cmd() use the same parent, and calls to tpm_buf_append_name() cause the exact same TPM2_ReadPublic command to be sent to the chip, causing unnecessary traffic.

Quoted 8 lines

1. Export tpm2_read_public in order to make it callable from 'trusted_tpm2'.
2. Re-orchestrate tpm2_seal_trusted() and tpm2_unseal_trusted() in order to halve the name resolutions required:
2a. Move tpm2_read_public() calls into trusted_tpm2.
2b. Pass TPM name to tpm_buf_append_name().
2c. Rework tpm_buf_append_name() to use the pre-resolved name.

If ASN.1 blob would contain also name of the parent then zero tpm2_read_public() calls would be required i.e., the main bottleneck here inherits from the limitations of the file format itself.

BR, Jarkko

author maintainer
#2 lore raw
Quoted 12 lines · Jarkko Sakkinen
Quoted 11 lines · Jarkko Sakkinen

tpm2_load_cmd() and tpm2_unseal_cmd() use the same parent, and calls to tpm_buf_append_name() cause the exact same TPM2_ReadPublic command to be sent to the chip, causing unnecessary traffic.

1. Export tpm2_read_public in order to make it callable from 'trusted_tpm2'.
2. Re-orchestrate tpm2_seal_trusted() and tpm2_unseal_trusted() in order to halve the name resolutions required:
2a. Move tpm2_read_public() calls into trusted_tpm2.
2b. Pass TPM name to tpm_buf_append_name().
2c. Rework tpm_buf_append_name() to use the pre-resolved name.

Quoted 5 lines
Quoted 1 line

If ASN.1 blob would contain also name of the parent then zero tpm2_read_public() calls would be required i.e., the main bottleneck here inherits from the limitations of the file format itself.

Along the lines of attached patch.

BR, Jarkko

From c5fc7e38aae838dd1190b33545a8b1a1696e9ce8 Mon Sep 17 00:00:00 2001
From: Jarkko Sakkinen <[email protected]>
Date: Fri, 5 Dec 2025 01:53:33 +0200
Subject: [PATCH] KEYS: trusted: Extend TPMKey ASN.1 definition with
'parentName'

Extend TPMKey ASN.1 definition [1] with an optional 'parentName' attribute containing TPMT_HA blob for the parent. Encode this attribute for the generated TPM keys, which allows skipping TPM2_ReadPublic when unsealing the key.

[1] https://www.hansenpartnership.com/draft-bottomley-tpm2-keys.txt

---
 security/keys/trusted-keys/tpm2key.asn1   | 17 ++++-
 security/keys/trusted-keys/trusted_tpm2.c | 80 +++++++++++++++--------
 2 files changed, 69 insertions(+), 28 deletions(-)
security/keys/trusted-keys/tpm2key.asn1 +16 -1
index f57f869ad600..080f0e399982 100644
@@ -1,11 +1,26 @@
 ---
 --- ASN.1 for TPM 2.0 keys
 ---
+TPMPolicy ::= SEQUENCE {
+	commandCode	[0] EXPLICIT INTEGER,
+	commandPolicy	[1] EXPLICIT OCTET STRING
+}
+
+TPMAuthPolicy ::= SEQUENCE {
+	name		[0] EXPLICIT UTF8String OPTIONAL,
+	policy		[1] EXPLICIT SEQUENCE OF TPMPolicy
+}
 
 TPMKey ::= SEQUENCE {
 	type		OBJECT IDENTIFIER ({tpm2_key_type}),
 	emptyAuth	[0] EXPLICIT BOOLEAN OPTIONAL,
+	policy		[1] EXPLICIT SEQUENCE OF TPMPolicy OPTIONAL,
+	secret		[2] EXPLICIT OCTET STRING OPTIONAL,
+	authPolicy	[3] EXPLICIT SEQUENCE OF TPMAuthPolicy OPTIONAL,
+	description	[4] EXPLICIT UTF8String OPTIONAL,
+	rsaParent	[5] EXPLICIT BOOLEAN OPTIONAL,
+	parentName	[6] EXPLICIT OCTET STRING ({tpm2_key_parent_name}),
 	parent		INTEGER ({tpm2_key_parent}),
 	pubkey		OCTET STRING ({tpm2_key_pub}),
 	privkey		OCTET STRING ({tpm2_key_priv})
-	}
+}
security/keys/trusted-keys/trusted_tpm2.c +53 -27

163 lines not on this page · raw message

Signature · 1 line
2.39.5
maintainer
#3 lore raw
Quoted 17 lines · Jarkko Sakkinen
Quoted 16 lines · Jarkko Sakkinen
Quoted 15 lines · Jarkko Sakkinen

tpm2_load_cmd() and tpm2_unseal_cmd() use the same parent, and calls to
tpm_buf_append_name() cause the exact same TPM2_ReadPublic command to be
sent to the chip, causing unnecessary traffic.

1. Export tpm2_read_public in order to make it callable from 'trusted_tpm2'.
2. Re-orchestrate tpm2_seal_trusted() and tpm2_unseal_trusted() in order to
   halve the name resolutions required:
2a. Move tpm2_read_public() calls into trusted_tpm2. 2b. Pass TPM name to tpm_buf_append_name().
2c. Rework tpm_buf_append_name() to use the pre-resolved name.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

If ASN.1 blob would contain also name of the parent then zero tpm2_read_public() calls would be required i.e., the main bottleneck here inherits from the limitations of the file format itself.

Along the lines of attached patch.

Well firstly [6] is already being taken by the creation data proposal, so this would introduce an incompatibility between the kernel and the spec, but secondly, if you want something like this in the spec before it goes to the IETF you really need to propose it now.

The problem with this particular addition is that it would be Linux Kernel specific. All the current TSSs already do a cached read public under the covers when they add the session wrappings so the user facing API they expose has nowhere to insert (or easily extract) a name field and thus TSS based implementations would have no incentive to either output or consume this field. That's not to say the standard can't have additions for crazy or niche use cases (that's what the rsaParent flag is: a one off to support a niche SUSE use case) but it would be hard to persuade user implementations to do this so the kernel would have to interoperate with the case where it didn't exist anyway.

The standard use today is with permanent handles for parents, where the parent is created on the fly, so the name is actually returned from TPM2_CreatePrimary for this use case. It should be a simple matter to bring the kernel implementation up to doing this as well.

Regards,

James

author maintainer
#4 lore raw
Quoted 25 lines · James Bottomley
Quoted 24 lines · Jarkko Sakkinen
Quoted 22 lines · Jarkko Sakkinen
Quoted 15 lines · Jarkko Sakkinen

tpm2_load_cmd() and tpm2_unseal_cmd() use the same parent, and calls to
tpm_buf_append_name() cause the exact same TPM2_ReadPublic command to be
sent to the chip, causing unnecessary traffic.

1. Export tpm2_read_public in order to make it callable from 'trusted_tpm2'.
2. Re-orchestrate tpm2_seal_trusted() and tpm2_unseal_trusted() in order to
   halve the name resolutions required:
2a. Move tpm2_read_public() calls into trusted_tpm2. 2b. Pass TPM name to tpm_buf_append_name().
2c. Rework tpm_buf_append_name() to use the pre-resolved name.

Quoted 1 line

If ASN.1 blob would contain also name of the parent then zero tpm2_read_public() calls would be required i.e., the main bottleneck here inherits from the limitations of the file format itself.

Quoted 6 lines
Quoted 1 line

Along the lines of attached patch.

Well firstly [6] is already being taken by the creation data proposal, so this would introduce an incompatibility between the kernel and the spec, but secondly, if you want something like this in the spec before it goes to the IETF you really need to propose it now.

What is the mailing list for the working group, or is this still unclear as of today?

Quoted 11 lines

The problem with this particular addition is that it would be Linux Kernel specific. All the current TSSs already do a cached read public under the covers when they add the session wrappings so the user facing API they expose has nowhere to insert (or easily extract) a name field and thus TSS based implementations would have no incentive to either output or consume this field. That's not to say the standard can't have additions for crazy or niche use cases (that's what the rsaParent flag is: a one off to support a niche SUSE use case) but it would be hard to persuade user implementations to do this so the kernel would have to interoperate with the case where it didn't exist anyway.

It is just matter of conditionally calling tpm2_read_public(). Not a big deal.

Quoted 5 lines

The standard use today is with permanent handles for parents, where the parent is created on the fly, so the name is actually returned from TPM2_CreatePrimary for this use case. It should be a simple matter to bring the kernel implementation up to doing this as well.

Intercepting TPM2_CreatePrimary does not provide full coverage, as it does not address persistent keys, which kernel interface does support.

Quoted 6 lines

Regards,

James

BR, Jarkko

author maintainer
#5 lore raw
Quoted 52 lines · Jarkko Sakkinen
Quoted 25 lines · James Bottomley
Quoted 24 lines · Jarkko Sakkinen
Quoted 22 lines · Jarkko Sakkinen
Quoted 15 lines · Jarkko Sakkinen

tpm2_load_cmd() and tpm2_unseal_cmd() use the same parent, and calls to
tpm_buf_append_name() cause the exact same TPM2_ReadPublic command to be
sent to the chip, causing unnecessary traffic.

1. Export tpm2_read_public in order to make it callable from 'trusted_tpm2'.
2. Re-orchestrate tpm2_seal_trusted() and tpm2_unseal_trusted() in order to
   halve the name resolutions required:
2a. Move tpm2_read_public() calls into trusted_tpm2. 2b. Pass TPM name to tpm_buf_append_name().
2c. Rework tpm_buf_append_name() to use the pre-resolved name.

Quoted 1 line

If ASN.1 blob would contain also name of the parent then zero tpm2_read_public() calls would be required i.e., the main bottleneck here inherits from the limitations of the file format itself.

Quoted 6 lines
Quoted 1 line

Along the lines of attached patch.

Well firstly [6] is already being taken by the creation data proposal, so this would introduce an incompatibility between the kernel and the spec, but secondly, if you want something like this in the spec before it goes to the IETF you really need to propose it now.

What is the mailing list for the working group, or is this still unclear as of today?

Quoted 11 lines

The problem with this particular addition is that it would be Linux Kernel specific. All the current TSSs already do a cached read public under the covers when they add the session wrappings so the user facing API they expose has nowhere to insert (or easily extract) a name field and thus TSS based implementations would have no incentive to either output or consume this field. That's not to say the standard can't have additions for crazy or niche use cases (that's what the rsaParent flag is: a one off to support a niche SUSE use case) but it would be hard to persuade user implementations to do this so the kernel would have to interoperate with the case where it didn't exist anyway.

It is just matter of conditionally calling tpm2_read_public(). Not a big deal.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines

The standard use today is with permanent handles for parents, where the parent is created on the fly, so the name is actually returned from TPM2_CreatePrimary for this use case. It should be a simple matter to bring the kernel implementation up to doing this as well.

Intercepting TPM2_CreatePrimary does not provide full coverage, as it does not address persistent keys, which kernel interface does support.

It also weaker solution in the sense that it lacks support for secondary keys as parents.

Name digest is universal as it scales primary keys, secondary keys both persistent and transient.

I'm not really sure why we should use TSS implementations as reference for anything in this space. We always want to support "superset' because it actually creates innovation and distruption to the pre-existing science.

BR, Jarkko