All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 10/25] arm: imx: hab: Add IVT header verification
Date: Tue,  2 Jan 2018 16:43:56 +0000	[thread overview]
Message-ID: <1514911451-4520-11-git-send-email-bryan.odonoghue@linaro.org> (raw)
In-Reply-To: <1514911451-4520-1-git-send-email-bryan.odonoghue@linaro.org>

The IVT header contains a magic number, fixed length and one of two version
identifiers. Validate these settings before doing anything with a putative
IVT binary.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Albert Aribaud <albert.u.boot@aribaud.net>
Cc: Sven Ebenfeld <sven.ebenfeld@gmail.com>
Cc: George McCollister <george.mccollister@gmail.com>
Cc: Breno Matheus Lima <brenomatheus@gmail.com>
---
 arch/arm/mach-imx/hab.c | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/hab.c b/arch/arm/mach-imx/hab.c
index 1d7b069..cb6214d 100644
--- a/arch/arm/mach-imx/hab.c
+++ b/arch/arm/mach-imx/hab.c
@@ -80,6 +80,31 @@
 
 static bool is_hab_enabled(void);
 
+static int ivt_header_error(const char *err_str, struct ivt_header *ivt_hdr)
+{
+	printf("%s magic=0x%x length=0x%02x version=0x%x\n", err_str,
+	       ivt_hdr->magic, ivt_hdr->length, ivt_hdr->version);
+
+	return 1;
+}
+
+static int verify_ivt_header(struct ivt_header *ivt_hdr)
+{
+	int result = 0;
+
+	if (ivt_hdr->magic != IVT_HEADER_MAGIC)
+		result = ivt_header_error("bad magic", ivt_hdr);
+
+	if (be16_to_cpu(ivt_hdr->length) != IVT_TOTAL_LENGTH)
+		result = ivt_header_error("bad length", ivt_hdr);
+
+	if (ivt_hdr->version != IVT_HEADER_V1 &&
+	    ivt_hdr->version != IVT_HEADER_V2)
+		result = ivt_header_error("bad version", ivt_hdr);
+
+	return result;
+}
+
 #if !defined(CONFIG_SPL_BUILD)
 
 #define MAX_RECORD_BYTES     (8*1024) /* 4 kbytes */
@@ -394,6 +419,8 @@ int authenticate_image(uint32_t ddr_start, uint32_t image_size,
 	hab_rvt_authenticate_image_t *hab_rvt_authenticate_image;
 	hab_rvt_entry_t *hab_rvt_entry;
 	hab_rvt_exit_t *hab_rvt_exit;
+	struct ivt *ivt;
+	struct ivt_header *ivt_hdr;
 
 	hab_rvt_authenticate_image = hab_rvt_authenticate_image_p;
 	hab_rvt_entry = hab_rvt_entry_p;
@@ -416,6 +443,13 @@ int authenticate_image(uint32_t ddr_start, uint32_t image_size,
 
 	/* Calculate IVT address header */
 	ivt_addr = ddr_start + ivt_offset;
+	ivt = (struct ivt *)ivt_addr;
+	ivt_hdr = &ivt->hdr;
+
+	/* Verify IVT header bugging out on error */
+	if (verify_ivt_header(ivt_hdr))
+		goto hab_caam_clock_disable;
+
 	start = ddr_start;
 	bytes = image_size;
 #ifdef DEBUG
@@ -435,8 +469,6 @@ int authenticate_image(uint32_t ddr_start, uint32_t image_size,
 	printf("\tivt_offset = 0x%x\n", ivt_offset);
 	printf("\tstart = 0x%08lx\n", start);
 	printf("\tbytes = 0x%x\n", bytes);
-#else
-	(void)ivt_addr;
 #endif
 	/*
 	 * If the MMU is enabled, we have to notify the ROM
-- 
2.7.4

  parent reply	other threads:[~2018-01-02 16:43 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-02 16:43 [U-Boot] [PATCH v4 00/25] Fix and extend i.MX HAB layer Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 01/25] arm: imx: hab: Make authenticate_image return int Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 02/25] arm: imx: hab: Fix authenticate_image result code Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 03/25] arm: imx: hab: Optimise flow of authenticate_image on is_enabled fail Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 04/25] arm: imx: hab: Optimise flow of authenticate_image on hab_entry fail Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 05/25] arm: imx: hab: Move IVT_SIZE to hab.h Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 06/25] arm: imx: hab: Move CSF_PAD_SIZE " Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 07/25] arm: imx: hab: Fix authenticate_image input parameters Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 08/25] arm: imx: hab: Fix authenticate image lockup on MX7 Bryan O'Donoghue
2018-01-03  1:25   ` Breno Matheus Lima
2018-01-03 19:37     ` Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 09/25] arm: imx: hab: Add IVT header definitions Bryan O'Donoghue
2018-01-02 16:43 ` Bryan O'Donoghue [this message]
2018-01-02 16:43 ` [U-Boot] [PATCH v4 11/25] arm: imx: hab: Verify IVT self matches calculated address Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 12/25] arm: imx: hab: Only call ROM once headers are verified Bryan O'Donoghue
2018-01-02 16:43 ` [U-Boot] [PATCH v4 13/25] arm: imx: hab: Print CSF based on IVT descriptor Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 14/25] arm: imx: hab: Print additional IVT elements during debug Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 15/25] arm: imx: hab: Define rvt_check_target() Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 16/25] arm: imx: hab: Implement hab_rvt_check_target Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 17/25] arm: imx: hab: Add a hab_rvt_check_target to image auth Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 18/25] arm: imx: hab: Print HAB event log only after calling ROM Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 19/25] arm: imx: hab: Make internal functions and data static Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 20/25] arm: imx: hab: Prefix authenticate_image with imx_hab Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 21/25] arm: imx: hab: Rename is_hab_enabled imx_hab_is_enabled Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 22/25] arm: imx: hab: Make imx_hab_is_enabled global Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 23/25] arm: imx: hab: Define rvt_failsafe() Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 24/25] arm: imx: hab: Implement hab_rvt_failsafe Bryan O'Donoghue
2018-01-02 16:44 ` [U-Boot] [PATCH v4 25/25] arm: imx: hab: Add hab_failsafe console command Bryan O'Donoghue

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=1514911451-4520-11-git-send-email-bryan.odonoghue@linaro.org \
    --to=bryan.odonoghue@linaro.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.