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 6F4A1C433EF for ; Mon, 14 Mar 2022 14:58:17 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F1BB883BBF; Mon, 14 Mar 2022 15:58:13 +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="GaWWZG0w"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C3F2083BAF; Mon, 14 Mar 2022 15:58:09 +0100 (CET) Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-pr2fra01on060a.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e18::60a]) (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 CBB56830AF for ; Mon, 14 Mar 2022 15:58:02 +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=MV0DM8bQHXFIGN36/0CKJloOZH3C+gmLEx42D7ifGUn2zXSg0n/puZN1qvDoFaGpyze/rWImafopEy/kRYWxdILC3JpEFvG+Py0vaBHb+8AN++GL9G4AgcEeymsTIPwy1i+5neuXpzoAvrvvGzKRzNuVjLxuPmh6H3RSBxa1qtw84YBrSfhRYJ2S66ER0mqjAn3+AK1DDAOfLVO4PW2I78Ee9p3pshxRFkBR8DV+4kS143WPYCf3oAd7H8PUA423xfnfB3qLI9QieI9atvMJ6n16Ot2CLuu/U5wmcrMr4Dw6zi3LzlS8GU5jQikHZHYUVpXyhUTpMcAxyq2YkhVp0g== 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=ZtvCMM7MQSy3q210tVX+1KxCTV6FYnZn/70rKmHaTdM=; b=DYOF6++RX6e5PYFVh57SR9a6vCKlsytp+adou+EhbKWfny5P5pA1hTvts44zvJv736lKSqy8iIkjpwT5bqCxu35A7iVfcUZl7SAIvfnnT0c8l0CTCMlUjOkoTT02+Z4PPHzkS4buOb1xfHEPSToLzxZ+xIJoIB//tHvQuUMclDk3bx2QbGWrQkurWiT8mFkrvclFdkLB3AKbk97s5Pk9Mb6aZINrD3dUUHWaCg5hrdCanvP00UCSUkSegyA1jl9ItzD5GVUZyWwbOhOqlGNa8ejYtBHhtOJId/HCb1GuwThJ7KoH+awrI95DzCHePL5YqIrUMJfbZHYetQdNLDqO8A== 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=ZtvCMM7MQSy3q210tVX+1KxCTV6FYnZn/70rKmHaTdM=; b=GaWWZG0wtSHxDCI+I+wr1VVqPYsDqxi5aoIfoGPFl1a8XqTquUm7dlbHomUYHIEvqK6/YBJZEJ/zKXm/d7u5YKIXplzPYM8ran1ugKAYp2EiRNpkkqiuXiVHbDADx8vBUDUQjZxtCgVlyyQmQFVDP2U2kNNYczRSWgW7SaRCUiTkank8fvTQJIiJxIf+OvvuMeCg43Qg0QiXuRib+DRZmagdRVyvKQdWMm6U4AZa2JwV59RGyKlbCxPEQg4L+zFfVZW/91GrspgDZeL6ZDChkSiKTFs+YZBXdCcF3StSHP5gDPrWmkN8nU2HsVwIYmh2ATg9xCZPfDZIzOk06Xdy7w== Received: from AS9PR06CA0315.eurprd06.prod.outlook.com (2603:10a6:20b:45b::26) by MRZP264MB1797.FRAP264.PROD.OUTLOOK.COM (2603:10a6:501:9::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Mon, 14 Mar 2022 14:58:01 +0000 Received: from PR2FRA01FT015.eop-fra01.prod.protection.outlook.com (2603:10a6:20b:45b:cafe::51) by AS9PR06CA0315.outlook.office365.com (2603:10a6:20b:45b::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.20 via Frontend Transport; Mon, 14 Mar 2022 14:58:01 +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 PR2FRA01FT015.mail.protection.outlook.com (10.152.48.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22 via Frontend Transport; Mon, 14 Mar 2022 14:58:00 +0000 Received: from localhost.localdomain (unknown [192.168.72.32]) by proxy.softathome.com (Postfix) with ESMTPSA id 7F12520014; Mon, 14 Mar 2022 15:58:00 +0100 (CET) From: Philippe Reynes To: sjg@chromium.org, rasmus.villemoes@prevas.dk Cc: u-boot@lists.denx.de, Philippe Reynes Subject: [PATCH v7 00/16] image: add a stage pre-load Date: Mon, 14 Mar 2022 15:57:29 +0100 Message-Id: <20220314145745.15249-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: 4c5757bf-7866-4d5d-fd57-08da05cb0896 X-MS-TrafficTypeDiagnostic: MRZP264MB1797: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: 4q+kpkuB61KmWM6/5UHklB+OwvU7fmcTsX7XKVmpaCKi3Tc6JLtzcyeD8j7oB8z4GegamjuuIssK5EYGUYikP3jGpkpHHylUmGTIJjqT183YXfgEVuvMRcX4OlmL1ByfN6l3qzcTV7An9lLnPOAK1kECF1IbLEBpbbOqjNkG6GxHVFqhAZf0b1L3C5Fm/UNf8OwQjSu4hA1pJFXApdeB5C0ZG98b+ihdx7xcKXjH9xgJcniLqDjDoe8clpSWHpdY+Su4JUIZOPTojTbV+OUz627hTte5XJSDCDnj7mRJJ/yEkbGKCWnt/yLZd0hJzT1kiOjX4mxO7JwXr4d0xHGysZCqhJ0XOjpJXF+OZqN8RJEHqA+x363r/o3YyS/kp7i81exP91B7X3JC5c3DbnwXQm3TjAoFO97Q5fhaxpxGCqK88WYQuN60lBGBuj5r8q+bnyzh99/yYTpv6SW1VolVk5b5ydHHOy1QQh5FmTV8A7TCC4kbOFvQf2vIPoeMXy3FvifEcmvtWDRUgN/huwaNJZN1g6QKi6jL4oL+x8lqbFtHCrL4sMikMPO4Plq3+0GH3Cmj8wsGDdgmqFllvQ/GfkDitlDJTiCwrV3y67QJJwYldMfyrK3PnIpu2VmVKRzSg7h7WxQNmU8BlswG0W7g14u0XPYkKYnYSN7QJOsblxdMey1+c8+G1gamMTJgjvhdfXOKr4vqmxKN3lhb6zxK0g== 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)(40470700004)(36840700001)(46966006)(83380400001)(44832011)(36756003)(6266002)(107886003)(2616005)(2906002)(8676002)(4326008)(70586007)(70206006)(426003)(336012)(186003)(26005)(6666004)(8936002)(47076005)(36860700001)(1076003)(498600001)(82960400001)(82310400004)(86362001)(6966003)(5660300002)(40460700003)(81166007)(356005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: softathome.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2022 14:58:00.6490 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4c5757bf-7866-4d5d-fd57-08da05cb0896 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: PR2FRA01FT015.eop-fra01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MRZP264MB1797 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: v7: - rename command verify to pre_load_verify - add usage doc for command pre_load_verify - some cleanup in support of pre-load in binman - rename variable key-path to pre-load-key-path - some cleanup in test vboot for pre-load 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: pre_load_verify: initial import configs: sandbox_defconfig: enable config CMD_PRE_LOAD_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 | 18 + cmd/Makefile | 2 + cmd/bootm.c | 2 +- cmd/pre-load-verify.c | 53 +++ common/spl/spl_ram.c | 21 +- configs/sandbox_defconfig | 4 + doc/usage/index.rst | 1 + doc/usage/pre-load-verify.rst | 44 ++ 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 | 145 +++++- 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/entries.rst | 38 ++ tools/binman/etype/pre_load.py | 162 +++++++ tools/binman/ftest.py | 51 +++ 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 +++++ 43 files changed, 1618 insertions(+), 28 deletions(-) create mode 100644 boot/image-pre-load.c create mode 100644 cmd/pre-load-verify.c create mode 100644 doc/usage/pre-load-verify.rst 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