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 90AF3C433F5 for ; Mon, 14 Mar 2022 15:01:26 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8905283C0D; Mon, 14 Mar 2022 16:01:24 +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="G2SvJYs6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 470EE83B00; Mon, 14 Mar 2022 15:58:47 +0100 (CET) Received: from FRA01-PR2-obe.outbound.protection.outlook.com (mail-pr2fra01on0619.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e18::619]) (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 EDB5583BC0 for ; Mon, 14 Mar 2022 15:58:04 +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=Qu+ndcS2pXFanQU7F8ctUth9up9KFbAfwjVDgQ3inFVIknRnKr1winJs9p0lc95M8viq2KHP4y0E74hEgyOSodL6R701UYBq5Kn8rUvXnGPb+I1kh2Bv19qEGZa7Eblgt/ISsnperb39VxdLwBSuAi3Q7wJbnkGBhlK6ME6HzKZn6dbkZss5FoeKlfPrjmUju8x0TICP9CNCivdA65kAZSaItvgirECLtimq7Hlgh50sFgERCAlqhHEpNcOFYpLc5Lf6OYCADXbecd29Jq4IQZCYCmcgiSV8AlHBmb0RPlKvof/X2u9vkZc+40DSDeYR4HnipWkZWyFO3Mcy8ymKNg== 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=9cKcAYpD6Ma+weISJPQmTqZzMabmWedbgpP5AFj0bLw=; b=iGSc8hFmpGlO37V5q4qcgQ1oX86QxAa3z7iuXAwiOauDVReK8tjXAmobU6L/sqQRvn6ees6hTpm6vm5u8bGLMVEqohCgW9gPUiomXrsl+j9VJTGOU2JkdJeW8VaWeibwNGzc0ftl4HZG9CixnPt49xYoMW6QCe5vSXpgHFkorEajDC7s9orq1poBbKW6JlWwOZ4Pe8HkkPDXmGEHe5aRmd9Wma7pb1c6shYok+gzjOXABlt+xugiAqdg1HZDSahejOAIgmMO98rSXqEvi1IV2930NOOdtJ8wAkOeyD67GeI1tyVgNFQ1WC/Yf0PMUcJSaZ43d2CYp6ZloqCPyc69zg== 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=9cKcAYpD6Ma+weISJPQmTqZzMabmWedbgpP5AFj0bLw=; b=G2SvJYs6ZQhw80unhAMVj3sooEQzTtj8hr9mlgyaFVQI6zRP5iwvnhMUGKVSsEWJz4eq3GLX1agmlVYBvzUuSHBc0qLsQ4s8ojRxaYueSZLrMHjkz8UhZ788kUgtn4oHL0WRugvNtZDHKR1Dz7U2MLD3ByCyBmwexOymQsq3Id0EKFFkrIlQibAgZpG4cfYpJjkxaNUez+iyyQQ7zPbk0oeXYdzNWfO+8sVb+KgqUHTqEHTU+xCHJtr0EiadWN9awPsN9YApKu6g+7mZXsSNxe9/UfXJyJwVarjKPZBVsgh3ehes7h83lb1iGqYz8Bq0h6Ax+cp4Bfy3xLDOQSCCZw== Received: from AS9PR06CA0146.eurprd06.prod.outlook.com (2603:10a6:20b:467::9) by MRXP264MB0248.FRAP264.PROD.OUTLOOK.COM (2603:10a6:500:20::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.26; Mon, 14 Mar 2022 14:58:02 +0000 Received: from PR2FRA01FT016.eop-fra01.prod.protection.outlook.com (2603:10a6:20b:467:cafe::a3) by AS9PR06CA0146.outlook.office365.com (2603:10a6:20b:467::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.25 via Frontend Transport; Mon, 14 Mar 2022 14:58:02 +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 PR2FRA01FT016.mail.protection.outlook.com (10.152.48.109) 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:02 +0000 Received: from localhost.localdomain (unknown [192.168.72.32]) by proxy.softathome.com (Postfix) with ESMTPSA id F0A4B20065; Mon, 14 Mar 2022 15:58:01 +0100 (CET) From: Philippe Reynes To: sjg@chromium.org, rasmus.villemoes@prevas.dk Cc: u-boot@lists.denx.de, Philippe Reynes Subject: [PATCH v7 15/16] cmd: pre_load_verify: initial import Date: Mon, 14 Mar 2022 15:57:44 +0100 Message-Id: <20220314145745.15249-16-philippe.reynes@softathome.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220314145745.15249-1-philippe.reynes@softathome.com> References: <20220314145745.15249-1-philippe.reynes@softathome.com> X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 1992805f-ffb7-4e47-71ba-08da05cb0977 X-MS-TrafficTypeDiagnostic: MRXP264MB0248: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: KbW/vcdfqIJR2VKJGhkgor+/KKYOCgxM/GMasw7/Kqg0LeQgY1AosZ7rsiT5VskDwxtYgkC8pC9QUaHEJqjUGkEjQ7mDapIcHXFmqxZpUSmU7bY2G37hkjX27CfxFb86OZubiAAIOg2v2Cu7ypGkl9eM9v7YCNpvIxkMpDlLOkdEkqoVW6joZ1/yo0rVYuLOnkXxFD7QtS0gfHAjA4QXlF0q/jRoBLLQMDkzVawulNd5XErLQcYKOTFy9/iMTCJbp7VPtn/J17ICvJt1eptHDSadRjUTAM1jXEIOtGZ4n2lQMOsz0bdReMa4jOOBw9FY8KRnrj9R8Onh0JX4fhhCymfH6tDC1xHpcn0PIhLcJjC/cPgX75oCyBGynwhVtr3uoyxlOv4L+bePVBQ708suzJGz709Ip2L1oeK7wWglLGyDmf1mNqoHdnbfirpTces2pB+Y9PhJEbOAR8DQKuvI399h77WVlYBiDPMj4VVTzld/yKPE0vOWZoQiaZA7VPegKSmCts5k8C8y7w9Jr6Hy/d3ySUYQ7mBaaJVE2Aqgcfo9Of/hqK2tXL5FHE0z/2UCHWzGmRY5wikqXAZhoZK73gabcm6y4az7RshRZH8oie6nPNTsI3KMnsihPeRKUFdySYO6Ij2ej+HiiSihcGmhZtSav7ac5g6eBgx8Qn+U0keQ58/HNKJg0XLWhI+n2CF/bNJffXnHfoRTnLL+u5NH6g== 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)(336012)(426003)(6966003)(498600001)(40460700003)(356005)(44832011)(26005)(81166007)(83380400001)(36756003)(6266002)(186003)(8676002)(47076005)(36860700001)(6666004)(107886003)(1076003)(8936002)(4326008)(2906002)(5660300002)(70206006)(70586007)(86362001)(82960400001)(82310400004)(2616005)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: softathome.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Mar 2022 14:58:02.1200 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1992805f-ffb7-4e47-71ba-08da05cb0977 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: PR2FRA01FT016.eop-fra01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MRXP264MB0248 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 Add the command pre_load_verify that check the signature of an image with the pre-load header. If the check succeed, the u-boot env variable 'loadaddr_verified' is set to the address of the image (without the header). It allows to run such commands: tftp script.img && pre_load_verify $loadaddr && source $loadaddr_verified Signed-off-by: Philippe Reynes --- cmd/Kconfig | 8 ++++++ cmd/Makefile | 2 ++ cmd/pre-load-verify.c | 53 +++++++++++++++++++++++++++++++++++ doc/usage/pre-load-verify.rst | 44 +++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 cmd/pre-load-verify.c create mode 100644 doc/usage/pre-load-verify.rst diff --git a/cmd/Kconfig b/cmd/Kconfig index 87aa3fb11a..9b235210e3 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -428,6 +428,14 @@ config CMD_THOR_DOWNLOAD There is no documentation about this within the U-Boot source code but you should be able to find something on the interwebs. +config CMD_PRE_LOAD_VERIFY + bool "verify the global signature" + depends on IMAGE_PRE_LOAD + help + Verify the signature provided in a pre-load header of + a full image. + Documentation is available in doc/usage/pre-load-verify.txt + config CMD_ZBOOT bool "zboot - x86 boot command" help diff --git a/cmd/Makefile b/cmd/Makefile index 166c652d98..29ee9b8fab 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -188,6 +188,8 @@ obj-$(CONFIG_CMD_ETHSW) += ethsw.o obj-$(CONFIG_CMD_AXI) += axi.o obj-$(CONFIG_CMD_PVBLOCK) += pvblock.o +obj-$(CONFIG_CMD_PRE_LOAD_VERIFY) += pre-load-verify.o + # Power obj-$(CONFIG_CMD_PMIC) += pmic.o obj-$(CONFIG_CMD_REGULATOR) += regulator.o diff --git a/cmd/pre-load-verify.c b/cmd/pre-load-verify.c new file mode 100644 index 0000000000..c2c4e57d5f --- /dev/null +++ b/cmd/pre-load-verify.c @@ -0,0 +1,53 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2022 Philippe Reynes + */ + +#include +#include +#include +#include + +static ulong verify_get_addr(int argc, char *const argv[]) +{ + ulong addr; + + if (argc > 0) + addr = hextoul(argv[0], NULL); + else + addr = image_load_addr; + + return addr; +} + +static int do_verify(struct cmd_tbl *cmdtp, int flag, int argc, + char *const argv[]) +{ + ulong addr = verify_get_addr(argc, argv); + int ret = 0; + + argc--; argv++; + + addr = verify_get_addr(argc, argv); + + if (CONFIG_IS_ENABLED(IMAGE_PRE_LOAD)) { + ret = image_pre_load(addr); + + if (ret) { + ret = CMD_RET_FAILURE; + goto out; + } + + env_set_hex("loadaddr_verified", addr + image_load_offset); + } + + out: + return ret; +} + +U_BOOT_CMD(pre_load_verify, 2, 1, do_verify, + "verify the global signature provided in the pre-load header,\n", + "\tif the check succeed, the u-boot env variable loadaddr_verified\n" + "\tis set to the address of the image (without the header)" + "" +); diff --git a/doc/usage/pre-load-verify.rst b/doc/usage/pre-load-verify.rst new file mode 100644 index 0000000000..7b833d079b --- /dev/null +++ b/doc/usage/pre-load-verify.rst @@ -0,0 +1,44 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +pre-load-verify command +======================= + +Synopsis +-------- + +:: + + pre_load_verify + +Description +----------- + +The pre-load-verify command verify the signature of the binary at address addr +using the pre-load header that should be at the beginning of the binary. + +addr + Address of the binary to verify + + +Examples +-------- + + +:: + + => pre_load_verify 100 + INFO: signature check has succeed + +If succeed, the u-boot env variable loadaddr_verified is set to the address +if the binary after the pre-load header + +:: + + => printenv loadaddr_verified + loadaddr_verified=1100 + + +Return value +------------ + +The return value $? is 0 is the signature check succeed, 1 otherwise -- 2.17.1