[PATCH v5 01/17] KEYS: trusted: Validate public_len before reading key attributes
From: Jarkko Sakkinen
Date: Fri Nov 27 2026 - 00:56:36 EST
tpm2_load_cmd() reads the 32-bit objectAttributes field at pub + 4
without checking that public_len is at least 8 bytes. Reject blobs with
public_len < 8 before dereferencing pub + 4.
Cc: stable@xxxxxxxxxxxxxxx
Fixes: e5fb5d2c5a03 ("security: keys: trusted: Make sealed key properly interoperable")
Signed-off-by: Jarkko Sakkinen <jarkko@xxxxxxxxxx>
---
security/keys/trusted-keys/trusted_tpm2.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c
index 30188a0ec676..621f8ffba17e 100644
--- a/security/keys/trusted-keys/trusted_tpm2.c
+++ b/security/keys/trusted-keys/trusted_tpm2.c
@@ -425,6 +425,9 @@ static int tpm2_load_cmd(struct tpm_chip *chip,
if (private_len + 2 + public_len + 2 > blob_len)
return -E2BIG;
+ if (public_len < 8)
+ return -EINVAL;
+
pub = blob + 2 + private_len + 2;
/* key attributes are always at offset 4 */
attrs = get_unaligned_be32(pub + 4);
--
2.47.3