Skip to contentSkip to conversation

Move TPM-specific fields out of trusted_key_options

PATCH Superseded Srish Srinivasan 2 participants 4 messages Sep 10 – Sep 18

Subsystems (4)

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v8 cover Move TPM-specific fields out of trusted_key_options

struct trusted_key_options contains fields that are specific to the TPM trusted source, resulting in the accumulation backend-specific fields in the generic options structure.

Move the TPM-specific fields into a new struct trusted_key_tpm and store a pointer to it in the private member of struct trusted_key_options.

As a preparatory change, return immediately after a TPM unseal failure to prevent pcrlock() from overwriting the unseal error.

Changelog:

v8:
- Rebase onto commit
adc6a9f6d997 ("KEYS: trusted: Fix tpm2_load_cmd() boundary check") to resolve the merge conflicts
- Include Jarkko's Reviewed-by tag

v7:
- Fix a memory leak in the preparatory fix

v6:
- Add a preparatory fix to return immediately after a TPM unseal failure
- Replace explicit cleanup with __free(kfree_sensitive) in the TPM seal and unseal paths, as suggested by Jarkko

v5:
- Rename struct trusted_tpm_options to struct trusted_key_tpm, as suggestedby Jarkko.

v4:
- Rebased onto mainline after tpm-buf memory-safe allocation changes were merged
- Resolved the resulting merge conflicts

v3:
- Exclude the preparatory clean up patch as the problem has been addressed in commit
9ec4175a30eb ("KEYS: trusted: Debugging as a feature")

v2:
- Exclude the bug-fix patch as it has already been applied to 6.19-rc7
- Rename instances of trusted_tpm_options from tpm_opts to private
- Use pr_debug and KERN_DEBUG for logging debug messages (preparatory clean up patch)
- Address other minor comments from Jarkko

Srish Srinivasan (2):
keys/trusted_keys: return immediately after TPM unseal failure keys/trusted_keys: move TPM-specific fields into struct
trusted_key_tpm

 include/keys/trusted-type.h               |  11 --
 include/keys/trusted_tpm.h                |  14 +++
 security/keys/trusted-keys/trusted_tpm1.c | 125 ++++++++++++----------
 security/keys/trusted-keys/trusted_tpm2.c |  50 +++++----
 4 files changed, 113 insertions(+), 87 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v3 1/2 keys/trusted_keys: return immediately after TPM unseal failure

trusted_tpm_unseal() proceeds to pcrlock() when the TPM unseal operation fails. If pcrlock() succeeds, its return value overwrites the unseal error, causing key instantiation to succeed.

Return immediately when unseal fails to preserve the original error.

Fixes 5d0682be3189 ("KEYS: trusted: Add generic trusted keys framework")
---
 security/keys/trusted-keys/trusted_tpm1.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
security/keys/trusted-keys/trusted_tpm1.c +3 -1
index bf0bf7f36970..9cdfeea800a3 100644
@@ -923,8 +923,10 @@ static int trusted_tpm_unseal(struct trusted_key_payload *p, char *datablob)
 		ret = tpm2_unseal_trusted(chip, p, options);
 	else
 		ret = key_unseal(p, options);
