Blame SOURCES/0001-tpm2_import-fix-fixed-AES-key-CVE-2021-3565.patch

4ac4b9
From c069e4f179d5e6653a84fb236816c375dca82515 Mon Sep 17 00:00:00 2001
4ac4b9
From: William Roberts <william.c.roberts@intel.com>
4ac4b9
Date: Fri, 21 May 2021 12:22:31 -0500
4ac4b9
Subject: [PATCH] tpm2_import: fix fixed AES key CVE-2021-3565
4ac4b9
4ac4b9
tpm2_import used a fixed AES key for the inner wrapper, which means that
4ac4b9
a MITM attack would be able to unwrap the imported key. Even the
4ac4b9
use of an encrypted session will not prevent this. The TPM only
4ac4b9
encrypts the first parameter which is the fixed symmetric key.
4ac4b9
4ac4b9
To fix this, ensure the key size is 16 bytes or bigger and use
4ac4b9
OpenSSL to generate a secure random AES key.
4ac4b9
4ac4b9
Fixes: #2738
4ac4b9
4ac4b9
Signed-off-by: William Roberts <william.c.roberts@intel.com>
4ac4b9
---
4ac4b9
 tools/tpm2_import.c | 12 +++++++++++-
4ac4b9
 1 file changed, 11 insertions(+), 1 deletion(-)
4ac4b9
4ac4b9
diff --git a/tools/tpm2_import.c b/tools/tpm2_import.c
4ac4b9
index cfb6f207ba9c..f44326c87e7e 100644
4ac4b9
--- a/tools/tpm2_import.c
4ac4b9
+++ b/tools/tpm2_import.c
4ac4b9
@@ -118,7 +118,17 @@ static tool_rc key_import(ESYS_CONTEXT *ectx, TPM2B_PUBLIC *parent_pub,
4ac4b9
     TPM2B_DATA enc_sensitive_key = {
4ac4b9
         .size = parent_pub->publicArea.parameters.rsaDetail.symmetric.keyBits.sym / 8
4ac4b9
     };
4ac4b9
-    memset(enc_sensitive_key.buffer, 0xFF, enc_sensitive_key.size);
4ac4b9
+
4ac4b9
+    if(enc_sensitive_key.size < 16) {
4ac4b9
+        LOG_ERR("Calculated wrapping keysize is less than 16 bytes, got: %u", enc_sensitive_key.size);
4ac4b9
+        return tool_rc_general_error;
4ac4b9
+    }
4ac4b9
+
4ac4b9
+    int ossl_rc = RAND_bytes(enc_sensitive_key.buffer, enc_sensitive_key.size);
4ac4b9
+    if (ossl_rc != 1) {
4ac4b9
+        LOG_ERR("RAND_bytes failed: %s", ERR_error_string(ERR_get_error(), NULL));
4ac4b9
+        return tool_rc_general_error;
4ac4b9
+    }
4ac4b9
 
4ac4b9
     /*
4ac4b9
      * Calculate the object name.
4ac4b9
-- 
4ac4b9
2.31.0
4ac4b9