From patchwork Wed Feb 9 18:01:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe REYNES X-Patchwork-Id: 1590663 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=softathome1.onmicrosoft.com header.i=@softathome1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-softathome1-onmicrosoft-com header.b=qGRIJJ/g; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Jv76z3ZzLz9sCD for ; Thu, 10 Feb 2022 05:04:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 12CF683F0D; Wed, 9 Feb 2022 19:02:42 +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="qGRIJJ/g"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2351683EC3; Wed, 9 Feb 2022 19:02:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from FRA01-MR2-obe.outbound.protection.outlook.com (mail-mr2fra01on061d.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e19::61d]) (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 6F54383EC5 for ; Wed, 9 Feb 2022 19:01:47 +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=KvdyY2bfoBWoDWLcsO9bQ2QGVCsKJl8vJCd4cjiKEhLYG4VXEZsx9TujUgF82SDLnxVRqI2+Ug4P1h2lZ6Qbsx73iJdbCJKf9pUwq+6wBzH2fT0EraKp4BEofn+nwrxumIRQ+21QweABxNzMAaa5ANiRfID6DfHVgmEDPWGjGe/NnZCpXlQilJ/Wij+34sQE2pOrnvYKDWuf1dXTJF/t8ntmfm7WXBpJgWWrl5/YgQMXvkhp0/5cx2PLFCBV9Nf6YpidD9M/ac5l/gPH5Dp6oKhHPqXMDyNovT933nZrArWqRTwGhvHqpk4PZhtrc3JMmvOK+rFvtpV8ndGTRWDIjg== 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=px6x9OCM03yjhg5xzmpcfBwg10D+CEqOZb7O/IK88ZQ=; b=ifkQ+qclUvVqVTMkddssvgOLuAynhPdxd5ZZfP5fE877EaCcl0oLHGYhFC1I1l656CUIU7WOniwfNuWqHUN1J/JgRYUqyOcl7VcF88Rq+Uyh+ejC1Y0O9aKMY+PVB/46OrRtAzx7sPrUZscczJJm15VZ6bSUl/wDsKpIbsWdV540jnX7TQNNPNP8Vh+XV06f1qunqnRXUlDVzXFwp2CrOhHLWvOVq5n5etkJuwC0qpzFmic1CsJhY+jQpHe6raH3R54FTGsyJpixO+TByV1XhLlPBJfGdUfT3BouUhErUydpdkRLW1AYS4nVAATFpxEYKLMTb7tZC3HQaU7ObyYvbg== 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=px6x9OCM03yjhg5xzmpcfBwg10D+CEqOZb7O/IK88ZQ=; b=qGRIJJ/gcSgpZcA47CLThMpoCODiGiO8+kIAgMfkgKmcJkCoT4o+IRSemAsQ6d4J3AdzOBQOc408opf5R2fpgAb+v4ZEFRSMS2umSn9HenHDf35TXX2tJPIoZ0TcvTX59Qu58yEC+KaZrzWEI9b303+l9oDu66EbNN0E2DtOkCzLVgGMHmDTzC3+8fAdQKpP7tDAcIYpCXOtRsrAreLy+p7HPLYDdHq97NaSmLFXdD5MUAjxdbKG0I3MVprLj+GTt6cOj0g8NBzjWWm5oSHoJgK2yAyEGvAarHUZ0L1TZzgzqWlCiTiohfXwfIYaVPa/bcC3erhuIdunL1hQHMf81w== Received: from PR2P264CA0037.FRAP264.PROD.OUTLOOK.COM (2603:10a6:101:1::25) by PR0P264MB2327.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:1e2::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Wed, 9 Feb 2022 18:01:45 +0000 Received: from MR2FRA01FT014.eop-fra01.prod.protection.outlook.com (2603:10a6:101:1:cafe::94) by PR2P264CA0037.outlook.office365.com (2603:10a6:101:1::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11 via Frontend Transport; Wed, 9 Feb 2022 18:01:45 +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 MR2FRA01FT014.mail.protection.outlook.com (10.152.50.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4975.11 via Frontend Transport; Wed, 9 Feb 2022 18:01:45 +0000 Received: from sah1lpt571.softathome.com (unknown [192.168.75.67]) by proxy.softathome.com (Postfix) with ESMTPSA id C8E88201F8; Wed, 9 Feb 2022 19:01:44 +0100 (CET) From: Philippe Reynes To: sjg@chromium.org, rasmus.villemoes@prevas.dk Cc: u-boot@lists.denx.de, Philippe Reynes Subject: [PATCH v5 15/16] cmd: verify: initial import Date: Wed, 9 Feb 2022 19:01:27 +0100 Message-Id: <20220209180128.10655-16-philippe.reynes@softathome.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220209180128.10655-1-philippe.reynes@softathome.com> References: <20220209180128.10655-1-philippe.reynes@softathome.com> X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 935bcb53-24dd-4947-35fd-08d9ebf63c58 X-MS-TrafficTypeDiagnostic: PR0P264MB2327:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OXEQm+IDAd806590HWepdjp+kzBNrZbafpqEVdxFIpSERySwDgdtql+c2EbQmzMIEujO/iaM0uAhpeXsK97LoNPjZN0kZtPQeIXtQCDc84kn/AZyrE5JxnL5P9bP2PhddcD+6SeygIVcS6AqIsPjUTy0CuSpJC8nKS7FjL7jVK+9ZTDdQdg723gN3PZJAz5vbYwBLaKaqW0tfLdzYDIuj9+AC52rZqkKOsuobC7+66MPewY1lXxKydPTEp0usENT9vqkkF1kxJRgYN8xRewWi8imr7g8lhJE5J4kUkIGT7bynrOtmDKjRoVUpKq1Gu9YCnskQaygFo13CTOYg5Psd7+ap07ZBswWSrGuls5hE7Yoe3dCKuCMgrgYD0V12KiiWU8/LN1GRGAKKjOSOwTLzW3kDqENJpGJ0bmSqJZfADGrVJ3RkBfr3LgrQuAsWnemLAFtfH3aBMwrw/gpgZBmjDTYAML47izrVY9hMr6aZazePOeEsU8tFpoLFTKlWi+iDNR6v0ErLr0banGlM+mBSozsoADdu3uhVgZMwRJnWeUarHJJC6Lb3Of7N7rQ2Neh/Obl6v3tNrlZ4stfU00Cu4ncBmQ6HwLPt/hwRO2X4wKYX/D6BTGbmwygY0Yf7G3HZ58LHpdv3bxAS4EnMMqUopurGkjWq7GRNATeoOh4x4exme3264NggpZ1iRjzRexJNHFcCvE6p8i9uRSngwQ4BQ== 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)(46966006)(40470700004)(36840700001)(70206006)(44832011)(4326008)(8936002)(316002)(15650500001)(86362001)(2906002)(8676002)(70586007)(36860700001)(5660300002)(83380400001)(82960400001)(508600001)(40460700003)(186003)(2616005)(81166007)(47076005)(26005)(36756003)(426003)(6266002)(7696005)(82310400004)(6666004)(356005)(1076003)(107886003)(336012)(6966003)(36900700001); DIR:OUT; SFP:1101; X-OriginatorOrg: softathome.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2022 18:01:45.5906 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 935bcb53-24dd-4947-35fd-08d9ebf63c58 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: MR2FRA01FT014.eop-fra01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PR0P264MB2327 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 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 && verify $loadaddr && source $loadaddr_verified Signed-off-by: Philippe Reynes --- cmd/Kconfig | 7 +++++++ cmd/Makefile | 1 + cmd/verify.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 cmd/verify.c diff --git a/cmd/Kconfig b/cmd/Kconfig index 87aa3fb11a..0460d5c3a0 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -428,6 +428,13 @@ 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_VERIFY + bool "verify the global signature" + depends on CMD_BOOTM_PRE_LOAD + help + Verify the signature provided in a pre-load header of + a full image. + config CMD_ZBOOT bool "zboot - x86 boot command" help diff --git a/cmd/Makefile b/cmd/Makefile index 166c652d98..80e054e806 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -177,6 +177,7 @@ obj-$(CONFIG_CMD_THOR_DOWNLOAD) += thordown.o obj-$(CONFIG_CMD_XIMG) += ximg.o obj-$(CONFIG_CMD_YAFFS2) += yaffs2.o obj-$(CONFIG_CMD_SPL) += spl.o +obj-$(CONFIG_CMD_VERIFY) += verify.o obj-$(CONFIG_CMD_W1) += w1.o obj-$(CONFIG_CMD_ZIP) += zip.o obj-$(CONFIG_CMD_ZFS) += zfs.o diff --git a/cmd/verify.c b/cmd/verify.c new file mode 100644 index 0000000000..4d055e0790 --- /dev/null +++ b/cmd/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 = simple_strtoul(argv[0], NULL, 16); + 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(CMD_BOOTM_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(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)", + "" +);