From mboxrd@z Thu Jan 1 00:00:00 1970 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 B295FC433EF for ; Tue, 7 Jun 2022 08:46:38 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1B5F78435F; Tue, 7 Jun 2022 10:46:36 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Psk5yXl+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C44B384366; Tue, 7 Jun 2022 10:46:33 +0200 (CEST) Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (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 29D248435C for ; Tue, 7 Jun 2022 10:46:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x42d.google.com with SMTP id u8so18773278wrm.13 for ; Tue, 07 Jun 2022 01:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=hthlA5NY+XeSt/oB7RHruBkD/2edreqV0gtKoITSq7c=; b=Psk5yXl+azQqSgymk7yhBn7Mz0pkHkIOGgy/Qh3qtG7pGNE3NY+xmM+wxYXwxnWu4o ffLp/em++eciHozdf6QyJ8rm6fjb3xvfsMZ6z8EZZV9Ho/W6OpS+ZYls8+pfKDX7zOUc IRY9BY8DMkokxEb4pEJ08++kviVw6BIJ3LkMsRIsWQWBjJ+Be9U2EKSaLsKHedDFLzbM m6GgMIos4Rc6ZT9znflg0RJFMEi6OQL7Ks0p0sGRZ6CYmQ8YsQrTdfOq5maPtOK1B2ul UOkWSSuYpIbrRith26c/86+edDunJBAt4NUecj/ySmoMj7LpRLE1DuYdaU++wQWDrcS/ a6jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=hthlA5NY+XeSt/oB7RHruBkD/2edreqV0gtKoITSq7c=; b=LmJapW95Ok8AbursU3G4tC3+MiWTGyzkAHc0nv3R+KubKsh8pDBTu3qQqS242cByXz OM/qrzzi2vWuVcnH58gL4ZwEXP4gXuKs4NaCYExHsRVlIiRnehUtPw+g5iecJ5eCUrAY mxMDCDvl879K0hCx4ppQhIcjWhRpvU2Tkoaw0yeODiOCZltONaqF2s1QzezmQAHmvas3 Iz8a1Z6JWicr+fCEP5rwN/UESq4dqFs4com0Uteeh+N8VlXNdDxZD/hUKujtUgvZb1yN MkjloA4vzAo15qzf0H2HPuVTvWxBgPIyBk3XzwG2jQEU6TyyRWl6wsQ7cMabuZ0O/B7V XGdw== X-Gm-Message-State: AOAM530SowJLyt/CNatgckL6Mx6f9/0zHP1bcBbJu1X+se0WQyep961I HQicM4E8PUFY3NBgvf41ZsjZneH1tn4LZg== X-Google-Smtp-Source: ABdhPJyId6xt57ITVKDHfDQIttpTEUsCINRMzReFrrAuGYx/aH5T+XPbeLiv+34C7PeFtUsltt1Irw== X-Received: by 2002:a5d:6e85:0:b0:210:3ded:60ac with SMTP id k5-20020a5d6e85000000b002103ded60acmr25984345wrz.143.1654591590735; Tue, 07 Jun 2022 01:46:30 -0700 (PDT) Received: from hera (ppp089210241233.access.hol.gr. [89.210.241.233]) by smtp.gmail.com with ESMTPSA id z14-20020adfd0ce000000b00215bd1680a8sm10286911wrh.79.2022.06.07.01.46.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 01:46:30 -0700 (PDT) Date: Tue, 7 Jun 2022 11:46:27 +0300 From: Ilias Apalodimas Cc: U-Boot Mailing List Subject: Re: [PATCH 4/8] tpm: Correct the define-space command in TPMv2 Message-ID: References: <20220301001125.1554442-1-sjg@chromium.org> <20220301001125.1554442-5-sjg@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220301001125.1554442-5-sjg@chromium.org> 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.5 at phobos.denx.de X-Virus-Status: Clean Hi Simon, Thanks for fixing this. On Mon, Feb 28, 2022 at 05:11:21PM -0700, Simon Glass wrote: > The message format is incorrect. Fix it. > > Signed-off-by: Simon Glass > --- > > lib/tpm-v2.c | 18 +++++++++++------- > 1 file changed, 11 insertions(+), 7 deletions(-) > > diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c > index 6058f2e1e4..fe99b9c863 100644 > --- a/lib/tpm-v2.c > +++ b/lib/tpm-v2.c > @@ -89,14 +89,14 @@ 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; > + uint offset = 10 + 4 + 13 + 14; > 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 */ Similar to my comment on the previous patches, please send a version with defines that gets rid of the magic numbers (offset, +2 on nv_policy_size etc) > > /* session header 13 bytes */ > @@ -107,12 +107,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(12 + nv_policy_size + 2), /* 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 +123,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.35.1.574.g5d30c73bfb-goog > Cheers /Ilias