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 47E77C433EF for ; Fri, 25 Feb 2022 14:58:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BFF0C83C71; Fri, 25 Feb 2022 15:58:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=softathome.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=softathome1.onmicrosoft.com header.i=@softathome1.onmicrosoft.com header.b="IZJfUifi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A533B83C7A; Fri, 25 Feb 2022 15:58:05 +0100 (CET) Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-pr2fra01on061c.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e18::61c]) (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 EB2EA83381 for ; Fri, 25 Feb 2022 15:57:59 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=softathome.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=philippe.reynes@softathome.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QPUu1GQGR6RUY01SIHkEDWu2M8gfK9jPsjdVhfY2Ts1Vx9ShqC7hQCzRTPgrxSZHS0YW6CxXkr22j8jr6X9FWm11KhmsVYHqm546U3tyKWCDSMwZe5j5u/vxzk97j8hYt8TBS9NTMhDNQh9XOZVsmDBPySkkldVE/8Z1JvyBZ86+UsQ8nYzhq3py8Vw14kl+87Wq+qE+8NUW4ndfzjW4ZIpOiYXl3kdLsDs+kVh7S7LB9XxEUjqFxCSvX6Isr3ntnNCCnsG9VaIMev9LiUIyqZtgdzuooZJ6/4mWyIDMOGJn6KXNTT97o5YvKaswlFFh177ftrcRz+DyPvOABjZfxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=uGWnyAdAKbeeZJHTnwwc+zbG4zOkjbTQVMkzmBXSa7k=; b=RuJYiEkgMQU6gCPRepgvnWCPPCLulZeGDKmZQZgQlMs+C44KQvpwTeOm1d5IvoNMV5UxSVUsLQv2LgsEWS7GYU12bS2VsbnV+RKsKlhVnzS14xfuuKe3cImrfl+tGTiGgxIMDibNK1aTrh4smZ/2r1xGqHXe6toG4Uzy3V8DCzWnxsKof/K+dSa6rRizpCYB0u9KK9vcCyE6QRfLnwlu0Q1YZQRP567lnfRXc2HYW+bOrHN1BpCekV7Q6WrWiJwGZR0BqCVxzEkO4TW7FtladsJE2UYfJYnYoKWV1ykWGFkY8nDoBm04qN00cK7FJd9GdQdfZqWB9dRpvOlpt70KWw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.6.166.170) smtp.rcpttodomain=chromium.org smtp.mailfrom=softathome.com; dmarc=bestguesspass action=none header.from=softathome.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=softathome1.onmicrosoft.com; s=selector1-softathome1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=uGWnyAdAKbeeZJHTnwwc+zbG4zOkjbTQVMkzmBXSa7k=; b=IZJfUifiV7ddph4qa3R3iSpQ4fC9MSFC1kM+Id5JRDVCl2MoiJvcL6AEdK1W5eU2Pkt5ZE9RgFuyY9VeHZ6KJms3ya9LcQQWq3DPFS5EbEcdh0ORvLsL2DSo+3wQ3iPuMqSycTQNUUz/QrRXhw0wSKI0seAhjyAoyFXfD9WVTeIboMSx7huoOzDwnmD595Y/M2EQa7ksTVikkAOzcvIwKH57gMJddn/r8Jts5Y2kFMK3gFT+vApp2OMkUb62OwU/JY2bZlaU4PP+YMqI2RYYLhEN4gI1KQVyFSG9HiDjZARAacZyA6eMOXEAwW+N90h/iQKlWfV4IrW2Xyqmt9FkHQ== Received: from PR3PR09CA0020.eurprd09.prod.outlook.com (2603:10a6:102:b7::25) by PR1P264MB2232.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1b1::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.25; Fri, 25 Feb 2022 14:57:58 +0000 Received: from PR2FRA01FT012.eop-fra01.prod.protection.outlook.com (2603:10a6:102:b7:cafe::70) by PR3PR09CA0020.outlook.office365.com (2603:10a6:102:b7::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.24 via Frontend Transport; Fri, 25 Feb 2022 14:57:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.6.166.170) smtp.mailfrom=softathome.com; dkim=none (message not signed) header.d=none;dmarc=bestguesspass action=none header.from=softathome.com; Received-SPF: Pass (protection.outlook.com: domain of softathome.com designates 149.6.166.170 as permitted sender) receiver=protection.outlook.com; client-ip=149.6.166.170; helo=proxy.softathome.com; Received: from proxy.softathome.com (149.6.166.170) by PR2FRA01FT012.mail.protection.outlook.com (10.152.48.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22 via Frontend Transport; Fri, 25 Feb 2022 14:57:58 +0000 Received: from localhost.localdomain (unknown [192.168.72.32]) by proxy.softathome.com (Postfix) with ESMTPSA id BF0E01FF30; Fri, 25 Feb 2022 15:57:57 +0100 (CET) From: Philippe Reynes To: sjg@chromium.org, rasmus.villemoes@prevas.dk Cc: u-boot@lists.denx.de, Philippe Reynes Subject: [PATCH v6 00/16] image: add a stage pre-load Date: Fri, 25 Feb 2022 15:57:38 +0100 Message-Id: <20220225145754.30217-1-philippe.reynes@softathome.com> X-Mailer: git-send-email 2.17.1 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: c369987b-8fda-457f-ef9d-08d9f86f3600 X-MS-TrafficTypeDiagnostic: PR1P264MB2232:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HCzu+rTuQ68tau5DP2ISnN7Od2kf+TqqIOPewYF4X7lzkdTSuH1GXbi63BsS5cRNjs8ws17BBsmnaC4ZDpvj5UWShwVqWqY2fy1xbB2XvcgW/lDQsxnVnN4iSnGZkdF7muAwsFxDoGD9hH77htZcFH7pWfFIlwEwYloBV2RimM7JArTeNbfdNleqVT6KvtmQoigRbqPSh/r5pYn7hGzlCVKsFJkv1wulYnXRQzRY9wgw1iJD6MtDaAw7+13BaTO0383kbIJU3uk2aM0ZA6nvm88AtanGIDAhnugOjokQVf9A9pA+VP9zOP5NeywaSbkrid3pNuQQInr45b7VFvjj5cp9t7x86uTBiZv+Rm5aFjhbZk6sV94jAkYXkKJ2pXlxut5xMSO+VHDJhyF+Ylb3lApOZnWiaGkeWaI6pqQbacdEGoAdLMDsP8k4mGOUWbl8Owuqy6Gj5fj8+FVpIjkIvTST/6Im+KHMVJdbzmaWi9SZS4pDJ2Kp3U+h/3ulK7EIryW4V0QPeVVrDvLBcvaQt8a9NyNcMgexLxvRnAefTPyCdED5q4iOimETncv129qyeUEhitGzCU3CqQSsebmrRg/WFV0dTlDW9TXWLs+Qj9i+dtfzhSTWgHqu7LqsBkmXJrSNYNRgnM2DaXvmdgInuKpYKkKScLUV3iPQwfxKRdQrRuDCjLavheSnAFh9+J+WTvv//MCxZaGw/iPlViOU/w== X-Forefront-Antispam-Report: CIP:149.6.166.170; CTRY:FR; LANG:en; SCL:1; SRV:; IPV:CAL; SFV:NSPM; H:proxy.softathome.com; PTR:InfoDomainNonexistent; CAT:NONE; SFS:(13230001)(4636009)(36840700001)(40470700004)(46966006)(86362001)(8936002)(36860700001)(2906002)(81166007)(508600001)(47076005)(40460700003)(356005)(36756003)(44832011)(5660300002)(8676002)(83380400001)(6666004)(426003)(336012)(316002)(4326008)(6266002)(82310400004)(2616005)(26005)(6966003)(70206006)(70586007)(1076003)(107886003)(82960400001)(186003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: softathome.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Feb 2022 14:57:58.0256 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c369987b-8fda-457f-ef9d-08d9f86f3600 X-MS-Exchange-CrossTenant-Id: aa10e044-e405-4c10-8353-36b4d0cce511 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=aa10e044-e405-4c10-8353-36b4d0cce511; Ip=[149.6.166.170]; Helo=[proxy.softathome.com] X-MS-Exchange-CrossTenant-AuthSource: PR2FRA01FT012.eop-fra01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR1P264MB2232 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.5 at phobos.denx.de X-Virus-Status: Clean This serie adds a stage pre-load before launching an image. This stage is used to read a header before the image and this header contains the signature of the full image. So u-boot may check the full image before using any data of the image. The support of this header is added to binman, and a command verify checks the signature of a blob and set the u-boot env variable "loadaddr_verified" to the beginning of the "real" image. The support of this header is only added to binman, but it may also be added to mkimage. Changelog: v6: - set values in big endian in the pre-load header - binman: etypes: pre-load: read image from other entry instead of directly from a file - binman: etypes: pre-load: add test unit - lib: Makefile: no longer add -I$(obj) for SPL It was to fix build when oid is built on spl but not on u-boot. It is not longer possible. v5: - replace config SANDBOX_BINMAN by an imply v4: - add a config SANDBOX_BIN - enhance help for asn1 and oid - change the format of the pre-load header - add the support of pre-load header in binman - add py test for pre-load header - add a command verify v3: - move image-pre-load.c to /boot - update mkimage to add public key in u-boot device tree - add script gen_pre_load_header.sh v2: - move the code to image-pre-load - add support of stage pre-load for spl - add support of stage pre-load on spl_ram Philippe Reynes (16): arch: Kconfig: imply BINMAN for SANDBOX lib: Kconfig: enhance help for ASN1 lib: Kconfig: enhance the help of OID_REGISTRY lib: allow to build asn1 decoder and oid registry in SPL lib: crypto: allow to build crypyo in SPL lib: rsa: allow rsa verify with pkey in SPL boot: image: add a stage pre-load cmd: bootm: add a stage pre-load common: spl: fit_ram: allow to use image pre load mkimage: add public key for image pre-load stage Makefile: provide sah-key to binman tools: binman: add support for pre-load header configs: sandbox_defconfig: enable stage pre-load in bootm test: py: vboot: add test for global image signature cmd: verify: initial import configs: sandbox_defconfig: enable config CMD_VERIFY Makefile | 1 + arch/Kconfig | 1 + arch/sandbox/dts/sandbox.dtsi | 3 + arch/sandbox/dts/test.dts | 3 + boot/Kconfig | 55 +++ boot/Makefile | 1 + boot/bootm.c | 33 ++ boot/image-pre-load.c | 416 ++++++++++++++++++ cmd/Kconfig | 17 + cmd/Makefile | 1 + cmd/bootm.c | 2 +- cmd/verify.c | 53 +++ common/spl/spl_ram.c | 21 +- configs/sandbox_defconfig | 4 + include/image.h | 30 ++ lib/Kconfig | 37 +- lib/Makefile | 7 +- lib/crypto/Kconfig | 29 ++ lib/crypto/Makefile | 19 +- lib/rsa/Kconfig | 19 + test/py/tests/test_fit.py | 3 + test/py/tests/test_vboot.py | 125 +++++- test/py/tests/vboot/sandbox-binman-pss.dts | 25 ++ test/py/tests/vboot/sandbox-binman.dts | 24 + .../tests/vboot/sandbox-u-boot-global-pss.dts | 28 ++ test/py/tests/vboot/sandbox-u-boot-global.dts | 27 ++ test/py/tests/vboot/sandbox-u-boot.dts | 3 + test/py/tests/vboot/simple-images.its | 36 ++ tools/binman/etype/pre_load.py | 165 +++++++ tools/binman/ftest.py | 45 ++ tools/binman/test/225_dev.key | 28 ++ tools/binman/test/225_pre_load.dts | 22 + tools/binman/test/226_pre_load_pkcs.dts | 23 + tools/binman/test/227_pre_load_pss.dts | 23 + .../test/228_pre_load_invalid_padding.dts | 23 + .../binman/test/229_pre_load_invalid_sha.dts | 23 + .../binman/test/230_pre_load_invalid_algo.dts | 23 + .../binman/test/231_pre_load_invalid_key.dts | 23 + tools/fit_image.c | 3 + tools/image-host.c | 114 +++++ 40 files changed, 1510 insertions(+), 28 deletions(-) create mode 100644 boot/image-pre-load.c create mode 100644 cmd/verify.c create mode 100644 test/py/tests/vboot/sandbox-binman-pss.dts create mode 100644 test/py/tests/vboot/sandbox-binman.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global-pss.dts create mode 100644 test/py/tests/vboot/sandbox-u-boot-global.dts create mode 100644 test/py/tests/vboot/simple-images.its create mode 100644 tools/binman/etype/pre_load.py create mode 100644 tools/binman/test/225_dev.key create mode 100644 tools/binman/test/225_pre_load.dts create mode 100644 tools/binman/test/226_pre_load_pkcs.dts create mode 100644 tools/binman/test/227_pre_load_pss.dts create mode 100644 tools/binman/test/228_pre_load_invalid_padding.dts create mode 100644 tools/binman/test/229_pre_load_invalid_sha.dts create mode 100644 tools/binman/test/230_pre_load_invalid_algo.dts create mode 100644 tools/binman/test/231_pre_load_invalid_key.dts -- 2.17.1