mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 6/6] bootm: Add verify mode "available"
Date: Tue, 10 May 2016 16:08:09 +0200	[thread overview]
Message-ID: <1462889289-24215-6-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1462889289-24215-1-git-send-email-s.hauer@pengutronix.de>

The verify "available" mode checks whatever is available in the
booted image, so when an image has a signature, it is checked and
must be correct and when an image is hashed, it is also checked
for correctness.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootm.c     |  1 +
 common/image-fit.c | 64 ++++++++++++++++++++++++++++++++++++++----------------
 include/boot.h     |  1 +
 3 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 53edc71..bf1b344 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -74,6 +74,7 @@ static const char * const bootm_verify_names[] = {
 #ifndef CONFIG_BOOTM_FORCE_SIGNED_IMAGES
 	[BOOTM_VERIFY_NONE] = "none",
 	[BOOTM_VERIFY_HASH] = "hash",
+	[BOOTM_VERIFY_AVAILABLE] = "available",
 #endif
 	[BOOTM_VERIFY_SIGNATURE] = "signature",
 };
diff --git a/common/image-fit.c b/common/image-fit.c
index ceb55c2..9b6c40f 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -428,7 +428,10 @@ static int fit_open_image(struct fit_handle *handle, const char *unit, const voi
 	}
 
 	if (handle->verify > BOOTM_VERIFY_NONE) {
-		ret = -EINVAL;
+		if (handle->verify == BOOTM_VERIFY_AVAILABLE)
+			ret = 0;
+		else
+			ret = -EINVAL;
 		for_each_child_of_node(image, hash) {
 			if (handle->verbose)
 				of_print_nodes(hash, 0);
@@ -449,9 +452,46 @@ static int fit_open_image(struct fit_handle *handle, const char *unit, const voi
 	return 0;
 }
 
+static int fit_config_verify_signature(struct fit_handle *handle, struct device_node *conf_node)
+{
+	struct device_node *sig_node;
+	int ret = -EINVAL;
+
+	if (!IS_ENABLED(CONFIG_FITIMAGE_SIGNATURE))
+		return 0;
+
+	switch (handle->verify) {
+	case BOOTM_VERIFY_NONE:
+	case BOOTM_VERIFY_HASH:
+		return 0;
+	case BOOTM_VERIFY_SIGNATURE:
+		ret = -EINVAL;
+		break;
+	case BOOTM_VERIFY_AVAILABLE:
+		ret = 0;
+		break;
+	}
+
+	for_each_child_of_node(conf_node, sig_node) {
+		if (handle->verbose)
+			of_print_nodes(sig_node, 0);
+		ret = fit_verify_signature(sig_node, handle->fit);
+		if (ret < 0)
+			return ret;
+	}
+
+	if (ret < 0) {
+		pr_err("configuration '%s' does not have a signature\n",
+		       conf_node->full_name);
+		return ret;
+	}
+
+	return ret;
+}
+
 static int fit_open_configuration(struct fit_handle *handle, const char *name)
 {
-	struct device_node *conf_node = NULL, *sig_node;
+	struct device_node *conf_node = NULL;
 	const char *unit, *desc = "(no description)";
 	int ret;
 
@@ -474,23 +514,9 @@ static int fit_open_configuration(struct fit_handle *handle, const char *name)
 	of_property_read_string(conf_node, "description", &desc);
 	pr_info("configuration '%s': %s\n", unit, desc);
 
-	if (IS_ENABLED(CONFIG_FITIMAGE_SIGNATURE) &&
-	    handle->verify == BOOTM_VERIFY_SIGNATURE) {
-		ret = -EINVAL;
-		for_each_child_of_node(conf_node, sig_node) {
-			if (handle->verbose)
-				of_print_nodes(sig_node, 0);
-			ret = fit_verify_signature(sig_node, handle->fit);
-			if (ret < 0)
-				return ret;
-		}
-
-		if (ret < 0) {
-			pr_err("configuration '%s': %s does not have a signature\n",
-			       unit, desc);
-			return ret;
-		}
-	}
+	ret = fit_config_verify_signature(handle, conf_node);
+	if (ret)
+		return ret;
 
 	if (of_property_read_string(conf_node, "kernel", &unit) == 0) {
 		ret = fit_open_image(handle, unit, &handle->kernel, &handle->kernel_size);
diff --git a/include/boot.h b/include/boot.h
index 2683d72..8e7a9f1 100644
--- a/include/boot.h
+++ b/include/boot.h
@@ -11,6 +11,7 @@ enum bootm_verify {
 	BOOTM_VERIFY_NONE,
 	BOOTM_VERIFY_HASH,
 	BOOTM_VERIFY_SIGNATURE,
+	BOOTM_VERIFY_AVAILABLE,
 };
 
 struct bootm_data {
-- 
2.8.0.rc3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2016-05-10 14:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-10 14:08 [PATCH 1/6] bootm: Move bootm options to common/Kconfig Sascha Hauer
2016-05-10 14:08 ` [PATCH 2/6] bootm: Add missing BOOTM_FORCE_SIGNED_IMAGES option Sascha Hauer
2016-05-10 14:08 ` [PATCH 3/6] bootm: fit: Print error when image is not hashed Sascha Hauer
2016-05-10 14:08 ` [PATCH 4/6] bootm: fit: Print error when image is not signed Sascha Hauer
2016-05-10 14:08 ` [PATCH 5/6] bootm: set bootm_verify_mode to correct value Sascha Hauer
2016-05-10 14:08 ` Sascha Hauer [this message]

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=1462889289-24215-6-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox