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 X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC360C433EF for ; Tue, 14 Sep 2021 06:51:04 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A437E60FDA for ; Tue, 14 Sep 2021 06:51:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A437E60FDA Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DC36D833F2; Tue, 14 Sep 2021 08:51:00 +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="UWpxooeE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 992C983406; Tue, 14 Sep 2021 08:50:58 +0200 (CEST) Received: from mail-ed1-x536.google.com (mail-ed1-x536.google.com [IPv6:2a00:1450:4864:20::536]) (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 BCBE5833E7 for ; Tue, 14 Sep 2021 08:50:54 +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-ed1-x536.google.com with SMTP id z94so12016678ede.8 for ; Mon, 13 Sep 2021 23:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MWRod9CKdeqDQ2+gm3SeQfwOijyF9vimUJ1RK9bTeoI=; b=UWpxooeEh/442V2M5lAOaU4BQL8hS6LTRHuDLYkSUDjsle9M2bZOvo5SNY33aZ2DCx /bjxWiCOfItTXdLUzvGeQCm6driRH2G2Hx6PY5RHocDsBIbA62nF0OA1odpOiR1i6k8R xRmanqDPY/6uNzxR7Ig71bo7d34wt7PSrkqkalXRGHwsYTMUPJqKTiiMp9AIZS6gLWJw 9GCBtu6qxZ5fSMfHB2hIVpZqJkHBU+s0170qYD0B3fxufVbxZiJTAL6kalewbB3gDEro usFsfVLIW5MfsI2wsyDkMGyWXG8wYM+njh4RZvJ4mdH9Cloojb8p0OE3FKJmTMf/DQ91 2XIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MWRod9CKdeqDQ2+gm3SeQfwOijyF9vimUJ1RK9bTeoI=; b=005quUk+Dh449D1R1juMZ4eLl4EwXyXkMfvyEPV44dfHHoEFMDDIgddWdFvv/H8RsO 6X8S9C1TEQaZXH/J2fH5U2WXxL0UEATxV3Sw4ZvbW/rxWIIXtU5+zi8d5d4vcKrT12FI 5jtbAWBuAgZJTHQkR1HstFj/CnXk8TY5VUcfDpebrxcjY8ZPbQP92oDmfK+8dm2UIk+Z 1tszBcPbiuTkJvGTfbOFTr/A0PiM++IrPocmrar2ADvI1R3ZyoaL2CFq/V+2Ju4Ai8Hf 9f1Y80naoNFNzFRArFMLhorp7uXgjIkDEFuYjjMQl+t0++zFEpmTh3nJuCxJafNsh3M+ j/Mw== X-Gm-Message-State: AOAM530rZehnLh/qZyjWk2mCgWph0bsoQ49XaCd1SVXtZ5GdOGFQ/D+o 6GeTq3eQGE7xIXsgIvz/l50ZsA== X-Google-Smtp-Source: ABdhPJwyJqLOiXw65aCuomAFgZVGAGgiiksYSxyyalOCOKG4d3kSibx91SqWUv4mFtafYtfFNvZFyg== X-Received: by 2002:a05:6402:16d3:: with SMTP id r19mr16198487edx.363.1631602254341; Mon, 13 Sep 2021 23:50:54 -0700 (PDT) Received: from apalos.home (ppp-94-66-220-137.home.otenet.gr. [94.66.220.137]) by smtp.gmail.com with ESMTPSA id p8sm4378671ejo.2.2021.09.13.23.50.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Sep 2021 23:50:54 -0700 (PDT) Date: Tue, 14 Sep 2021 09:50:51 +0300 From: Ilias Apalodimas To: Ruchika Gupta Cc: u-boot@lists.denx.de, Masahisa Kojima , Heinrich Schuchardt Subject: Re: [PATCH] efi_loader: Fix spec ID event creation Message-ID: References: <20210914064431.887691-1-ruchika.gupta@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210914064431.887691-1-ruchika.gupta@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean On Tue, Sep 14, 2021 at 12:14:31PM +0530, Ruchika Gupta wrote: > TCG EFI Protocol Specification defines the number_of_algorithms > field in spec ID event to be equal to the number of active > algorithms supported by the TPM device. In current implementation, > this field is populated with the count of all algorithms supported > by the TPM which leads to incorrect spec ID event creation. > > Similarly, the algorithm array in spec ID event should be a variable > length array with length being equal to the number_of_algorithms field. > In current implementation this is defined as a fixed length array > which has been fixed. > > Signed-off-by: Ruchika Gupta > CC: Masahisa Kojima > CC: Ilias Apalodimas > CC: Heinrich Schuchardt > --- > include/efi_tcg2.h | 7 +------ > lib/efi_loader/efi_tcg2.c | 40 ++++++++++++++++++++++----------------- > 2 files changed, 24 insertions(+), 23 deletions(-) > > diff --git a/include/efi_tcg2.h b/include/efi_tcg2.h > index c99384fb00..6c9f448a26 100644 > --- a/include/efi_tcg2.h > +++ b/include/efi_tcg2.h > @@ -165,8 +165,6 @@ struct tcg_efi_spec_id_event_algorithm_size { > * @digest_sizes: array of number_of_algorithms pairs > * 1st member defines the algorithm id > * 2nd member defines the algorithm size > - * @vendor_info_size: size in bytes for vendor specific info > - * @vendor_info: vendor specific info > */ > struct tcg_efi_spec_id_event { > u8 signature[16]; > @@ -176,10 +174,7 @@ struct tcg_efi_spec_id_event { > u8 spec_errata; > u8 uintn_size; > u32 number_of_algorithms; > - struct tcg_efi_spec_id_event_algorithm_size digest_sizes[TPM2_NUM_PCR_BANKS]; > - u8 vendor_info_size; > - /* U-Boot does not provide any vendor info */ > - u8 vendor_info[]; > + struct tcg_efi_spec_id_event_algorithm_size digest_sizes[]; > } __packed; > > /** > diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c > index b268a02976..3fd6bc30a1 100644 > --- a/lib/efi_loader/efi_tcg2.c > +++ b/lib/efi_loader/efi_tcg2.c > @@ -575,9 +575,10 @@ static efi_status_t tcg2_create_digest(const u8 *input, u32 length, > EFI_PRINT("Unsupported algorithm %x\n", hash_alg); > return EFI_INVALID_PARAMETER; > } > + digest_list->digests[digest_list->count].hash_alg = hash_alg; > + memcpy(&digest_list->digests[digest_list->count].digest, final, > + (u32)alg_to_len(hash_alg)); > digest_list->count++; > - digest_list->digests[i].hash_alg = hash_alg; > - memcpy(&digest_list->digests[i].digest, final, (u32)alg_to_len(hash_alg)); > } > > return EFI_SUCCESS; > @@ -798,8 +799,9 @@ static efi_status_t tcg2_hash_pe_image(void *efi, u64 efi_size, > EFI_PRINT("Unsupported algorithm %x\n", hash_alg); > return EFI_INVALID_PARAMETER; > } > - digest_list->digests[i].hash_alg = hash_alg; > - memcpy(&digest_list->digests[i].digest, hash, (u32)alg_to_len(hash_alg)); > + digest_list->digests[digest_list->count].hash_alg = hash_alg; > + memcpy(&digest_list->digests[digest_list->count].digest, hash, > + (u32)alg_to_len(hash_alg)); > digest_list->count++; > } > > @@ -1123,7 +1125,7 @@ static efi_status_t create_specid_event(struct udevice *dev, void *buffer, > struct tcg_efi_spec_id_event *spec_event; > size_t spec_event_size; > efi_status_t ret = EFI_DEVICE_ERROR; > - u32 active = 0, supported = 0; > + u32 active = 0, supported = 0, pcr_count = 0, alg_count = 0; > int err; > size_t i; > > @@ -1145,25 +1147,29 @@ static efi_status_t create_specid_event(struct udevice *dev, void *buffer, > TCG_EFI_SPEC_ID_EVENT_SPEC_VERSION_ERRATA_TPM2; > spec_event->uintn_size = sizeof(efi_uintn_t) / sizeof(u32); > > - err = tpm2_get_pcr_info(dev, &supported, &active, > - &spec_event->number_of_algorithms); > + err = tpm2_get_pcr_info(dev, &supported, &active, &pcr_count); > + > if (err) > goto out; > - if (spec_event->number_of_algorithms > MAX_HASH_COUNT || > - spec_event->number_of_algorithms < 1) > - goto out; > > - for (i = 0; i < spec_event->number_of_algorithms; i++) { > + for (i = 0; i < pcr_count; i++) { > u16 hash_alg = hash_algo_list[i].hash_alg; > u16 hash_len = hash_algo_list[i].hash_len; > > - if (active && alg_to_mask(hash_alg)) { > + if (active & alg_to_mask(hash_alg)) { > put_unaligned_le16(hash_alg, > - &spec_event->digest_sizes[i].algorithm_id); > + &spec_event->digest_sizes[alg_count].algorithm_id); > put_unaligned_le16(hash_len, > - &spec_event->digest_sizes[i].digest_size); > + &spec_event->digest_sizes[alg_count].digest_size); > + alg_count++; > } > } > + > + spec_event->number_of_algorithms = alg_count; > + if (spec_event->number_of_algorithms > MAX_HASH_COUNT || > + spec_event->number_of_algorithms < 1) > + goto out; > + > /* > * the size of the spec event and placement of vendor_info_size > * depends on supported algoriths > @@ -1172,9 +1178,9 @@ static efi_status_t create_specid_event(struct udevice *dev, void *buffer, > offsetof(struct tcg_efi_spec_id_event, digest_sizes) + > spec_event->number_of_algorithms * sizeof(spec_event->digest_sizes[0]); > /* no vendor info for us */ > - memset(buffer + spec_event_size, 0, > - sizeof(spec_event->vendor_info_size)); > - spec_event_size += sizeof(spec_event->vendor_info_size); > + memset(buffer + spec_event_size, 0, 1); > + /* add a byte for vendor_info_size in the spec event */ > + spec_event_size += 1; > *event_size = spec_event_size; > > return EFI_SUCCESS; > -- > 2.25.1 > Reviewed-by: Ilias Apalodimas