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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA418C433EF for ; Fri, 1 Oct 2021 09:09:06 +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 A84AB60FC1 for ; Fri, 1 Oct 2021 09:09:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org A84AB60FC1 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 7B5EF815A8; Fri, 1 Oct 2021 11:09:01 +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="f+bY+cQV"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 93F96811CF; Fri, 1 Oct 2021 11:08:59 +0200 (CEST) Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (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 336BB8187B for ; Fri, 1 Oct 2021 11:08:55 +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-x52c.google.com with SMTP id l7so8565800edq.3 for ; Fri, 01 Oct 2021 02:08:55 -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:content-transfer-encoding:in-reply-to; bh=hgCWuMV0rwfKCqATCZ2iC5cAEIhAwZtLyEQTDI8bQM0=; b=f+bY+cQVCyJUqn1dTxxCYbjWE/4MG5/tvdSpBU30E8fHCdNWO6mOQVMGseLUnrdv3x YQSKxjOTqE937uUFHZdWgNi7N+PFnX8As551/QExErT5jhRdL0AZ7hDDvRcxaQ/yTiDN W6ccEBK6/274xJJesgpc3UW+cPZ+3b503UH2IAdbGU7M+NAyiYvRWM82gk00xgJb6gr8 r5AouNY3Brr2s8ugAbYIHVI7vT4cs4VxIRCgIpsDZ8ZD8ZBMts8d7laKoaI55pT29P1g NwTZoYH/ciGIr0gDomYOdqrVHCwXt1V58aDAdrOEtTCnOrs2w39lUJUQrsBXL/u7wKy4 P7tg== 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:content-transfer-encoding :in-reply-to; bh=hgCWuMV0rwfKCqATCZ2iC5cAEIhAwZtLyEQTDI8bQM0=; b=GBmMRfhU5BxxO3vLBh76KVdc8u5BDRFNqK1A0+3twa+qrgAkeWTEn+vD4wpOu/ZqW0 4TwHhfNTJVs9X1f0A/5HNia8D74ZN9TPP+CMTQIAhV17MlozfTQnBgPZLJ4Vh2zB23C3 mwBn+Hei9ErEpZvUBXLpsY9Uh1ELP+6gJ3k87QUmrhRSmPR+IZKXic/gDNddKa2n7z1i OAZnLKoA4HcxwQRixVPo+KrZ4ENMlFjc4CRsSQbXGHemvPle4R2S1JZb6pZOX9KOQ0xw bIaQP39OhBH0LcIIL1FM7fyCHbjUHjlzC1qBNsNfMyIlQn5APstXF8Y7neEexQzuLEzO EjNQ== X-Gm-Message-State: AOAM531HLzffpPK+pjoSXKYoskTLysrXqosidAduBkG1zHRcXchfKE/2 P/epOFXL5X6qicXsybUGfSUWIQ== X-Google-Smtp-Source: ABdhPJwZ48n1if7cJm9NSO2A9Jn9f+yOmYhpBrMCBuLbv3SWZ/6jbsu7Shm7E5rJ2/VfDf/86O4CRA== X-Received: by 2002:a17:906:608e:: with SMTP id t14mr4843139ejj.441.1633079334261; Fri, 01 Oct 2021 02:08:54 -0700 (PDT) Received: from apalos.home (ppp-94-66-220-209.home.otenet.gr. [94.66.220.209]) by smtp.gmail.com with ESMTPSA id ne24sm2647702ejc.46.2021.10.01.02.08.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 02:08:53 -0700 (PDT) Date: Fri, 1 Oct 2021 12:08:51 +0300 From: Ilias Apalodimas To: Masahisa Kojima Cc: U-Boot Mailing List , Heinrich Schuchardt , Alexander Graf , Simon Glass Subject: Re: [PATCH v2 2/3] efi_loader: add UEFI GPT measurement Message-ID: References: <20210921071931.3755-1-masahisa.kojima@linaro.org> <20210921071931.3755-3-masahisa.kojima@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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 Fri, Oct 01, 2021 at 04:37:40PM +0900, Masahisa Kojima wrote: > On Tue, 28 Sept 2021 at 05:21, Ilias Apalodimas > wrote: > > > > On Tue, Sep 21, 2021 at 04:19:30PM +0900, Masahisa Kojima wrote: > > > This commit adds the UEFI GPT disk partition topology > > > measurement required in TCG PC Client PFP Spec. > > > > > > Signed-off-by: Masahisa Kojima > > > --- > > > > > > (no changes since v1) > > > > > > include/blk.h | 3 + > > > include/efi_loader.h | 2 +- > > > include/efi_tcg2.h | 12 +++ > > > lib/efi_loader/efi_boottime.c | 2 +- > > > lib/efi_loader/efi_tcg2.c | 175 +++++++++++++++++++++++++++++++++- > > > 5 files changed, 191 insertions(+), 3 deletions(-) > > > > > > diff --git a/include/blk.h b/include/blk.h > > > index 19bab081c2..f0cc7ca1a2 100644 > > > --- a/include/blk.h > > > +++ b/include/blk.h > > > @@ -45,6 +45,9 @@ enum if_type { > > > #define BLK_PRD_SIZE 20 > > > #define BLK_REV_SIZE 8 > > > > > > +#define PART_FORMAT_PCAT 0x1 > > > > This isn't used anywhere > > UEFI spec says: > --- > Partition Format: > 0x01 – PC-AT compatible legacy MBR > 0x02 – GUID Partition Table > --- > I think it is better to define both value even if one of them is not used. > Fair enough > > > > > @@ -230,6 +230,18 @@ struct smbios_handoff_table_pointers2 { > > > struct efi_configuration_table table_entry[]; > > > } __packed; > > > > > > +/** > > > + * struct tdUEFI_GPT_DATA - event log structure of industry standard tables > > > + * @uefi_partition_header: gpt partition header > > > + * @number_of_partitions: the number of partition > > > + * @partitions: partition entries > > > + */ > > > +struct efi_gpt_data { > > > + gpt_header uefi_partition_header; > > > + u64 number_of_partitions; > > > + gpt_entry partitions[]; > > > +} __packed; > > > + > > > struct efi_tcg2_protocol { > > > efi_status_t (EFIAPI * get_capability)(struct efi_tcg2_protocol *this, > > > struct efi_tcg2_boot_service_capability *capability); > > > diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c > > > index 701e2212c8..bf5661e1ee 100644 > > > --- a/lib/efi_loader/efi_boottime.c > > > +++ b/lib/efi_loader/efi_boottime.c > > > @@ -3003,7 +3003,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, > > > > > > if (IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL)) { > > > if (image_obj->image_type == IMAGE_SUBSYSTEM_EFI_APPLICATION) { > > > - ret = efi_tcg2_measure_efi_app_invocation(); > > > + ret = efi_tcg2_measure_efi_app_invocation(image_obj); > > > if (ret != EFI_SUCCESS) { > > > log_warning("tcg2 measurement fails(0x%lx)\n", > > > ret); > > > diff --git a/lib/efi_loader/efi_tcg2.c b/lib/efi_loader/efi_tcg2.c > > > index 4f68f6dfd5..ea2c1ead03 100644 > > > --- a/lib/efi_loader/efi_tcg2.c > > > +++ b/lib/efi_loader/efi_tcg2.c > > > @@ -1525,12 +1525,181 @@ static void *find_smbios_table(void) > > > return NULL; > > > } > > > > > > +/** > > > + * search_gpt_dp_node() - search gpt device path node > > > + * > > > + * @device_path: device path > > > + * > > > + * Return: pointer to the gpt device path node > > > + */ > > > +static struct > > > +efi_device_path *search_gpt_dp_node(struct efi_device_path *device_path) > > > +{ > > > + struct efi_device_path *dp = device_path; > > > + > > > + while (dp) { > > > + if (dp->type == DEVICE_PATH_TYPE_MEDIA_DEVICE && > > > + dp->sub_type == DEVICE_PATH_SUB_TYPE_HARD_DRIVE_PATH) { > > > + struct efi_device_path_hard_drive_path *hd_dp = > > > + (struct efi_device_path_hard_drive_path *)dp; > > > + > > > + if (hd_dp->partmap_type == PART_FORMAT_GPT && > > > > On dp_part_node() partmap_type is set to 2 for EFI partition types. Why do > > we interpret it as 'GPT' here? > > UEFI spec says: > partmap_type = 0x02 – GUID Partition Table Ah yes my bad, it's setting that to '2' indeed based on the 'struct blk_desc' info. This is correct > > > + total_gpt_entry_size = gpt_h->num_partition_entries * [...] > > > + gpt_h->sizeof_partition_entry; > > > + orig_gpt_e = calloc(1, total_gpt_entry_size + block_io->media->io_align); > > > + entry = (void *)ALIGN((uintptr_t)orig_gpt_e, block_io->media->io_align); > > > + if (!entry) { > > > + ret = EFI_OUT_OF_RESOURCES; > > > + goto out2; > > > + } > > > + > > > + ret = block_io->read_blocks(block_io, block_io->media->media_id, > > > + gpt_h->partition_entry_lba, > > > + total_gpt_entry_size, entry); > > > + if (ret != EFI_SUCCESS) > > > + goto out2; > > > + > > > > Can't you use efi_bl_read() here, instead of searching for the protocol? > > If you can, moving that out of a static function would make more sense. > > With chat discussion with Ilias, we concluded not to do this modification. Indeed efi_bl_read() cant be used here. Just a heads up to the rest of the people in this thread, just replace the alignment calls with PTR_ALIGN() and split the allocation/reading to a different fucntion. This should make this code a lot more readable. Thanks! /Ilias > > Thanks, > Masahisa Kojima > > > > > > + /* count valid GPT entry */ > > > + gpt_e = entry; > > > + for (i = 0; i < gpt_h->num_partition_entries; i++) { > > > + if (guidcmp(&null_guid, &gpt_e->partition_type_guid)) > > > + num_of_valid_entry++; > > > + > > > + gpt_e = (gpt_entry *)((u8 *)gpt_e + gpt_h->sizeof_partition_entry); > > > + } > > > + > > > + /* prepare event data for measurement */ > > > + event_size = sizeof(struct efi_gpt_data) + > > > + (num_of_valid_entry * gpt_h->sizeof_partition_entry); > > > + event = calloc(1, event_size); > > > + if (!event) { > > > + ret = EFI_OUT_OF_RESOURCES; > > > + goto out2; > > > + } > > > + memcpy(event, gpt_h, sizeof(gpt_header)); > > > + put_unaligned_le64(num_of_valid_entry, &event->number_of_partitions); > > > + > > > + /* copy valid GPT entry */ > > > + gpt_e = entry; > > > + num_of_valid_entry = 0; > > > + for (i = 0; i < gpt_h->num_partition_entries; i++) { > > > + if (guidcmp(&null_guid, &gpt_e->partition_type_guid)) { > > > + memcpy((u8 *)event->partitions + > > > + (num_of_valid_entry * gpt_h->sizeof_partition_entry), > > > + gpt_e, gpt_h->sizeof_partition_entry); > > > + num_of_valid_entry++; > > > + } > > > + > > > + gpt_e = (gpt_entry *)((u8 *)gpt_e + gpt_h->sizeof_partition_entry); > > > + } > > > + > > > + ret = tcg2_measure_event(dev, 5, EV_EFI_GPT_EVENT, event_size, (u8 *)event); > > > + if (ret != EFI_SUCCESS) > > > + goto out2; > > > + > > > +out2: > > > + EFI_CALL(efi_close_protocol((efi_handle_t)block_io, &efi_block_io_guid, > > > + NULL, NULL)); > > > + free(orig_gpt_h); > > > + free(orig_gpt_e); > > > + free(event); > > > +out1: > > > + efi_free_pool(device_path); > > > + > > > + return ret; > > > +} > > > + > > > /** > > > * efi_tcg2_measure_efi_app_invocation() - measure efi app invocation > > > * > > > * Return: status code > > > */ > > > -efi_status_t efi_tcg2_measure_efi_app_invocation(void) > > > +efi_status_t efi_tcg2_measure_efi_app_invocation(struct efi_loaded_image_obj *handle) > > > { > > > efi_status_t ret; > > > u32 pcr_index; > > > @@ -1569,6 +1738,10 @@ efi_status_t efi_tcg2_measure_efi_app_invocation(void) > > > goto out; > > > } > > > > > > + ret = tcg2_measure_gpt_data(dev, handle); > > > + if (ret != EFI_SUCCESS) > > > + goto out; > > > + > > > tcg2_efi_app_invoked = true; > > > out: > > > return ret; > > > -- > > > 2.17.1 > > > > > > > Cheers > > /Ilias