From patchwork Wed May 10 07:43:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 680509 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp2697252wrs; Wed, 10 May 2023 00:45:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6cPe8V/yeXHmw9qRaOHjBgQJC/zp8m9SUn8tdGk1TNwJLUEAQ/hfGkGDIUYTRDas2Y9KoF X-Received: by 2002:a17:902:788d:b0:1ac:8215:623d with SMTP id q13-20020a170902788d00b001ac8215623dmr8278366pll.0.1683704718551; Wed, 10 May 2023 00:45:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683704718; cv=none; d=google.com; s=arc-20160816; b=wzqpKM264hVNOyHXp+pVosc10nYaGWc5FKaXQjLqYfvNPU3V283AXxxtAn0cCfQQV8 mSSer0uB7iTl5mG93a09kQv1QGR5QTHdcyozIy1/fvwXBwR8s9S3sXyUtbqlolMH5s4I WqoB5o/xrsWnHYv4EGpuujq5dV/hW5+A38Sg51jg66ZF+Ydu5t1lG+wtc/RHfD+G1PNn UxkJQpHLsinvMNcYll78DIfOXjYoMDWlZLxeB3QRaZIj3PxS508mOllfBbJmfIQqgiF1 IDDalLBYFcdYEBGqO8ErMMC/9texiU8JILCLfWjH80jDRSxX++sEQddORJj4K3If7/Ol oyKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fdncRAzEjlYFV0cOPnsEPemVPi9nrtcDyU0JPiIIbmM=; b=TcTeKciWbCTPp5ftP86dt0LHypYxPTeTycwSABOJVvdwRejGAPRw6dE7xwUXk89SPT WhgR+iEkjv4ABuu/1CiwfLiaGCidf+7UJDTh/nErzaFmQUIJ53hgE4wc6AoU93UYYKX9 PxKASK032559cbWBPULavhLueUjen/sVIuChVwEWfmaaZIPatVAFTDeioY3oUL3mRzjY 2S28dAas37bmkiTPrvy2Q1bskfmZbp6gB48ul9n0at8GAxJC7fgXjtzneANoyaSI3+bK DJ8yVTMh6oVPWL9vWLlBUmNe2GdfmHgUiC4Nvla/rE5FriKTRo03o+rnHTg3osq8ut/z zFpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ihbYcEIU; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id w10-20020a1709029a8a00b001ac94b7f2e7si3279668plp.343.2023.05.10.00.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 00:45:18 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ihbYcEIU; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E652286074; Wed, 10 May 2023 09:44:38 +0200 (CEST) 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="ihbYcEIU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5D1DE8606E; Wed, 10 May 2023 09:44:36 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (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 96C9B86071 for ; Wed, 10 May 2023 09:44:31 +0200 (CEST) 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-wr1-x42c.google.com with SMTP id ffacd0b85a97d-30639daee76so4432852f8f.1 for ; Wed, 10 May 2023 00:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1683704671; x=1686296671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fdncRAzEjlYFV0cOPnsEPemVPi9nrtcDyU0JPiIIbmM=; b=ihbYcEIUj3DM2DlkTbr7OUMq4/2lck0TnT3BAOmYuyoftwXbT7GgR2tcTQRwLBwoZa v0UlVS6hio4LgKhwKtM21jobBlgGm0nzTiuCSJPmw0rpWXNkJ5C1nmbQFUmV0952rluh 56cg91SMfr9BPojqkaaih8t9Va/ZZm+lU0+C1nRqWEvDnrbzgvnWFZdtFECvY9fjPRk5 ac7IWhwRGn1O9+LD3ZMxDFCzfnoopgWYLRJuk+07N/+CsngOtjR2KEV2lKFnxMrm/Y7T Y96TvcTdhHSU4Yl9uZbBXngU+lnP0cy0j/tgMpw+pY0tO/NcPbdKyE4VD0Za75WPG1Js ISkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683704671; x=1686296671; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fdncRAzEjlYFV0cOPnsEPemVPi9nrtcDyU0JPiIIbmM=; b=U7SGiNs48h1qUcfEmH+4le+QrodV4PlFRRYynlTcsIzetI8rtokrIafhT+VkXvcFGX //eTr1+hfqKDuzPN64elhrIXOcbIPIidJq8yeKAwZjFl+RhlVUucvWyWXoDGyCytcbla R1dW/IVrm8z8UsNJC4IfDsUpl+ZmK6PonSPMToJb9p9EB/blODZwo3rRajkhUT9nOPjO b8wIto2bjXX2nblcuZg7Fuqn8zgWlS6XXhgvQCET5YbotaW7mty7ZBPOmq4XvY6kjxnm 9dEKqZr9JKqo2JLqt8nvKMXDu9r163fga7OkLySpGy26yEzu31UPsqr4IZ7uhDE0DKQH VWxg== X-Gm-Message-State: AC+VfDz2hdbUGYpsk3YFwgMNKv6nqW2CufDuhrLoLlBtmpXbJ1pp10kp TlyDe8v0KJ+f+gC3MAeyrb7b7/967MYTDRb9cLyW0A== X-Received: by 2002:a5d:4701:0:b0:306:31e0:964 with SMTP id y1-20020a5d4701000000b0030631e00964mr10878590wrq.55.1683704671057; Wed, 10 May 2023 00:44:31 -0700 (PDT) Received: from localhost.localdomain (ppp176092130041.access.hol.gr. [176.92.130.41]) by smtp.gmail.com with ESMTPSA id p20-20020a1c7414000000b003f435652aaesm2022446wmc.11.2023.05.10.00.44.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 May 2023 00:44:30 -0700 (PDT) From: Ilias Apalodimas To: u-boot@lists.denx.de Cc: Eddie James , Simon Glass , Ilias Apalodimas , Heinrich Schuchardt , Robert Marko , Dzmitry Sankouski , Rasmus Villemoes , Sean Anderson , Nikhil M Jain , Abdellatif El Khlifi , Andrew Davis , Safae Ouajih , Mattijs Korpershoek , Daniel Golle , Sughosh Ganu , Roger Knecht , Steven Lawrance , Rui Miguel Silva , Linus Walleij , Marek Vasut , Stephen Carlson , Leo Yu-Chi Liang , Kautuk Consul , Brandon Maier , Patrick Delaunay Subject: [PATCH 5/9] test: Add sandbox TPM boot measurement Date: Wed, 10 May 2023 10:43:53 +0300 Message-Id: <20230510074359.2837818-5-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230510074359.2837818-1-ilias.apalodimas@linaro.org> References: <20230510074359.2837818-1-ilias.apalodimas@linaro.org> MIME-Version: 1.0 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.8 at phobos.denx.de X-Virus-Status: Clean From: Eddie James Use the sandbox TPM driver to measure some boot images in a unit test case. Signed-off-by: Eddie James Reviewed-by: Simon Glass Acked-by: Ilias Apalodimas --- arch/sandbox/dts/sandbox.dtsi | 13 +++++++ arch/sandbox/dts/test.dts | 13 +++++++ configs/sandbox_defconfig | 1 + include/test/suites.h | 1 + test/boot/Makefile | 1 + test/boot/measurement.c | 66 +++++++++++++++++++++++++++++++++++ test/cmd_ut.c | 4 +++ 7 files changed, 99 insertions(+) create mode 100644 test/boot/measurement.c diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi index 30a305c4d208..ed39d20c6a4a 100644 --- a/arch/sandbox/dts/sandbox.dtsi +++ b/arch/sandbox/dts/sandbox.dtsi @@ -4,11 +4,23 @@ * and sandbox64 builds. */ +#include #include #define USB_CLASS_HUB 9 / { + reserved-memory { + #address-cells = <1>; + #size-cells = <1>; + ranges; + + event_log: tcg_event_log { + no-map; + reg = <(CFG_SYS_SDRAM_SIZE - 0x2000) 0x2000>; + }; + }; + binman { }; @@ -336,6 +348,7 @@ tpm2 { compatible = "sandbox,tpm2"; + memory-region = <&event_log>; }; triangle { diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 453e53db71a8..ad17c535ad0a 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -9,6 +9,7 @@ /dts-v1/; +#include #include #include #include @@ -66,6 +67,17 @@ osd0 = "/osd"; }; + reserved-memory { + #address-cells = <1>; + #size-cells = <1>; + ranges; + + event_log: tcg_event_log { + no-map; + reg = <(CFG_SYS_SDRAM_SIZE - 0x2000) 0x2000>; + }; + }; + binman: binman { }; @@ -1365,6 +1377,7 @@ tpm2 { compatible = "sandbox,tpm2"; + memory-region = <&event_log>; }; tpm { diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 1ec44d5b33bb..85ef821296fb 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -344,3 +344,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 7349ce5aa60f..a90c52e8e204 100644 --- a/include/test/suites.h +++ b/include/test/suites.h @@ -44,6 +44,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 22ed61c8fa02..2dbb032a7e6f 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 obj-$(CONFIG_EXPO) += expo.o diff --git a/test/boot/measurement.c b/test/boot/measurement.c new file mode 100644 index 000000000000..9db2ed324c2a --- /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] = 0xf0 | (i & 0xf); + initrd[i] = (i & 0xf0) | 0xf; + images.ft_addr[i] = 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 d440da833a9c..56b8be347b69 100644 --- a/test/cmd_ut.c +++ b/test/cmd_ut.c @@ -96,6 +96,10 @@ static struct cmd_tbl cmd_ut_sub[] = { #if CONFIG_IS_ENABLED(UT_UNICODE) && !defined(API_BUILD) U_BOOT_CMD_MKENT(unicode, CONFIG_SYS_MAXARGS, 1, do_ut_unicode, "", ""), #endif +#ifdef CONFIG_MEASURED_BOOT + U_BOOT_CMD_MKENT(measurement, CONFIG_SYS_MAXARGS, 1, do_ut_measurement, + "", ""), +#endif #ifdef CONFIG_SANDBOX U_BOOT_CMD_MKENT(compression, CONFIG_SYS_MAXARGS, 1, do_ut_compression, "", ""),