All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Eddie James <eajames@linux.ibm.com>
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
Date: Thu, 2 Mar 2023 12:28:02 +0200	[thread overview]
Message-ID: <ZAB6Mmi4QrDhCxd9@hades> (raw)
In-Reply-To: <20230301225056.1402722-5-eajames@linux.ibm.com>

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 <ilias.apalodimas@linaro.org>

  reply	other threads:[~2023-03-02 10:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-01 22:50 [PATCH v7 0/6] tpm: Support boot measurements Eddie James
2023-03-01 22:50 ` [PATCH v7 1/6] tpm: Fix spelling for tpmu_ha union Eddie James
2023-03-01 22:50 ` [PATCH v7 2/6] tpm: sandbox: Update for needed TPM2 capabilities Eddie James
2023-03-01 22:50 ` [PATCH v7 3/6] tpm: Support boot measurements Eddie James
2023-03-02 14:17   ` Ilias Apalodimas
2023-03-02 14:35     ` Ilias Apalodimas
2023-03-02 20:22   ` Ilias Apalodimas
2023-03-03 19:17     ` Eddie James
2023-03-01 22:50 ` [PATCH v7 4/6] bootm: Support boot measurement Eddie James
2023-03-02 10:28   ` Ilias Apalodimas [this message]
2023-03-01 22:50 ` [PATCH v7 5/6] test: Add sandbox TPM " Eddie James
2023-03-01 22:50 ` [PATCH v7 6/6] doc: Add measured boot documentation Eddie James
2023-03-02 10:29   ` Ilias Apalodimas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZAB6Mmi4QrDhCxd9@hades \
    --to=ilias.apalodimas@linaro.org \
    --cc=eajames@linux.ibm.com \
    --cc=joel@jms.id.au \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.