From patchwork Thu Dec 28 18:49:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bryan O'Donoghue X-Patchwork-Id: 122866 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp3809710qgn; Thu, 28 Dec 2017 11:04:13 -0800 (PST) X-Google-Smtp-Source: ACJfBovIr1Wdslp005z3Cwtzil7Phn8z3xITITub0Vm8YIHCaCi1+G0uqUCXgDOaQMeYC3/nxrnc X-Received: by 10.80.211.18 with SMTP id g18mr42654752edh.279.1514487853391; Thu, 28 Dec 2017 11:04:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514487853; cv=none; d=google.com; s=arc-20160816; b=BrvIZ1haIL/mnmT3cbDWf5gMTuYdrx4IPlIDY5PXyMVxoRfQf7mNfF5Z7zowergeMe MKgpCLgbVI35JU4ybBslp382CHayf7JDQEu58yTdrJNuNwSeQ52Yakb6/CsRVpFd7p8h seRyhUtSVcfnjj23J4bMdp8OWlxf9hrjUmKBM9l6jgsSIZVqGogWnHgmcqhk9li4sdnO BJU5SwQqfzWbcUbKkHTX8GnInsuwyqgVay43THzqFS4CX2i7SZOyDYSNhvqCIOs/Gzry Vkw9oFd9p6cm1uF328kkmw48L9eFEqtNRBIciMOyBJ5FB2tv/1u25AMVv3bQ1q6MNla0 jLVg== 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=A6DwTfRPSiUzXqtgXzsWZpp3nihoECQ7yhUhZrQlyq8=; b=sXajcW8oIMMXKz95/s2Sofo7kltRiwNywmbZ4ow+bhiWpUvySAziB4HexTf2mx/h7Y 4EdqixGiXg38bcjQCYF23XedFj5697Ilh8Rh7lGGTrTBLIxoGDPdFDR+DsEuzRtoHe9+ /V9q1Gbi4TqrDgz9dafLUMLij42lYreAoxLShZbz0gnKA1RsTPR29YiR+LqhmWAdhl0T jsidBOf6Z/0whIRpjjkh+/PLYNAvKSLQS+ddNS9n65MPfRdOREvfM2+JpXIUT7ToDVf2 EoKKCGtWXenuup5LtC3xFSYxAoHpAwMlwMGCkz/6VKFXEtPxJJxp7h3tUvECr/9FA4lS CcMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=S12Z8B1H; 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 e11si3880681eda.52.2017.12.28.11.04.12; Thu, 28 Dec 2017 11:04:13 -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=S12Z8B1H; 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 D1159C21DE5; Thu, 28 Dec 2017 18:54:59 +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 22FD1C21E4D; Thu, 28 Dec 2017 18:51:03 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 30EE7C21DD9; Thu, 28 Dec 2017 18:50:00 +0000 (UTC) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by lists.denx.de (Postfix) with ESMTPS id A6068C21DCE for ; Thu, 28 Dec 2017 18:49:56 +0000 (UTC) Received: by mail-wm0-f66.google.com with SMTP id f21so1903098wmh.1 for ; Thu, 28 Dec 2017 10:49:56 -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=K8jGXjHJlQG52Itin0ehjRHo3P34kiVJ1OjHqtyqcC4=; b=S12Z8B1H8RSldiZc1GWT4XkmB00Ee/y6xPdCNMyASpZcINE+aRt/RyHsSBF4914T61 f1qNCKL1jiNgwpNy6eLKhniY/SZcblBIcDED4V1Idse+29VJysRJ4KDedoCBevgnnkgX h53p9bMG6o4NhgpKb1bJysU+u0jdSQROVeIT4= 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=K8jGXjHJlQG52Itin0ehjRHo3P34kiVJ1OjHqtyqcC4=; b=PjusafFsmAsfx0tC26nXqaIdK00MeiuSfo/bvjlA5TfIQ0rnE2J8Dr+L9Em/s2UUMw JWp7aMLTewZLpDKmtaSivfcIAQqzGiTTNMwjc1wUgp9VKlYYdlJTBoomtG8YDU0R/YlB g4j/V5TqMM9J7t0RNkjkKlhgdNS9wByK+NF6l2k/XFIBCxRAbvlwQi69OJfax2OKCEHv fzTKpX4uLekgYp0j+XcRnnCTVNzP9EdYn+vxr8LCw7N+6lQM8Pd7ixsnbI/U5xOxGNVV daUO1nz+NdK4/AwLj7Zc3CaWEOA8b7PCjeHj3InazjYK6m86jSDFFD+/SVsPwxue4I8j mNeQ== X-Gm-Message-State: AKGB3mLgldPljhwtm0bucbt8EmZT/JeLk/Ar4LwyC3Mvz/nb+3Pfgo9Z g1a1chq7sxIXKp7xUGlK32eNNnz1mDI= X-Received: by 10.80.193.129 with SMTP id m1mr42407302edf.207.1514486996045; Thu, 28 Dec 2017 10:49:56 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id x28sm35246579edd.0.2017.12.28.10.49.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Dec 2017 10:49:55 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, brenomatheus@gmail.com Date: Thu, 28 Dec 2017 18:49:29 +0000 Message-Id: <1514486982-19059-11-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514486982-19059-1-git-send-email-bryan.odonoghue@linaro.org> References: <1514486982-19059-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Fabio Estevam Subject: [U-Boot] [PATCH v2 10/23] 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 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