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 1ED38ECAAD8 for ; Wed, 31 Aug 2022 03:06:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DC3AE849BC; Wed, 31 Aug 2022 05:06:12 +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="LhgBf49W"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1E88D849C0; Wed, 31 Aug 2022 05:06:02 +0200 (CEST) Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) (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 7EFE3849B5 for ; Wed, 31 Aug 2022 05:05:57 +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-oa1-x33.google.com with SMTP id 586e51a60fabf-11e9a7135easo18854774fac.6 for ; Tue, 30 Aug 2022 20:05:57 -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:subject:date; bh=FUkqrz3eOGTE8090OY4BXMRMMPfgYd9dSI+hT/R3nhE=; b=LhgBf49WtCiPXzCHfUUP49nEW9Kk1n077NABaNQ5bFCpYiX/Pn21PK/G6L6pa3tL7Q sZ1zrRP9ajUcHzaxaXTZ1RpRytGYq1qg/szujw9GXnWH7t3AwipXO+ZwIXFbN4kDtMDa aTLU+uhsNHrpza3C/gtshgn4pwHmRwpT4EksY= 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 :subject:date; bh=FUkqrz3eOGTE8090OY4BXMRMMPfgYd9dSI+hT/R3nhE=; b=0xqZPT5UuyQ/XivhmOom1PnxRk2q83YssOx+3xUvwaXMtVm9IcsbsHJptHCHEt2ikA c9LYenuMnn0zHCCK3K5Wm2+gBHJnCmqiaxpkrDg6Ggnd5JCX4wpfhuGEMqxYbGcii+uk H7/sHmbs2nzujz6ze7zjbQbMh/tDIFAgibFCUfQZ27MiK2KscOOzV1V1MM76TEVUiz4P c8wX57r6ktZ+m930Tj8mxnkKu2nsyL2Wj6AJlqrxWVVDx+uLeUSx8ITofpDg/Hg8nFDl HXH4St66Ow7OGrCbbZNU6XoA+KMnmAPdqp9a0q8yppAZGu4cUWey65f7HkHrvAg0hI7D ZxFQ== X-Gm-Message-State: ACgBeo3mEAuPrXe5/x9sK1P82uU0XEhKkK7z0IKL0zR9967lYAfG2NRN ravviSsMwuylduc8+W7njM/t1Eh0Mf1/zA== X-Google-Smtp-Source: AA6agR62FCIbzlDEgnVpGhULZKkOn1fYVQ236nCQqln4YOHgDUT6FxnGjbYNvNoK9dAOCDLKVBLEAQ== X-Received: by 2002:a05:6870:f6a3:b0:11d:1ca9:ed55 with SMTP id el35-20020a056870f6a300b0011d1ca9ed55mr510641oab.121.1661915155895; Tue, 30 Aug 2022 20:05:55 -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 cp6-20020a056830660600b0063b34c35575sm2888129otb.42.2022.08.30.20.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Aug 2022 20:05:55 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Ilias Apalodimas Subject: [PATCH v5 3/7] tpm: Correct the define-space command in TPMv2 Date: Tue, 30 Aug 2022 21:05:34 -0600 Message-Id: <20220831030538.26742-4-sjg@chromium.org> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog In-Reply-To: <20220831030538.26742-1-sjg@chromium.org> References: <20220831030538.26742-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 Acked-by: Ilias Apalodimas --- (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.2.672.g94769d06f0-goog