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 DFEDBC5479D for ; Mon, 9 Jan 2023 23:26:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5F09382A27; Tue, 10 Jan 2023 00:26:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de 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; secure) header.d=gmx.de header.i=@gmx.de header.b="sXQOVIbx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7B481835D8; Tue, 10 Jan 2023 00:26:56 +0100 (CET) Received: from mout.gmx.net (mout.gmx.net [212.227.15.19]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CB547817FB for ; Tue, 10 Jan 2023 00:26:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1673306809; bh=jGlfVEM1Z7Ux9/D4FttG5DOITAnyW1mFb1Tb/rFgReQ=; h=X-UI-Sender-Class:Date:Subject:From:To:Cc:References:In-Reply-To; b=sXQOVIbxoJwdhw6zP2KdvJPsgLX8+0WGJc84jnUxQDodfn9Q7gGDhX9Vt/oUlvnr7 ha8oAzk0JYr+H1BCOfGxIeaHl2Z/18Ayf5Jabn0D6RRuFtIZlgGk7JOr5JncVCbEGK Qd6lanC6CpBFY8fW/AzMl3lK0qPe/F/Ol0WUYkvlS/VWWBvpOzNEvoJUDWf6ezIlPu Jd4/k5Zi9ko3g5Z49yI8m/RLZ9davR8L4h5zDV8PgOwJTA+5ZXo/NkZRVbQBQcz5+b K/ENnyhpJ5KCF9mxJInAuSw8/j15lmOClFJ4wBcdzh85A5PqRvYac5jalFlgDyIneq SVgt8LQqtQiZQ== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.123.94] ([88.152.145.137]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M7Jza-1p7M1t2DrY-007lu1; Tue, 10 Jan 2023 00:26:49 +0100 Message-ID: Date: Tue, 10 Jan 2023 00:26:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v2 5/5] test: Add sandbox TPM boot measurement Content-Language: en-US From: Heinrich Schuchardt To: Eddie James Cc: ilias.apalodimas@linaro.org, sjg@chromium.org, u-boot@lists.denx.de References: <20230109215525.79046-1-eajames@linux.ibm.com> <20230109215525.79046-6-eajames@linux.ibm.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:OfdR+6fAOlFcwDmRL1On8V0TrTwRrGNOd9uEQIq8G93FrlZoKK1 osPrkHuz43JtoGOc9qIdjbBP/vji8yRyr2+Q0nZ0TUEHHzgP/UIYyVcl7SkYaLma2VvCZI8 H+2eXjuw+vNIqT4PGbIRrkf9L6f9gIlT/x+Iq2UJy74GtAOoDAsdcVwz/I5wOW7VOuwZlMK flqghg77zdkBq7EkzqVeg== UI-OutboundReport: notjunk:1;M01:P0:ZZHmKBrROJY=;gtTHE7JUTHz9JnOPo1SWk5Gj7Gg hw/0Fs1Ikz7+PzOBD1QM9FqPNuUue+gWTAoDwwZ07yvsOC72UWJJ8CbmNU+KyHYybIGQ18rv4 /kMcdRDGoufGw51Xmd9BqSrnpUvLiDOW2cw+gbwd/0yH+O+s3E53OEc8ySL35Cd/QH4TNmTMm mQIRZBnOLFwnm+f3gaQKLw3ovLA4BQ8BXmOlmmTgOSPCWOzNWOZvxO0J8khjKDTD+moPOYVRx xQKDaUOXY06JRaD3BEiqty6jPjM+a7kTlRBGev9S7hCK7CE8vNN1ATCRiNDNo6Cx9mHY7fd4n 1tTFMGYsxg0Wqg2NsKwYsCPlz2wE/oS/Rsa+beNq7+QDFAuJWj5zXQGByUA+ZUhw4HD12Mm7D y0uv95DrzdmLj70vsehYNvLWPEnQf6IFkA2W3Xr2IjRuy09EdcyVUkTYNlAKMwfo0cHWXzSAp 4bfOzvWo90h/3JaMQmx650vHG45u5bgKEoDykcEcKRyayS/kdFvBB7bE7sQ4IXao1qXEFLBy1 G0Rs8ZyQ5fGkD3vS84WnlGJtLws2e8v3O++VQIcqM6cfxtoypZL9xvzVVva0tXUlDq7Bx7jXE puP+5VPcY5UnP5K5ZkHehzBjq8sJi+T+cQLya5qbGyTR/dkB0npOuDq9fJOMcJa81ZYPsEcK1 lM8lhVrgvcwTR7WMubfzabl7jbjPIbnJBMsYQ5UbISi/8eI2vGHm3pgj+4qaM9WzlDOQZGits pOMo/OAhmcR6RFy2tKDuChxodDhDmTW1XAw47Tyq0enmvsMyjY+Kf2ZbzEmdgrwijE6+yGbDD YOYphCXxFsFnZUdtP6yWg+Kc7Ph5wczctixwlbVIys0ZhV186DAg8XtPSX9pEqLEHMCGNm7qg 7rdBbCrubEU9ArtPBFr4A1LFIvGFJuYoO53H8v0D2uAiwSMM4MIFCPK6ByjncEE1HmZCZ181S N6niqsKoKwmIlFgnMpfW3bicDdM= 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/10/23 00:13, Heinrich Schuchardt wrote: > On 1/9/23 22:55, Eddie James wrote: >> Use the sandbox TPM driver to measure some boot images in a unit >> test case. >> >> $ ./u-boot -T -c "ut measurement" >> Running 1 measurement tests >> Test: measure: measurement.c >> Failures: 0 >> >> Signed-off-by: Eddie James >> --- >> =C2=A0 arch/sandbox/dts/test.dts | 12 +++++++ >> =C2=A0 configs/sandbox_defconfig |=C2=A0 1 + >> =C2=A0 include/test/suites.h=C2=A0=C2=A0=C2=A0=C2=A0 |=C2=A0 1 + >> =C2=A0 test/boot/Makefile=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 |= =C2=A0 1 + >> =C2=A0 test/boot/measurement.c=C2=A0=C2=A0 | 66 +++++++++++++++++++++++= ++++++++++++++++ >> =C2=A0 test/cmd_ut.c=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0 |=C2=A0 2 ++ >> =C2=A0 6 files changed, 83 insertions(+) >> =C2=A0 create mode 100644 test/boot/measurement.c >> >> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts >> index dffe10adbf..ad90bf0541 100644 >> --- a/arch/sandbox/dts/test.dts >> +++ b/arch/sandbox/dts/test.dts >> @@ -66,6 +66,17 @@ >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 osd0 =3D "/osd"; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }; >> >> +=C2=A0=C2=A0=C2=A0 reserved-memory { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #address-cells =3D <1>; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 #size-cells =3D <1>; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ranges; >> + >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 event_log: tcg_event_log@d0= e000 { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 no-= map; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 reg= =3D <0x00d0e000 0x2000>; How should this work if you don't define linux,sml-base and linux,sml-size= ? Best regards Heinrich > > This would limit the file loaded at $loadaddr =3D 0x0 to 13 MiB. Please, > choose a much higher address. Or change $loadaddr, e.g. use loadaddr =3D > kernel_addr_r =3D 0x1000000. I would prefer raising loadaddr. > > Best regards > > Heinrich > >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }; >> +=C2=A0=C2=A0=C2=A0 }; >> + >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 binman: binman { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }; >> >> @@ -1332,6 +1343,7 @@ >> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 tpm2 { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 compatible =3D "= sandbox,tpm2"; >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 memory-region =3D <&event_l= og>; >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 }; >> >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 uart0: serial { >> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig >> index de799b5cea..5ac115f2d8 100644 >> --- a/configs/sandbox_defconfig >> +++ b/configs/sandbox_defconfig >> @@ -335,3 +335,4 @@ CONFIG_TEST_FDTDEC=3Dy >> =C2=A0 CONFIG_UNIT_TEST=3Dy >> =C2=A0 CONFIG_UT_TIME=3Dy >> =C2=A0 CONFIG_UT_DM=3Dy >> +CONFIG_MEASURED_BOOT=3Dy >> diff --git a/include/test/suites.h b/include/test/suites.h >> index a01000e127..f9284871b0 100644 >> --- a/include/test/suites.h >> +++ b/include/test/suites.h >> @@ -43,6 +43,7 @@ int do_ut_font(struct cmd_tbl *cmdtp, int flag, int >> argc, char *const argv[]); >> =C2=A0 int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *c= onst >> argv[]); >> =C2=A0 int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char >> *const argv[]); >> =C2=A0 int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * >> const argv[]); >> +int do_ut_measurement(struct cmd_tbl *cmdtp, int flag, int argc, char >> * const argv[]); >> =C2=A0 int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *c= onst >> argv[]); >> =C2=A0 int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char >> *const argv[]); >> =C2=A0 int do_ut_overlay(struct cmd_tbl *cmdtp, int flag, int argc, >> diff --git a/test/boot/Makefile b/test/boot/Makefile >> index d724629d3b..24cc20bdff 100644 >> --- a/test/boot/Makefile >> +++ b/test/boot/Makefile >> @@ -4,6 +4,7 @@ >> >> =C2=A0 obj-$(CONFIG_BOOTSTD) +=3D bootdev.o bootstd_common.o bootflow.o >> bootmeth.o >> =C2=A0 obj-$(CONFIG_FIT) +=3D image.o >> +obj-$(CONFIG_MEASURED_BOOT) +=3D measurement.o >> >> =C2=A0 ifdef CONFIG_OF_LIVE >> =C2=A0 obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) +=3D vbe_simple.o >> diff --git a/test/boot/measurement.c b/test/boot/measurement.c >> new file mode 100644 >> index 0000000000..2155208894 >> --- /dev/null >> +++ b/test/boot/measurement.c >> @@ -0,0 +1,66 @@ >> +// SPDX-License-Identifier: GPL-2.0+ >> +/* >> + * Test for measured boot functions >> + * >> + * Copyright 2023 IBM Corp. >> + * Written by Eddie James >> + */ >> + >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +#define MEASUREMENT_TEST(_name, _flags)=C2=A0=C2=A0=C2=A0 \ >> +=C2=A0=C2=A0=C2=A0 UNIT_TEST(_name, _flags, measurement_test) >> + >> +static int measure(struct unit_test_state *uts) >> +{ >> +=C2=A0=C2=A0=C2=A0 struct bootm_headers images; >> +=C2=A0=C2=A0=C2=A0 const size_t size =3D 1024; >> +=C2=A0=C2=A0=C2=A0 u8 *kernel; >> +=C2=A0=C2=A0=C2=A0 u8 *initrd; >> +=C2=A0=C2=A0=C2=A0 size_t i; >> + >> +=C2=A0=C2=A0=C2=A0 kernel =3D malloc(size); >> +=C2=A0=C2=A0=C2=A0 initrd =3D malloc(size); >> + >> +=C2=A0=C2=A0=C2=A0 images.os.image_start =3D map_to_sysmem(kernel); >> +=C2=A0=C2=A0=C2=A0 images.os.image_len =3D size; >> + >> +=C2=A0=C2=A0=C2=A0 images.rd_start =3D map_to_sysmem(initrd); >> +=C2=A0=C2=A0=C2=A0 images.rd_end =3D images.rd_start + size; >> + >> +=C2=A0=C2=A0=C2=A0 images.ft_addr =3D malloc(size); >> +=C2=A0=C2=A0=C2=A0 images.ft_len =3D size; >> + >> +=C2=A0=C2=A0=C2=A0 env_set("bootargs", "measurement testing"); >> + >> +=C2=A0=C2=A0=C2=A0 for (i =3D 0; i < size; ++i) { >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 kernel[i] =3D (u8)(0xf0 | (= i & 0xf)); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 initrd[i] =3D (u8)((i & 0xf= 0) | 0xf); >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ((u8 *)images.ft_addr)[i] = =3D (u8)(i & 0xff); >> +=C2=A0=C2=A0=C2=A0 } >> + >> +=C2=A0=C2=A0=C2=A0 ut_assertok(bootm_measure(&images)); >> + >> +=C2=A0=C2=A0=C2=A0 free(images.ft_addr); >> +=C2=A0=C2=A0=C2=A0 free(initrd); >> +=C2=A0=C2=A0=C2=A0 free(kernel); >> + >> +=C2=A0=C2=A0=C2=A0 return 0; >> +} >> +MEASUREMENT_TEST(measure, 0); >> + >> +int do_ut_measurement(struct cmd_tbl *cmdtp, int flag, int argc, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 char *const argv[]) >> +{ >> +=C2=A0=C2=A0=C2=A0 struct unit_test *tests =3D UNIT_TEST_SUITE_START(m= easurement_test); >> +=C2=A0=C2=A0=C2=A0 const int n_ents =3D UNIT_TEST_SUITE_COUNT(measurem= ent_test); >> + >> +=C2=A0=C2=A0=C2=A0 return cmd_ut_category("measurement", "measurement_= test_", tests, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 n_ents, argc, argv); >> +} >> diff --git a/test/cmd_ut.c b/test/cmd_ut.c >> index 2736582f11..819031c0f8 100644 >> --- a/test/cmd_ut.c >> +++ b/test/cmd_ut.c >> @@ -100,6 +100,8 @@ static struct cmd_tbl cmd_ut_sub[] =3D { >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 "", ""), >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MA= XARGS, 1, do_ut_bloblist, >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 "", ""), >> +=C2=A0=C2=A0=C2=A0 U_BOOT_CMD_MKENT(measurement, CONFIG_SYS_MAXARGS, 1= , >> do_ut_measurement, >> +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 "", ""), >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXAR= GS, 1, do_ut_bootm, "", >> ""), >> =C2=A0 #endif >> =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS= , 1, do_ut_str, "", ""), >