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 B2EAEC46467 for ; Tue, 10 Jan 2023 16:39:29 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 648758545D; Tue, 10 Jan 2023 17:39:27 +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="HUqVwF1i"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 824E58545D; Tue, 10 Jan 2023 17:39:24 +0100 (CET) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 4FDC58539D for ; Tue, 10 Jan 2023 17:39:02 +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 (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 30AGI01u012519; Tue, 10 Jan 2023 16:38:58 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=h5gG6ihVrjsgpJ0AHztvY02J7cZG3cHk+IoWNkX9OOg=; b=HUqVwF1iExyqQ3pbiAUJUOzenVDC/Lr9Np8xy6q8A8MXqOaATgLTRV1qrdjkGA98YvRq QtLaspay1f/9GQK43PBPG0+TsXpj/+wLgJc67pQy2rduTXPvwoXDOiI7zHEbiGgofss4 uzQ6qchkQI0gFNfG9LpaxwsYX+p3tyQCKmlA+GU2oWR1H6HGTVkWkXLrW3F9QvFEud1C 1dkdWHOBYA2Gn+m6A+5ruhIXKdu6TJhWOQEpRhTBWu7UNNhKcF6zm3ap68MnqD+wj6tD lI3hrQ97XnPf3C/+GMpmcETwUv6MENxnhVP/75bOLnkeWTGkVRAPWIb6C5ISArDMsWAP jA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3n188dxuju-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Jan 2023 16:38:58 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 30AGNcl8011000; Tue, 10 Jan 2023 16:38:57 GMT Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3n188dxuje-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Jan 2023 16:38:57 +0000 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30AF0uvt029629; Tue, 10 Jan 2023 16:38:57 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([9.208.129.114]) by ppma03dal.us.ibm.com (PPS) with ESMTPS id 3my0c7qdu0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Jan 2023 16:38:56 +0000 Received: from smtpav05.wdc07v.mail.ibm.com (smtpav05.wdc07v.mail.ibm.com [10.39.53.232]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 30AGctC128115514 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Jan 2023 16:38:55 GMT Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 82D0F5805D; Tue, 10 Jan 2023 16:38:55 +0000 (GMT) Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBAF558043; Tue, 10 Jan 2023 16:38:54 +0000 (GMT) Received: from [9.65.206.155] (unknown [9.65.206.155]) by smtpav05.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 10 Jan 2023 16:38:54 +0000 (GMT) Message-ID: <4192c9f7-6b8a-4d94-150f-d48e2be364cf@linux.ibm.com> Date: Tue, 10 Jan 2023 10:38:54 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v2 5/5] test: Add sandbox TPM boot measurement To: Heinrich Schuchardt 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> Content-Language: en-US From: Eddie James In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: wqQezAyb0cEhLdKGyoWKt5aIiCjijijL X-Proofpoint-GUID: YdhIilxjSbnjUNvAx84zBCRsSpnAFHv2 Content-Transfer-Encoding: 8bit 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-10_06,2023-01-10_03,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 spamscore=0 priorityscore=1501 bulkscore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301100104 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/9/23 17:26, Heinrich Schuchardt wrote: > 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 >>> --- >>>   arch/sandbox/dts/test.dts | 12 +++++++ >>>   configs/sandbox_defconfig |  1 + >>>   include/test/suites.h     |  1 + >>>   test/boot/Makefile        |  1 + >>>   test/boot/measurement.c   | 66 >>> +++++++++++++++++++++++++++++++++++++++ >>>   test/cmd_ut.c             |  2 ++ >>>   6 files changed, 83 insertions(+) >>>   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 @@ >>>           osd0 = "/osd"; >>>       }; >>> >>> +    reserved-memory { >>> +        #address-cells = <1>; >>> +        #size-cells = <1>; >>> +        ranges; >>> + >>> +        event_log: tcg_event_log@d0e000 { >>> +            no-map; >>> +            reg = <0x00d0e000 0x2000>; > > How should this work if you don't define linux,sml-base and > linux,sml-size? I have sent a patch to the linux list for using a reserved memory region, as I have also added in the u-boot TPM layer for the event log. https://patchwork.kernel.org/project/linux-integrity/patch/20230103162010.381214-1-eajames@linux.ibm.com/ Thanks, Eddie > > Best regards > > Heinrich > >> >> This would limit the file loaded at $loadaddr = 0x0 to 13 MiB. Please, >> choose a much higher address. Or change $loadaddr, e.g. use loadaddr = >> kernel_addr_r = 0x1000000. I would prefer raising loadaddr. >> >> Best regards >> >> Heinrich >> >>> +        }; >>> +    }; >>> + >>>       binman: binman { >>>       }; >>> >>> @@ -1332,6 +1343,7 @@ >>> >>>       tpm2 { >>>           compatible = "sandbox,tpm2"; >>> +        memory-region = <&event_log>; >>>       }; >>> >>>       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=y >>>   CONFIG_UNIT_TEST=y >>>   CONFIG_UT_TIME=y >>>   CONFIG_UT_DM=y >>> +CONFIG_MEASURED_BOOT=y >>> 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[]); >>>   int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const >>> argv[]); >>>   int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char >>> *const argv[]); >>>   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[]); >>>   int do_ut_mem(struct cmd_tbl *cmdtp, int flag, int argc, char *const >>> argv[]); >>>   int do_ut_optee(struct cmd_tbl *cmdtp, int flag, int argc, char >>> *const argv[]); >>>   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 @@ >>> >>>   obj-$(CONFIG_BOOTSTD) += bootdev.o bootstd_common.o bootflow.o >>> bootmeth.o >>>   obj-$(CONFIG_FIT) += image.o >>> +obj-$(CONFIG_MEASURED_BOOT) += measurement.o >>> >>>   ifdef CONFIG_OF_LIVE >>>   obj-$(CONFIG_BOOTMETH_VBE_SIMPLE) += 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)    \ >>> +    UNIT_TEST(_name, _flags, measurement_test) >>> + >>> +static int measure(struct unit_test_state *uts) >>> +{ >>> +    struct bootm_headers images; >>> +    const size_t size = 1024; >>> +    u8 *kernel; >>> +    u8 *initrd; >>> +    size_t i; >>> + >>> +    kernel = malloc(size); >>> +    initrd = malloc(size); >>> + >>> +    images.os.image_start = map_to_sysmem(kernel); >>> +    images.os.image_len = size; >>> + >>> +    images.rd_start = map_to_sysmem(initrd); >>> +    images.rd_end = images.rd_start + size; >>> + >>> +    images.ft_addr = malloc(size); >>> +    images.ft_len = size; >>> + >>> +    env_set("bootargs", "measurement testing"); >>> + >>> +    for (i = 0; i < size; ++i) { >>> +        kernel[i] = (u8)(0xf0 | (i & 0xf)); >>> +        initrd[i] = (u8)((i & 0xf0) | 0xf); >>> +        ((u8 *)images.ft_addr)[i] = (u8)(i & 0xff); >>> +    } >>> + >>> +    ut_assertok(bootm_measure(&images)); >>> + >>> +    free(images.ft_addr); >>> +    free(initrd); >>> +    free(kernel); >>> + >>> +    return 0; >>> +} >>> +MEASUREMENT_TEST(measure, 0); >>> + >>> +int do_ut_measurement(struct cmd_tbl *cmdtp, int flag, int argc, >>> +              char *const argv[]) >>> +{ >>> +    struct unit_test *tests = UNIT_TEST_SUITE_START(measurement_test); >>> +    const int n_ents = UNIT_TEST_SUITE_COUNT(measurement_test); >>> + >>> +    return cmd_ut_category("measurement", "measurement_test_", tests, >>> +                   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[] = { >>>                "", ""), >>>       U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist, >>>                "", ""), >>> +    U_BOOT_CMD_MKENT(measurement, CONFIG_SYS_MAXARGS, 1, >>> do_ut_measurement, >>> +             "", ""), >>>       U_BOOT_CMD_MKENT(bootm, CONFIG_SYS_MAXARGS, 1, do_ut_bootm, "", >>> ""), >>>   #endif >>>       U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str, "", ""), >> > >