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 34A5AC32772 for ; Tue, 23 Aug 2022 17:13:33 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7589484849; Tue, 23 Aug 2022 19:13:09 +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="GvcRR02g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E5D278025C; Tue, 23 Aug 2022 19:13:02 +0200 (CEST) Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (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 C32FE80019 for ; Tue, 23 Aug 2022 19:12:59 +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-pj1-x1033.google.com with SMTP id r14-20020a17090a4dce00b001faa76931beso17867752pjl.1 for ; Tue, 23 Aug 2022 10:12:59 -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=nbMSRBjFuIrO26Ocov0AlXJFtFHcftm0yGusF295osU=; b=GvcRR02gPUfl9QxuqhGi8mkGMkUqtVviqjPYMCsWVFMuqUMr7rS6jlzw2InmrkqjN4 /WpXEar0Ot80u9aWfr+Bm/7x1ntA0bRT1PYCVGjDyNjU/P/eJCL7gSUQeRqjpSvxuUVT PReTruqYktQ3vxcC6S3kxnWPKoM4O2id/i/Lo= 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=nbMSRBjFuIrO26Ocov0AlXJFtFHcftm0yGusF295osU=; b=mEevAmbTVBCkvjCfYwWQ+/NKyrbMIFKAxtzVfIWjjmZ2wvATyfrukp85LpcbH+rxF+ 0mk87imXSEP4ZpDWhX8IsVSjyt0NW6K5geNqcQDjDtaQewY7YiA5ChU+BlskvdSy7qkv cLe0ATk/FaghkWsJb/igs0rmTChhNCgl4Oan+MbjLtT/WVhUSV/nYfAwF5WYWAdGXrV+ iidbRINWZQ4KzJ/Hnjb8GVOMfa3Cpd/1EnSx1QiOZXTplp2bvDtwAGfoyx/eOL+KR1HG eIUMdkvxSODRVPf01+B1YOe0nF/j4F73/PMVvGcSCEeBgPihicGPc9AeWLCWQWTjDm8G qPTw== X-Gm-Message-State: ACgBeo2YY4yD99c47EhyvDMxDNix+EWJhqZ/6cgueSqqMgWp8GvxDk6+ QHTeXhiBaiRGxfcVteh33UNKbfgtUt6UIupe X-Google-Smtp-Source: AA6agR7FMIdnp/3oLI0JImUp2E9ovOgvUAx0Xi1NOgDVvwy8IyCYj6zPav5n4SBDyPPmyH87AmY1RQ== X-Received: by 2002:a17:90b:4a0e:b0:1fb:4c5e:9584 with SMTP id kk14-20020a17090b4a0e00b001fb4c5e9584mr4351873pjb.152.1661274777812; Tue, 23 Aug 2022 10:12:57 -0700 (PDT) Received: from sjg1.corp.google.com ([2620:0:1000:2514:4cd7:64:5174:de80]) by smtp.gmail.com with ESMTPSA id x3-20020a170902a38300b0016f154c8910sm10759441pla.204.2022.08.23.10.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Aug 2022 10:12:57 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Ilias Apalodimas , Masahisa Kojima , Ruchika Gupta Subject: [PATCH v4 3/7] tpm: Correct the define-space command in TPMv2 Date: Tue, 23 Aug 2022 10:12:36 -0700 Message-Id: <20220823171240.386269-4-sjg@chromium.org> X-Mailer: git-send-email 2.37.2.609.g9ff673ca1a-goog In-Reply-To: <20220823171240.386269-1-sjg@chromium.org> References: <20220823171240.386269-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.2.609.g9ff673ca1a-goog