Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CEF2BC32771 for ; Fri, 19 Aug 2022 13:47:47 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DC44A84B59; Fri, 19 Aug 2022 15:47:27 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ZsncM7LT"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8DC4E84B69; Fri, 19 Aug 2022 15:47:19 +0200 (CEST) Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0445E84B59 for ; Fri, 19 Aug 2022 15:47:16 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x232.google.com with SMTP id u14so4827055oie.2 for ; Fri, 19 Aug 2022 06:47:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=oWQIvfXoJ58o/92wsYmakRaPuiAJZpGvQP7pNXTOzcI=; b=ZsncM7LTybkIK0evXT2kIsMH/u80r7MTT6qxJJ9KanMfJ7iT6h4h/GYzuZxAdEuMNJ 0uycjUgSeT9MDEHYUafTcR4mhx/y0/DHaHX0uXZBYmJ2BAoV79UDUs8FrJbb742itClL ck+3ZRxaLt4Sa0YWA+M6EL53kPGFeEEYcOjVk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=oWQIvfXoJ58o/92wsYmakRaPuiAJZpGvQP7pNXTOzcI=; b=qGkqWwg6wHg6K4la+du5wjnOGLeqkyNZDiHbuYl1KYjVKnhNqyA0bl+MhbfhxVYnzo VPFXvfURVoosSgZmTJSRjdAkNy6+HJtF6IF8JcNsi9vtYKeMEyPaeQw/N58sTAxKmMPo gSZNL9vd4Whu3Rs9Q450SwqNCHFjPsAOr+owMmm+i8kF+iCSdhbZTyeQMYkE7qEGnI3w ti2+ucveWZ2MKsj5g4IOByZrmUUqeBTiaByK1rJeczzwbBPEDPD+XOdY+nHLp7t1DT/s olf/ha9i+NJ4TJHuObuwrLkhLseOWMxxigntJV0WUZ3oumYuyxnI04knwBJ7eLlSMjsU RKdg== X-Gm-Message-State: ACgBeo3Z0te/QjLobSZQzApTikZUxCbEEsEFVNv4sZOUjDGVUKLHTNtr e7uHmPmfQg3AlGLPx8N5uxdAxc0VdaDzYA== X-Google-Smtp-Source: AA6agR4KVf7lnxpsWfiPwu8M0jbax7mY6rgl/EScfzhzM8S8R58p3BCgqajzQA8Uzim5YZPIOT+6bw== X-Received: by 2002:a05:6808:199e:b0:343:6601:7571 with SMTP id bj30-20020a056808199e00b0034366017571mr3287213oib.235.1660916833911; Fri, 19 Aug 2022 06:47:13 -0700 (PDT) Received: from sjg1.roam.corp.google.com (c-67-190-102-125.hsd1.co.comcast.net. [67.190.102.125]) by smtp.gmail.com with ESMTPSA id z36-20020a056870d6a400b0011856117469sm1309429oap.10.2022.08.19.06.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Aug 2022 06:47:13 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Ilias Apalodimas , Masahisa Kojima , Ruchika Gupta Subject: [PATCH v3 3/7] tpm: Correct the define-space command in TPMv2 Date: Fri, 19 Aug 2022 07:46:43 -0600 Message-Id: <20220819134647.269563-4-sjg@chromium.org> X-Mailer: git-send-email 2.37.1.595.g718a3a8f04-goog In-Reply-To: <20220819134647.269563-1-sjg@chromium.org> References: <20220819134647.269563-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The message format is incorrect. Fix it. Signed-off-by: Simon Glass --- (no changes since v2) 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