-	if (ret < 0)
+	if (ret < 0) {
 		pr_info("key_unseal failed (%d)\n", ret);
+		goto out;
+	}
 
 	if (options->pcrlock) {
 		ret = pcrlock(options->pcrlock);
Signature · 1 line
2.53.0
#2 lore raw

PATCH v8 2/2 keys/trusted_keys: move TPM-specific fields into struct trusted_key_tpm

In reply to Srish Srinivasan

The trusted_key_options struct contains TPM-specific fields (keyhandle, keyauth, blobauth_len, blobauth, pcrinfo_len, pcrinfo, pcrlock, hash, policydigest_len, policydigest, and policyhandle). This leads to the accumulation of backend-specific fields in the generic options structure.

Define struct trusted_key_tpm and move the TPM-specific fields there. Store a pointer to it in the private member of struct trusted_key_options.

---
 include/keys/trusted-type.h               |  11 --
 include/keys/trusted_tpm.h                |  14 +++
 security/keys/trusted-keys/trusted_tpm1.c | 123 ++++++++++++----------
 security/keys/trusted-keys/trusted_tpm2.c |  50 +++++----
 4 files changed, 111 insertions(+), 87 deletions(-)
include/keys/trusted-type.h +0 -11
index 9f9940482da4..3db61b57cf73 100644
@@ -39,17 +39,6 @@ struct trusted_key_payload {
 
 struct trusted_key_options {
 	uint16_t keytype;
-	uint32_t keyhandle;
-	unsigned char keyauth[TPM_DIGEST_SIZE];
-	uint32_t blobauth_len;
-	unsigned char blobauth[TPM_DIGEST_SIZE];
-	uint32_t pcrinfo_len;
-	unsigned char pcrinfo[MAX_PCRINFO_SIZE];
-	int pcrlock;
-	uint32_t hash;
-	uint32_t policydigest_len;
-	unsigned char policydigest[MAX_DIGEST_SIZE];
-	uint32_t policyhandle;
 	void *private;
 };
 
include/keys/trusted_tpm.h +14 -0
index 3a0fa3bc8454..dafbd4a84ddd 100644
@@ -6,6 +6,20 @@
 
 extern struct trusted_key_ops trusted_key_tpm_ops;
 
+struct trusted_key_tpm {
+	uint32_t keyhandle;
+	unsigned char keyauth[TPM_DIGEST_SIZE];
+	uint32_t blobauth_len;
+	unsigned char blobauth[TPM_DIGEST_SIZE];
+	uint32_t pcrinfo_len;
+	unsigned char pcrinfo[MAX_PCRINFO_SIZE];
+	int pcrlock;
+	uint32_t hash;
+	uint32_t policydigest_len;
+	unsigned char policydigest[MAX_DIGEST_SIZE];
+	uint32_t policyhandle;
+};
+
 int tpm2_seal_trusted(struct tpm_chip *chip,
 		      struct trusted_key_payload *payload,
 		      struct trusted_key_options *options);
security/keys/trusted-keys/trusted_tpm1.c +69 -54

299 lines not on this page · raw message

security/keys/trusted-keys/trusted_tpm2.c +28 -22

159 lines not on this page · raw message

Signature · 1 line
2.53.0
maintainer
#3 lore raw
In reply to Srish Srinivasan
Quoted 52 lines · Srish Srinivasan

struct trusted_key_options contains fields that are specific to the TPM trusted source, resulting in the accumulation backend-specific fields in the generic options structure.

Move the TPM-specific fields into a new struct trusted_key_tpm and store a pointer to it in the private member of struct trusted_key_options.

As a preparatory change, return immediately after a TPM unseal failure to prevent pcrlock() from overwriting the unseal error.

Changelog:

v8:
- Rebase onto commit
adc6a9f6d997 ("KEYS: trusted: Fix tpm2_load_cmd() boundary check") to resolve the merge conflicts
- Include Jarkko's Reviewed-by tag

v7:
- Fix a memory leak in the preparatory fix

v6:
- Add a preparatory fix to return immediately after a TPM unseal failure
- Replace explicit cleanup with __free(kfree_sensitive) in the TPM seal and unseal paths, as suggested by Jarkko

v5:
- Rename struct trusted_tpm_options to struct trusted_key_tpm, as suggestedby Jarkko.

v4:
- Rebased onto mainline after tpm-buf memory-safe allocation changes were merged
- Resolved the resulting merge conflicts

v3:
- Exclude the preparatory clean up patch as the problem has been addressed in commit
9ec4175a30eb ("KEYS: trusted: Debugging as a feature")

v2:
- Exclude the bug-fix patch as it has already been applied to 6.19-rc7
- Rename instances of trusted_tpm_options from tpm_opts to private
- Use pr_debug and KERN_DEBUG for logging debug messages (preparatory clean up patch)
- Address other minor comments from Jarkko

Srish Srinivasan (2):
keys/trusted_keys: return immediately after TPM unseal failure keys/trusted_keys: move TPM-specific fields into struct
trusted_key_tpm

Quoted 9 lines
 include/keys/trusted-type.h               |  11 --
 include/keys/trusted_tpm.h                |  14 +++
 security/keys/trusted-keys/trusted_tpm1.c | 125 ++++++++++++----------
 security/keys/trusted-keys/trusted_tpm2.c |  50 +++++----
 4 files changed, 113 insertions(+), 87 deletions(-)
Signature · 1 line
2.53.0

Thank you. Applied.

BR, Jarkko