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 allow 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 | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/security/keys/trusted-keys/trusted_tpm2.c
b/security/keys/trusted-keys/trusted_tpm2.c
index e20e54203b83..6b4cd07176cb 100644
--- a/security/keys/trusted-keys/trusted_tpm2.c
+++ b/security/keys/trusted-keys/trusted_tpm2.c
@@ -490,8 +490,8 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
struct trusted_key_tpm *private = options->private;
u8 blob_name[TPM2_MAX_NAME_SIZE];
struct tpm_buf *buf __free(kfree) = NULL;
+ unsigned int data_len;
u16 blob_name_size;
- u16 data_len;
u8 *data;
int rc;
@@ -555,9 +555,11 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip,
rc = tpm_buf_check_hmac_response(chip, buf, rc);
if (!rc) {
+ unsigned int 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