2023-02-15 13:29:57 +01:00
|
|
|
From dcfb996d872a750fc42cb627627a5ac3f6d89a23 Mon Sep 17 00:00:00 2001
|
2023-02-09 09:57:28 +01:00
|
|
|
From: Gary Lin <glin@suse.com>
|
|
|
|
Date: Thu, 9 Feb 2023 14:56:05 +0800
|
|
|
|
Subject: [PATCH 03/13] tpm2: resend the command on TPM_RC_RETRY
|
|
|
|
|
|
|
|
Sometimes TPM may return TPM_RC_RETRY for some reason, and the only
|
|
|
|
thing we can do is to send the command again. To avoid pending in the
|
|
|
|
while loop indefinitely, just try to send the command 3 times.
|
|
|
|
|
|
|
|
Signed-off-by: Gary Lin <glin@suse.com>
|
|
|
|
---
|
|
|
|
grub-core/tpm2/tpm2.c | 33 ++++++++++++++++++++++++++++-----
|
|
|
|
1 file changed, 28 insertions(+), 5 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/grub-core/tpm2/tpm2.c b/grub-core/tpm2/tpm2.c
|
2023-02-15 13:29:57 +01:00
|
|
|
index 5377ad2c7..083d59d02 100644
|
2023-02-09 09:57:28 +01:00
|
|
|
--- a/grub-core/tpm2/tpm2.c
|
|
|
|
+++ b/grub-core/tpm2/tpm2.c
|
|
|
|
@@ -25,11 +25,11 @@
|
|
|
|
#include <grub/types.h>
|
|
|
|
|
|
|
|
static TPM_RC
|
|
|
|
-grub_tpm2_submit_command (TPMI_ST_COMMAND_TAG tag,
|
|
|
|
- TPM_CC commandCode,
|
|
|
|
- TPM_RC* responseCode,
|
|
|
|
- const struct grub_tpm2_buffer* in,
|
|
|
|
- struct grub_tpm2_buffer* out)
|
|
|
|
+grub_tpm2_submit_command_real (const TPMI_ST_COMMAND_TAG tag,
|
|
|
|
+ const TPM_CC commandCode,
|
|
|
|
+ TPM_RC *responseCode,
|
|
|
|
+ const struct grub_tpm2_buffer *in,
|
|
|
|
+ struct grub_tpm2_buffer *out)
|
|
|
|
{
|
|
|
|
grub_err_t err;
|
|
|
|
struct grub_tpm2_buffer buf;
|
|
|
|
@@ -75,6 +75,29 @@ grub_tpm2_submit_command (TPMI_ST_COMMAND_TAG tag,
|
|
|
|
return TPM_RC_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static TPM_RC
|
|
|
|
+grub_tpm2_submit_command (const TPMI_ST_COMMAND_TAG tag,
|
|
|
|
+ const TPM_CC commandCode,
|
|
|
|
+ TPM_RC *responseCode,
|
|
|
|
+ const struct grub_tpm2_buffer *in,
|
|
|
|
+ struct grub_tpm2_buffer *out)
|
|
|
|
+{
|
|
|
|
+ TPM_RC err;
|
|
|
|
+ int retry_cnt = 0;
|
|
|
|
+
|
|
|
|
+ /* Catch TPM_RC_RETRY and send the command again */
|
|
|
|
+ do {
|
|
|
|
+ err = grub_tpm2_submit_command_real (tag, commandCode, responseCode,
|
|
|
|
+ in, out);
|
2023-02-15 13:29:57 +01:00
|
|
|
+ if (*responseCode != TPM_RC_RETRY)
|
2023-02-09 09:57:28 +01:00
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ retry_cnt++;
|
|
|
|
+ } while (retry_cnt < 3);
|
|
|
|
+
|
|
|
|
+ return err;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
TPM_RC
|
|
|
|
TPM2_CreatePrimary (const TPMI_RH_HIERARCHY primaryHandle,
|
|
|
|
const TPMS_AUTH_COMMAND *authCommand,
|
|
|
|
--
|
|
|
|
2.35.3
|
|
|
|
|