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 05924C25B06 for ; Sun, 14 Aug 2022 23:30:11 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 31F338484C; Mon, 15 Aug 2022 01:29:53 +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="KonHeDY7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0ACF98460B; Mon, 15 Aug 2022 01:29:48 +0200 (CEST) Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) (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 16E148460B for ; Mon, 15 Aug 2022 01:29:45 +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@google.com Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-3321c2a8d4cso411367b3.5 for ; Sun, 14 Aug 2022 16:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=Oj/H3ErAAXLV6e6NrbzUqV1JgAO7MwEUxMixojBsdTQ=; b=KonHeDY7plcyDecJs2TKyVbYP8RLz/oWrrrCSJscBSODYhkGUdUpr78Z8azknza8Mh /ny98fPNoNuW8ZR7j4+wO/XIff9aR4K8rnOcs6UIyyCzeEL13R5v2/xRMKU9hiyjQs3f xFRYpM223aAG6cgHkCmHb9rcjIIwJ75Vl+vQY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=Oj/H3ErAAXLV6e6NrbzUqV1JgAO7MwEUxMixojBsdTQ=; b=7Gn302Brv3UNAw7wogJTjMjAevCTmJ8GkRsI2KndCNsb4zypnQ6QKIx79NtEGGcA+b Lyg0xId+oCa8grTD5MOZLsipC6HtrrADqzcRiiLLjjDwGDNzQXLAT4enQ4x7HAxp5ct3 k4vS1ruWbYzLbNVNuw0AmlreEgWNjS6To+WOCne7hE6umo6/sYtB64LiRvoUogEoxbOn wLV6o3VT3YPIvVmpU7RgQuQmG33yzutobPY3cE2BKYjCRGDKZnknGeNp0ZSLVwgvV3QR q5KY9hwsVP769CTly49SqdCD7TXIYpIdGBcxsWQWBhyjAIqKhLDIk71nEz0chHYNFcOn IB5Q== X-Gm-Message-State: ACgBeo0BvGo9jxRnXp2JNCTzeFEK8Y/AuljE1YBq7Gsa88ZDKhtpvtT5 lMu6ESPtvwG1SPPIV0xpKZdFq2YdfM3MQYXcLL0b2mInygztKA== X-Google-Smtp-Source: AA6agR7Kr6SVMcOKnU5pYA96idKy2mzL9+rRRfHccp78U0vyk25eRX8vtjpYsqAyLphl6u1QETuAVqiE3T7tqB7t4iI= X-Received: by 2002:a81:6c43:0:b0:32f:df6d:f7ef with SMTP id h64-20020a816c43000000b0032fdf6df7efmr4444525ywc.422.1660519783587; Sun, 14 Aug 2022 16:29:43 -0700 (PDT) MIME-Version: 1.0 References: <20220301001125.1554442-1-sjg@chromium.org> <20220301001125.1554442-5-sjg@chromium.org> In-Reply-To: From: Simon Glass Date: Sun, 14 Aug 2022 17:29:33 -0600 Message-ID: Subject: Re: [PATCH 4/8] tpm: Correct the define-space command in TPMv2 To: Ilias Apalodimas Cc: U-Boot Mailing List Content-Type: text/plain; charset="UTF-8" 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 Hi Ilias, On Tue, 7 Jun 2022 at 02:46, Ilias Apalodimas wrote: > > 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) OK I have fixed these, with const int. > > > > > /* 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 Regards, Simon