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 5B484C46467 for ; Wed, 4 Jan 2023 14:56:45 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EC9DF8522E; Wed, 4 Jan 2023 15:56:42 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=linux.ibm.com 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=ibm.com header.i=@ibm.com header.b="EL0joYZt"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D558485301; Wed, 4 Jan 2023 15:56:41 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 7E9F5851E6 for ; Wed, 4 Jan 2023 15:56:38 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=eajames@linux.ibm.com Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 304CpYu8010333; Wed, 4 Jan 2023 14:56:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pp1; bh=b8qHX4+WslzgUWoPvRoq1seI+x1y+PQR0TM85cAj4I8=; b=EL0joYZteiPyin2fxT0RVYfnTwswz5dOaFs0CZqYFskpxD1Iv4uQr7Vb/acJww9aRAFQ Jsjd9GeNZ+g2yPCeZ99ZNMqO/ZT9gbB4KlyapZJP0byY0X7bBIqb3AffxQlSzPWSzx8m 7L6ZWsrEUkCfH2tKgNs2T6p07lJW/yks8bREDJIn+TrD661ncjG+DDgNwGWVkHcRlZj6 Oz9osyCFlwEecS9y3o8n97+EY2lO6nZWrycgbC0v7t1zpu10IfGrMd3zU4YGBIr1mKwK 72zwfITkolZwmh0zu4mUjVMHqfP1JGnTAXbunY2enoHkCa60zRCl4hEhYT8eDR5joSu+ OA== Received: from ppma03wdc.us.ibm.com (ba.79.3fa9.ip4.static.sl-reverse.com [169.63.121.186]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3mw9u2357n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Jan 2023 14:56:36 +0000 Received: from pps.filterd (ppma03wdc.us.ibm.com [127.0.0.1]) by ppma03wdc.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 304CURF2009551; Wed, 4 Jan 2023 14:56:36 GMT Received: from smtprelay07.dal12v.mail.ibm.com ([9.208.130.99]) by ppma03wdc.us.ibm.com (PPS) with ESMTPS id 3mtcq7g9qv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 04 Jan 2023 14:56:35 +0000 Received: from smtpav02.dal12v.mail.ibm.com (smtpav02.dal12v.mail.ibm.com [10.241.53.101]) by smtprelay07.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 304EuZkQ27132624 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 4 Jan 2023 14:56:35 GMT Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3433C58051; Wed, 4 Jan 2023 14:56:35 +0000 (GMT) Received: from smtpav02.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BFAF65805A; Wed, 4 Jan 2023 14:56:34 +0000 (GMT) Received: from [9.65.254.210] (unknown [9.65.254.210]) by smtpav02.dal12v.mail.ibm.com (Postfix) with ESMTP; Wed, 4 Jan 2023 14:56:34 +0000 (GMT) Message-ID: <09366ff0-8dfb-7a85-0c62-935b4337df54@linux.ibm.com> Date: Wed, 4 Jan 2023 08:56:34 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH 3/3] bootm: Support boot measurement Content-Language: en-US To: Etienne Carriere Cc: u-boot@lists.denx.de, ilias.apalodimas@linaro.org References: <20230103204202.417074-1-eajames@linux.ibm.com> <20230103204202.417074-4-eajames@linux.ibm.com> From: Eddie James In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: _j4CdctqNZGWz_th4XtRAiBS92cgwAoU X-Proofpoint-GUID: _j4CdctqNZGWz_th4XtRAiBS92cgwAoU Content-Transfer-Encoding: 7bit X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-04_07,2023-01-04_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 suspectscore=0 mlxscore=0 spamscore=0 impostorscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 bulkscore=0 clxscore=1011 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301040123 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 On 1/4/23 03:56, Etienne Carriere wrote: > Hello Eddie and all, > > On Tue, 3 Jan 2023 at 21:42, Eddie James wrote: >> Add a configuration option to measure the boot through the bootm >> function. >> >> Signed-off-by: Eddie James >> --- >> boot/bootm.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ >> cmd/bootm.c | 2 ++ >> common/Kconfig | 6 ++++++ >> include/image.h | 1 + >> 4 files changed, 62 insertions(+) >> >> diff --git a/boot/bootm.c b/boot/bootm.c >> index a4c0870c0f..7f64d79035 100644 >> --- a/boot/bootm.c >> +++ b/boot/bootm.c >> @@ -22,6 +22,9 @@ >> #include >> #include >> #include >> +#if defined(CONFIG_MEASURED_BOOT) >> +#include >> +#endif >> #if defined(CONFIG_CMD_USB) >> #include >> #endif >> @@ -713,6 +716,56 @@ 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 defined(CONFIG_MEASURED_BOOT) >> + if (!ret && (states & BOOTM_STATE_MEASURE)) { >> + void *initrd_buf; >> + void *image_buf; >> + const char *s; >> + u32 rd_len; >> + >> + ret = tcg2_measurement_init(); >> + if (ret) >> + goto measure_err; >> + >> + image_buf = map_sysmem(images->os.image_start, >> + images->os.image_len); >> + ret = tcg2_measure_data(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(8, rd_len, initrd_buf, EV_COMPACT_HASH, >> + strlen("initrd") + 1, (u8 *)"initrd"); >> + if (ret) >> + goto unmap_initrd; >> + >> + ret = tcg2_measure_data(9, images->ft_len, >> + (u8 *)images->ft_addr, >> + EV_TABLE_OF_DEVICES, strlen("dts") + 1, >> + (u8 *)"dts"); > This unconditionally measures DTB content but maybe there are > information that may differ at each boot as a random MAC address or an > ASLR seed. > Do you think something should condition measurement of the passed DTB > as proposed using a config switch in [1]? > > [1] https://lore.kernel.org/all/20221207151110.529106-1-etienne.carriere@linaro.org/ That would make sense, I am happy to add that in v2. Should I use that config switch as-is or add a new one for the bootm measurement? Thanks Eddie > > Regards, > Etienne > >> + if (ret) >> + goto unmap_initrd; >> + >> + s = env_get("bootargs"); >> + if (!s) >> + s = ""; >> + tcg2_measure_data(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(); >> +measure_err: >> + ret = 0; >> + } >> +#endif >> + >> /* Load the OS */ >> if (!ret && (states & BOOTM_STATE_LOADOS)) { >> iflag = bootm_disable_interrupts(); >> 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/common/Kconfig b/common/Kconfig >> index 21434c5cf1..57ef68e4f3 100644 >> --- a/common/Kconfig >> +++ b/common/Kconfig >> @@ -799,6 +799,12 @@ config AVB_BUF_SIZE >> >> endif # AVB_VERIFY >> >> +config MEASURED_BOOT >> + bool "Measure the boot to TPM and event log" >> + depends on HASH && TPM_V2 >> + help >> + This option enables measurement of the boot process. >> + >> config SCP03 >> bool "Build SCP03 - Secure Channel Protocol O3 - controls" >> depends on OPTEE || SANDBOX >> diff --git a/include/image.h b/include/image.h >> index 6f21dafba8..b00803eeac 100644 >> --- a/include/image.h >> +++ b/include/image.h >> @@ -406,6 +406,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 >>