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: [email protected]
Fixes: e5fb5d2c5a03 ("security: keys: trusted: Make sealed key properly 
interoperable")
Signed-off-by: Jarkko Sakkinen <[email protected]>
---
 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


Reply via email to