tpm2_unseal_cmd() rejects unsealed payloads shorter than MIN_KEY_SIZE (32
bytes) with -EFAULT even when loading an ASN.1 TPMKey (OID_TPMSealedData,
2.23.133.10.1.5) blob.

While kernel-generated trusted keys ("new <keylen>") and legacy old_format
blobs are at least 32 bytes long, external TPM2 tools such as sealing any
non-empty payload up to 128 bytes

Keep MIN_KEY_SIZE for legacy old_format blobs and accept 1..MAX_KEY_SIZE
bytes for ASN.1 TPMKey sealed blobs.

Signed-off-by: Jarkko Sakkinen <[email protected]>
---
 security/keys/trusted-keys/trusted_tpm2.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/security/keys/trusted-keys/trusted_tpm2.c 
b/security/keys/trusted-keys/trusted_tpm2.c
index 30188a0ec676..d7336f25b514 100644
--- a/security/keys/trusted-keys/trusted_tpm2.c
+++ b/security/keys/trusted-keys/trusted_tpm2.c
@@ -559,9 +559,11 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
        rc = tpm_buf_check_hmac_response(chip, buf, rc);
 
        if (!rc) {
+               u16 min_len = payload->old_format ? MIN_KEY_SIZE : 1;
+
                data_len = be16_to_cpup(
                        (__be16 *)&buf->data[TPM_HEADER_SIZE + 4]);
-               if (data_len < MIN_KEY_SIZE ||  data_len > MAX_KEY_SIZE)
+               if (data_len < min_len || data_len > MAX_KEY_SIZE)
                        return -EFAULT;
 
                if (tpm_buf_length(buf) < TPM_HEADER_SIZE + 6 + data_len)
-- 
2.47.3


Reply via email to