From patchwork Mon Jan 8 17:36:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 123772 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3013278qgn; Mon, 8 Jan 2018 09:44:33 -0800 (PST) X-Google-Smtp-Source: ACJfBosPf7vKd00FzdM3R7yWt7CEXOuhIGsEhzb8jww0D3PYmdEfmeZKxMqnzVW9LGSS/aAjAVSk X-Received: by 10.80.149.180 with SMTP id w49mr17582580eda.255.1515433473543; Mon, 08 Jan 2018 09:44:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515433473; cv=none; d=google.com; s=arc-20160816; b=xFxGgBjbIKcPlRrQJW4LYTX64nh9KWhz+MX+i8nhmz8X4ozjfE7fTzc7zY8RJs9kP+ ih0SVgD6Ol5h8Js1DTdSEVEaxMN1MoiP/BKaEMeFsAMf2uhecIbYo6A+tPD4uwGndXCB mgURt3zjXQX58ZC1HmbyTk+/yKqgucyARomtBBqJohbCUNHuMwEwoYWsYl8XwZ65rHe3 wHRbQ4QZ4U8GA2+FqTY0eBRTjfjaroattXRZ3fsGM0b3+BmqM45gg5LqFxWHK6JDlECT g81Og1c8a/RdnTXpCkUMGocuFYtFXkS+c7nIS6qxezgd3GR31mp89Lyh64y8xg6maar1 JeIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=wtBLTlfoJBvhf/eOuuvxQm98vTWQo0EbMS443rcgN7o=; b=u1ypsgjClMRZ8UnNVixoosZPzAmBgA6xY3lpC0ldnUnRFdkHR5/Oio3Lm1sC/FuO/R jrF0Ct0fNMQwOVuUQ6pylDRb4Pu1kc0ZcXoCGvc8erZXWxkKdvvovsDQLIEV9FHDn5Tn HYFQsJGvqIdpB5gs2CciK8LZEcR3ghL9HpPp1IC6ni6k8sE7ofukup07euIH4X8Zrbn6 GLwRlNbsHUxJToJWkAmRAtv4NZNQv7L7ThxB+krccWSg2kJ/NinIarj6Uhm3vRqWLdPb EHUiRtRTFdsO0rrY2lP6wG9gt1G6GPKEq+akVN/dkG1yVKk3SfpvCpXEP7AFhmZHSyKP GZBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=f+gzlwCM; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id m33si4585012ede.418.2018.01.08.09.44.33; Mon, 08 Jan 2018 09:44:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=f+gzlwCM; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 27E74C21F67; Mon, 8 Jan 2018 17:39:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 5F3D7C21F84; Mon, 8 Jan 2018 17:37:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7A70AC21FB1; Mon, 8 Jan 2018 17:37:01 +0000 (UTC) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by lists.denx.de (Postfix) with ESMTPS id 0FC48C21F8F for ; Mon, 8 Jan 2018 17:36:57 +0000 (UTC) Received: by mail-wm0-f65.google.com with SMTP id f140so15701447wmd.2 for ; Mon, 08 Jan 2018 09:36:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=R5DGvu8umvQQ/Yfvy/bdkA5glsJAQteZ8b5bHF8jCQ0=; b=f+gzlwCMC7oO7FXpOw2tXP9KkN4lipyhk2n3PvR9J3Xl8LTZGbwBr6b8s9VuAvjiu5 j3UtOChTyel9neItbWDPTehbhDFvFygcQ4umdWHgCgvF1CpMJCPvlnsN5aleyAhoSza+ WRlxGM89brYIrRos+2fMJYLwm1Pyz/J7RCBHs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=R5DGvu8umvQQ/Yfvy/bdkA5glsJAQteZ8b5bHF8jCQ0=; b=U+LEmQGHhAy+eNnOM5Cwyk6UFAkIOmAiF3FXz42O9Ig/P8AvHL50CzpNm87q5f9+1R ZxM9dUxJKoH6kFl8OabOEW9qJ8cdae2RoPp6eAW0pbY0tGu/OFAXAvYAgD4GP33U7/aR vsR8ZPb2n7wZnYvUWVHPGOEE/GcTi7Eys0SV7VuboXl8pdPYFA20Plqom2abuo4BxzyQ H2Mx9MyH8nCBqlSJXQo95dsa+LlCxeglNKC+7ympZcyGLT214Gi+IGYEhwWQwyyHxzeb BoGJZfArvciR9rXQX9+C4M5Hf+/ciNFvtiObK+oYgZ3Pqo4UAGjtcnAOJ2ENpcFV5yOm nwMw== X-Gm-Message-State: AKGB3mKh+bJYLIMcFdKANlfU5qxx7yZbSqWTiIwtqoChDO/s2SY2e7eP vOWVWerkZ4tXKM+6fi/7I2VIIYYbAdA= X-Received: by 10.80.182.229 with SMTP id f34mr17601774ede.150.1515433016439; Mon, 08 Jan 2018 09:36:56 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id a38sm7160033edf.3.2018.01.08.09.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Jan 2018 09:36:55 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, brenomatheus@gmail.com Date: Mon, 8 Jan 2018 17:36:26 +0000 Message-Id: <1515433001-13857-10-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515433001-13857-1-git-send-email-bryan.odonoghue@linaro.org> References: <1515433001-13857-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Fabio Estevam Subject: [U-Boot] [PATCH v5 09/24] arm: imx: hab: Add IVT header verification X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 Cc: Stefano Babic Cc: Fabio Estevam Cc: Peng Fan Cc: Albert Aribaud Cc: Sven Ebenfeld Cc: George McCollister Cc: Breno Matheus Lima --- 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 2a40d06..998d253 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