Skip to contentSkip to conversation

KEYS: trusted: Don't use 'buf->handles'

PATCH In review Jarkko Sakkinen 1 participant 2 messages Dec 9, 2025

Subsystems (3)
lore
Share & tools
lore

Jarkko Sakkinen

author maintainer
#0 lore raw

PATCH 1/1 KEYS: trusted: Don't use 'buf->handles'

tpm2_unseal_trusted() deduces number of handles in run-time even tho the expected value is known at compile time. Address the issue.

---
 security/keys/trusted-keys/trusted_tpm2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/trusted-keys/trusted_tpm2.c +1 -1
index 9074ae1a5896..e78061ee2d99 100644
@@ -491,7 +491,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
 		if (tpm2_chip_auth(chip)) {
 			tpm_buf_append_hmac_session(chip, buf, TPM2_SA_ENCRYPT, NULL, 0);
 		} else  {
-			offset = buf->handles * 4 + TPM_HEADER_SIZE;
+			offset = TPM_HEADER_SIZE + 2 * sizeof(u32);
 			head = (struct tpm_header *)buf->data;
 			if (tpm_buf_length(buf) == offset)
 				head->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS);
Signature · 1 line
2.39.5
author maintainer
#1 lore raw
Quoted 13 lines · Jarkko Sakkinen

tpm2_unseal_trusted() deduces number of handles in run-time even tho the expected value is known at compile time. Address the issue.

---
 security/keys/trusted-keys/trusted_tpm2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
security/keys/trusted-keys/trusted_tpm2.c +0 -0
index 9074ae1a5896..e78061ee2d99 100644

security/keys/trusted-keys/trusted_tpm2.c static int tpm2_unseal_cmd(struct tpm_chip *chip, · line 494

Quoted 5 lines
security/keys/trusted-keys/trusted_tpm2.c +1 -1
@@ -491,7 +491,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
 		if (tpm2_chip_auth(chip)) {
 			tpm_buf_append_hmac_session(chip, buf, TPM2_SA_ENCRYPT, NULL, 0);
 		} else  {
-			offset = buf->handles * 4 + TPM_HEADER_SIZE;
+			offset = TPM_HEADER_SIZE + 2 * sizeof(u32);

Oops.

Should be 'TPM_HEADER_SIZE + sizeof(u32)'. There's just a single handle.

Quoted 6 lines
security/keys/trusted-keys/trusted_tpm2.c +0 -0
 			head = (struct tpm_header *)buf->data;
 			if (tpm_buf_length(buf) == offset)
 				head->tag = cpu_to_be16(TPM2_ST_NO_SESSIONS);
Signature · 1 line
2.39.5

BR, Jarkko