All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Simon Glass <sjg@chromium.org>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Masahisa Kojima <masahisa.kojima@linaro.org>,
	Ruchika Gupta <ruchika.gupta@linaro.org>
Subject: [PATCH v2 3/7] tpm: Correct the define-space command in TPMv2
Date: Sat, 13 Aug 2022 13:56:35 -0600	[thread overview]
Message-ID: <20220813195639.1824765-4-sjg@chromium.org> (raw)
In-Reply-To: <20220813195639.1824765-1-sjg@chromium.org>

The message format is incorrect. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Use constants instead of open-coded values

 lib/tpm-v2.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c
index 6058f2e1e4f..3e240bb4c67 100644
--- a/lib/tpm-v2.c
+++ b/lib/tpm-v2.c
@@ -89,14 +89,18 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 space_index,
 	 * Calculate the offset of the nv_policy piece by adding each of the
 	 * chunks below.
 	 */
-	uint offset = 10 + 8 + 13 + 14;
+	const int platform_len = sizeof(u32);
+	const int session_hdr_len = 13;
+	const int message_len = 14;
+	uint offset = TPM2_HDR_LEN + platform_len + session_hdr_len +
+		message_len;
 	u8 command_v2[COMMAND_BUFFER_SIZE] = {
 		/* header 10 bytes */
 		tpm_u16(TPM2_ST_SESSIONS),	/* TAG */
-		tpm_u32(offset + nv_policy_size),/* Length */
+		tpm_u32(offset + nv_policy_size + 2),/* Length */
 		tpm_u32(TPM2_CC_NV_DEFINE_SPACE),/* Command code */
 
-		/* handles 8 bytes */
+		/* handles 4 bytes */
 		tpm_u32(TPM2_RH_PLATFORM),	/* Primary platform seed */
 
 		/* session header 13 bytes */
@@ -107,12 +111,15 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 space_index,
 		tpm_u16(0),			/* auth_size */
 
 		/* message 14 bytes + policy */
-		tpm_u16(12 + nv_policy_size),	/* size */
+		tpm_u16(message_len + nv_policy_size),	/* size */
 		tpm_u32(space_index),
 		tpm_u16(TPM2_ALG_SHA256),
 		tpm_u32(nv_attributes),
 		tpm_u16(nv_policy_size),
-		/* nv_policy */
+		/*
+		 * nv_policy
+		 * space_size
+		 */
 	};
 	int ret;
 
@@ -120,8 +127,9 @@ u32 tpm2_nv_define_space(struct udevice *dev, u32 space_index,
 	 * Fill the command structure starting from the first buffer:
 	 *     - the password (if any)
 	 */
-	ret = pack_byte_string(command_v2, sizeof(command_v2), "s",
-			       offset, nv_policy, nv_policy_size);
+	ret = pack_byte_string(command_v2, sizeof(command_v2), "sw",
+			       offset, nv_policy, nv_policy_size,
+			       offset + nv_policy_size, space_size);
 	if (ret)
 		return TPM_LIB_ERROR;
 
-- 
2.37.1.595.g718a3a8f04-goog


  parent reply	other threads:[~2022-08-13 19:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-13 19:56 [PATCH v2 0/7] tpm: Various minor fixes and enhancements Simon Glass
2022-08-13 19:56 ` [PATCH v2 1/7] tpm: Require a digest source when extending the PCR Simon Glass
2022-08-14  5:42   ` Heinrich Schuchardt
2022-08-13 19:56 ` [PATCH v2 2/7] tpm: Correct the permissions command in TPMv1 Simon Glass
2022-08-16 13:58   ` Ilias Apalodimas
2022-08-17 18:53     ` Simon Glass
2022-08-13 19:56 ` Simon Glass [this message]
2022-08-13 19:56 ` [PATCH v2 4/7] tpm: sandbox: Allow init of TPM in a different phase Simon Glass
2022-08-13 19:56 ` [PATCH v2 5/7] tpm: Allow reporting the internal state Simon Glass
2022-08-13 19:56 ` [PATCH v2 6/7] tpm: Implement state command for Cr50 Simon Glass
2022-08-16 12:43   ` Ilias Apalodimas
2022-08-17 18:53     ` Simon Glass
2022-08-18  7:29       ` Ilias Apalodimas
2022-08-19 13:46         ` Simon Glass
2022-08-22  6:00           ` Ilias Apalodimas
2022-08-22 16:39             ` Simon Glass
2022-08-13 19:56 ` [PATCH v2 7/7] tpm: Allow committing non-volatile data Simon Glass
2022-08-16 13:09   ` Ilias Apalodimas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220813195639.1824765-4-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=masahisa.kojima@linaro.org \
    --cc=ruchika.gupta@linaro.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.