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 54052C678D4 for ; Thu, 2 Mar 2023 10:28:11 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 47B5E85A28; Thu, 2 Mar 2023 11:28:09 +0100 (CET) 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="w8siZe92"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3057685C39; Thu, 2 Mar 2023 11:28:08 +0100 (CET) Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) (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 BD2BB800B1 for ; Thu, 2 Mar 2023 11:28:05 +0100 (CET) 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-x534.google.com with SMTP id cw28so16442520edb.5 for ; Thu, 02 Mar 2023 02:28:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Vm5O90l1Z4Atz7FK4SvIL/RNpzM4+eD9fqb4N/fV6vA=; b=w8siZe92ZkxIlh/TukoqnwojHXVSnSER4OhuAPdHjqF8uVkTAfsCQtQafUBmTKseaQ QiBi8SsZ7h6jI+MvwQ+DySeQa+a+m2pqCZVWZiIBmjz5WuXoBnSaFptCoAJnf1QM5j3H gjp3YLmq8sbwKfb8yo2envyerJAlY/hZXCatZrl7z2gajmGVy+cJJvtuyl0nBrLM4TE7 IFyMcPnTcLWC5JOw4CO1jZPpZjz4L4dbWQ/zXDJTJVfDy8dkY75v3dD2YQmJUOhtBBlt rvma7gfWN3kHYZ4dHrgiFhLIvJMluQgSx/MfOlZoxlzkSap5tMKo7hKPYYfMepLxdael lyog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Vm5O90l1Z4Atz7FK4SvIL/RNpzM4+eD9fqb4N/fV6vA=; b=n+m+1ORv+CD0RH47+oOzZvnH00euiazeWgO143qBqdmcBdtY29YPB8f/w9NdSwu0Oo qV2cyuSVsObJNuVAWziIb8JmCtMAK6Qwxf37+kfrS94f1x93yadboyx9QePeqflkI9Oc nhkFNK3XnL/XKje6tgFoIMe3cb3W6h7s5J0Y8eCx7XT9vZpbZB+3Bmb4nCv0CXHkFGfi Neg6LkJnqh7dAmRcpIEpFhTaZD0A0e2uCLtTsX456KL5/qSg7x7NfdMHNhjzMVS+kHI8 a5JQcgXGyOvCxUWacHfCaZZu4Cy84mFvFd4LBnsGzO6pVtOwZ7bflHvVQNuIYj+HXAbp UPiA== X-Gm-Message-State: AO0yUKVqXOXI+5nI5GeidFp/1yPp6w47aKUq5qL1Ou+fTFQWQDNaKu3n HzY1rgoprhnma5TT7nT2AAEVyw== X-Google-Smtp-Source: AK7set8Tgbg87cZ2OufQh+HAfGybe050Xzu9ILkvO9N9K4Adyf9nOpIFf9XkJl7xPtkcZ76h+IJz2g== X-Received: by 2002:a17:906:d0d6:b0:8b1:7a80:3790 with SMTP id bq22-20020a170906d0d600b008b17a803790mr10624297ejb.69.1677752885333; Thu, 02 Mar 2023 02:28:05 -0800 (PST) Received: from hades (ppp176092130041.access.hol.gr. [176.92.130.41]) by smtp.gmail.com with ESMTPSA id rk20-20020a170907215400b008b9d2da5343sm6943474ejb.210.2023.03.02.02.28.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Mar 2023 02:28:05 -0800 (PST) Date: Thu, 2 Mar 2023 12:28:02 +0200 From: Ilias Apalodimas To: Eddie James Cc: u-boot@lists.denx.de, sjg@chromium.org, xypron.glpk@gmx.de, joel@jms.id.au Subject: Re: [PATCH v7 4/6] bootm: Support boot measurement Message-ID: References: <20230301225056.1402722-1-eajames@linux.ibm.com> <20230301225056.1402722-5-eajames@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230301225056.1402722-5-eajames@linux.ibm.com> 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 Eddie, [...] > > +int bootm_measure(struct bootm_headers *images) > +{ > + int ret = 0; > + > + /* Skip measurement if EFI is going to do it */ > + if (images->os.os == IH_OS_EFI && > + IS_ENABLED(CONFIG_EFI_TCG2_PROTOCOL) && > + IS_ENABLED(CONFIG_BOOTM_EFI)) > + return ret; This is nice. Basically measuring becomes the boot command responsibility. > + > + if (IS_ENABLED(CONFIG_MEASURED_BOOT)) { > + struct tcg2_event_log elog; > + struct udevice *dev; > + void *initrd_buf; > + void *image_buf; > + const char *s; > + u32 rd_len; > + > + elog.log_size = 0; > + ret = tcg2_measurement_init(&dev, &elog); > + if (ret) > + return ret; > + > + image_buf = map_sysmem(images->os.image_start, > + images->os.image_len); > + ret = tcg2_measure_data(dev, &elog, 8, images->os.image_len, > + image_buf, EV_COMPACT_HASH, > + strlen("linux") + 1, (u8 *)"linux"); > + if (ret) > + goto unmap_image; > + > + rd_len = images->rd_end - images->rd_start; > + initrd_buf = map_sysmem(images->rd_start, rd_len); > + ret = tcg2_measure_data(dev, &elog, 9, rd_len, initrd_buf, > + EV_COMPACT_HASH, strlen("initrd") + 1, > + (u8 *)"initrd"); > + if (ret) > + goto unmap_initrd; > + > + if (IS_ENABLED(CONFIG_MEASURE_DEVICETREE)) { > + ret = tcg2_measure_data(dev, &elog, 0, images->ft_len, > + (u8 *)images->ft_addr, > + EV_TABLE_OF_DEVICES, > + strlen("dts") + 1, > + (u8 *)"dts"); > + if (ret) > + goto unmap_initrd; > + } > + > + s = env_get("bootargs"); > + if (!s) > + s = ""; > + ret = tcg2_measure_data(dev, &elog, 1, strlen(s) + 1, (u8 *)s, > + EV_PLATFORM_CONFIG_FLAGS, > + strlen(s) + 1, (u8 *)s); > + > +unmap_initrd: > + unmap_sysmem(initrd_buf); > + > +unmap_image: > + unmap_sysmem(image_buf); > + tcg2_measurement_term(dev, &elog, ret != 0); > + } > + > + return ret; > +} > + > /** > * Execute selected states of the bootm command. > * > @@ -710,6 +778,10 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, > if (!ret && (states & BOOTM_STATE_FINDOTHER)) > ret = bootm_find_other(cmdtp, flag, argc, argv); > > + if (IS_ENABLED(CONFIG_MEASURED_BOOT) && !ret && > + (states & BOOTM_STATE_MEASURE)) > + bootm_measure(images); > + > /* Load the OS */ > if (!ret && (states & BOOTM_STATE_LOADOS)) { > iflag = bootm_disable_interrupts(); > diff --git a/cmd/booti.c b/cmd/booti.c > index 6ac39193db..659bb10549 100644 > --- a/cmd/booti.c > +++ b/cmd/booti.c > @@ -127,6 +127,7 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) > #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH > BOOTM_STATE_RAMDISK | > #endif > + BOOTM_STATE_MEASURE | > BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | > BOOTM_STATE_OS_GO, > &images, 1); > diff --git a/cmd/bootm.c b/cmd/bootm.c > index 37c2af96e0..0c4a713e02 100644 > --- a/cmd/bootm.c > +++ b/cmd/bootm.c > @@ -161,6 +161,8 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) > BOOTM_STATE_OS_GO; > if (IS_ENABLED(CONFIG_SYS_BOOT_RAMDISK_HIGH)) > states |= BOOTM_STATE_RAMDISK; > + if (IS_ENABLED(CONFIG_MEASURED_BOOT)) > + states |= BOOTM_STATE_MEASURE; > if (IS_ENABLED(CONFIG_PPC) || IS_ENABLED(CONFIG_MIPS)) > states |= BOOTM_STATE_OS_CMDLINE; > ret = do_bootm_states(cmdtp, flag, argc, argv, states, &images, 1); > diff --git a/cmd/bootz.c b/cmd/bootz.c > index f1423573d2..87922bfc3c 100644 > --- a/cmd/bootz.c > +++ b/cmd/bootz.c > @@ -81,6 +81,7 @@ int do_bootz(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) > #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH > BOOTM_STATE_RAMDISK | > #endif > + BOOTM_STATE_MEASURE | > BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO | > BOOTM_STATE_OS_GO, > &images, 1); > diff --git a/include/bootm.h b/include/bootm.h > index 044a4797ed..76e8e38c82 100644 > --- a/include/bootm.h > +++ b/include/bootm.h > @@ -55,6 +55,17 @@ ulong bootm_disable_interrupts(void); > int bootm_find_images(int flag, int argc, char *const argv[], ulong start, > ulong size); > > +/* > + * Measure the boot images. Measurement is the process of hashing some binary > + * data and storing it into secure memory, i.e. TPM PCRs. In addition, each > + * measurement is logged into the platform event log such that the operating > + * system can access it and perform attestation of the boot. > + * > + * @images: The structure containing the various images to boot (linux, > + * initrd, dts, etc.) > + */ > +int bootm_measure(struct bootm_headers *images); > + > int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc, > char *const argv[], int states, struct bootm_headers *images, > int boot_progress); > diff --git a/include/image.h b/include/image.h > index 7717a4c13d..f7414b5338 100644 > --- a/include/image.h > +++ b/include/image.h > @@ -407,6 +407,7 @@ struct bootm_headers { > #define BOOTM_STATE_OS_FAKE_GO 0x00000200 /* 'Almost' run the OS */ > #define BOOTM_STATE_OS_GO 0x00000400 > #define BOOTM_STATE_PRE_LOAD 0x00000800 > +#define BOOTM_STATE_MEASURE 0x00001000 > int state; > > #if defined(CONFIG_LMB) && !defined(USE_HOSTCC) > -- > 2.31.1 > Acked-by: Ilias Apalodimas