[PATCH v4 03/11] KEYS: trusted: Validate public_len before reading key attributes
From: Jarkko Sakkinen
Date: Thu Nov 26 2026 - 15:51:20 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.
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 8c62342b2588..d2c74ef8844b 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