All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philippe Reynes <philippe.reynes@softathome.com>
To: sjg@chromium.org, rasmus.villemoes@prevas.dk
Cc: u-boot@lists.denx.de, Philippe Reynes <philippe.reynes@softathome.com>
Subject: [PATCH v7 15/16] cmd: pre_load_verify: initial import
Date: Mon, 14 Mar 2022 15:57:44 +0100	[thread overview]
Message-ID: <20220314145745.15249-16-philippe.reynes@softathome.com> (raw)
In-Reply-To: <20220314145745.15249-1-philippe.reynes@softathome.com>

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 <philippe.reynes@softathome.com>
---
 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 <philippe.reynes@softathome.com>
+ */
+
+#include <common.h>
+#include <env.h>
+#include <image.h>
+#include <mapmem.h>
+
+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)"
+	   "<image addr>"
+);
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 <addr>
+
+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


  parent reply	other threads:[~2022-03-14 15:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-14 14:57 [PATCH v7 00/16] image: add a stage pre-load Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 01/16] arch: Kconfig: imply BINMAN for SANDBOX Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 02/16] lib: Kconfig: enhance help for ASN1 Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 03/16] lib: Kconfig: enhance the help of OID_REGISTRY Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 04/16] lib: allow to build asn1 decoder and oid registry in SPL Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 05/16] lib: crypto: allow to build crypyo " Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 06/16] lib: rsa: allow rsa verify with pkey " Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 07/16] boot: image: add a stage pre-load Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 08/16] cmd: bootm: " Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 09/16] common: spl: fit_ram: allow to use image pre load Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 10/16] mkimage: add public key for image pre-load stage Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 11/16] Makefile: provide sah-key to binman Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 12/16] tools: binman: add support for pre-load header Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 13/16] configs: sandbox_defconfig: enable stage pre-load in bootm Philippe Reynes
2022-03-14 14:57 ` [PATCH v7 14/16] test: py: vboot: add test for global image signature Philippe Reynes
2022-03-25 17:11   ` Tom Rini
2022-03-25 22:54     ` Philippe REYNES
2022-03-25 23:02       ` Tom Rini
2022-03-28 20:58         ` Philippe REYNES
2022-03-14 14:57 ` Philippe Reynes [this message]
2022-03-14 14:57 ` [PATCH v7 16/16] configs: sandbox_defconfig: enable config CMD_PRE_LOAD_VERIFY Philippe Reynes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220314145745.15249-16-philippe.reynes@softathome.com \
    --to=philippe.reynes@softathome.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.