From patchwork Fri Jan 12 12:40:03 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: 124315 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp2016699qgn; Fri, 12 Jan 2018 04:44:56 -0800 (PST) X-Google-Smtp-Source: ACJfBouH2UHyozuZ483Nd0dTPXij1zrbYkYg1kM5mwiBLmFr4zJ/H7JR/LoaRy4cpFItdBHLvv8m X-Received: by 10.80.164.169 with SMTP id w38mr35096559edb.154.1515761096645; Fri, 12 Jan 2018 04:44:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515761096; cv=none; d=google.com; s=arc-20160816; b=NheddUarE61WHRj1+5zgbLTV4+lR+0yEIbHJPouslqgU68AnyvsmdyOmLhQvHArziT wCaBKpP95MOPP/I7dCfghrunhmBvmW9OZHxVMGOmfYGPh8DSLF0ugM/XMPfJDyCdos8f F6N+aFc0UO5QLC13EC0jN6e6uQefEzox72pUi2S9eODyBfKzpkY3d6Je4lsCq8nhlYD4 k2ET3WF5T+XKaj/v1H/TW4b2w4/ZQi4oR0MHigqJcygqok35g34qgt4euUS9Has6fFc6 iyXhijmyw/JkcIA3DutnZQRpVDyeioBUcrjD7somqBLhzHJcBNWf9EyLCYlQZ4K+6xJY azrA== 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=fj6n6JypHd4gIQwyknYnLkHHKtfweMk1BvW5cSKvc14=; b=aYqy+EYOJouXyTXBtc+DDuvTYEB5BI9Wv8d+yg1+jSbcBA9GdDpf/blXo8lWLuzi2n UT+4w+GqUe36m6t/PaxE2J/2PzZlufmGBJc5jMc0SOAxtrt+bOfEeBZvXGf602ptTj0j sIBpmJ2e/rJ4ZUMdNQy1xQKsV9qgOFjQSZ3prflnN8jo6Ktb6BNxbm2eC2dwlWK7NrER os1NSi4FW9koa+b+0hKlXrHGtqunPC2r3bQKIG3KSE9GYl3KcRTi5rNus3i2E974uGgC ZQNlC714grNJKYGyU2+CERxevwiJ39+MipCcyRsN5vHGUIVA5UMrEbifFTtD0XqvDoyK kScQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jA4EctAO; 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 p1si8629653edl.305.2018.01.12.04.44.56; Fri, 12 Jan 2018 04:44:56 -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=jA4EctAO; 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 2A782C220AD; Fri, 12 Jan 2018 12:43:36 +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_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 198F3C2218E; Fri, 12 Jan 2018 12:40:59 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 25925C221EA; Fri, 12 Jan 2018 12:40:38 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by lists.denx.de (Postfix) with ESMTPS id 89933C22150 for ; Fri, 12 Jan 2018 12:40:34 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id 81so2226761wmb.1 for ; Fri, 12 Jan 2018 04:40:34 -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=XFQQHynXYNN1UQQJeZ7sE3PLF+77JU7nxbA/fiXFCAo=; b=jA4EctAOwgK60zGVfvSXISIt3hR8mVqH+gOdll/Xfh18nXt1/4Of1rwOVBo9mliI3j x4dv9IP+31hcnKXXfyKDCFVc0SIJuu283qNzI2dZumpJwA588vtmfUk0ODcc2mSfzSSW ujv0S25JK7oxvnhRuCoN63SODemhLtuw5Cn0M= 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=XFQQHynXYNN1UQQJeZ7sE3PLF+77JU7nxbA/fiXFCAo=; b=kaC0bY9T70xyp363DPIrHN5odLZuX/JRfJrsYjT8VCDdiHZuyLpd08XO+HqqJocQB+ AwRIzY1M/m2jpOt6jMoVG1zFCWxXgHrZchGUNTdUBboPj88KRh7abq3d7StL8TqGrKqr 6w+oFmCIfcG2nrtFMN9sDwPMIXkTZuY7aX2Nn+XB/8cXw+6K4wPyUX6MzZxm/+yanimU p2QaG1ySW21gUyShdGFuiQ5irj1yaSuthgtWfRrjjS3YIgmT/at+CgQJhD3f0YuKp9fN It35zTA/RXs+f9lbj+PNkTijkxGu7K8f/xmkL59zJnBcip5+H75eHnodAHK7wSd6Ieze dFNg== X-Gm-Message-State: AKGB3mKEBIve6zBUfcUffcK1NDHaWHtEnWNKXn0C5t/13Of/jXh12CG9 A+CzaE09T/1O0ERbu1xjS3tznn9IIBs= X-Received: by 10.80.164.175 with SMTP id w44mr34821516edb.57.1515760833890; Fri, 12 Jan 2018 04:40:33 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id w2sm13893585edb.4.2018.01.12.04.40.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jan 2018 04:40:33 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, brenomatheus@gmail.com Date: Fri, 12 Jan 2018 12:40:03 +0000 Message-Id: <1515760819-15116-10-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515760819-15116-1-git-send-email-bryan.odonoghue@linaro.org> References: <1515760819-15116-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Fabio Estevam Subject: [U-Boot] [PATCH v6 09/25] 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 Tested-by: Breno Lima Reviewed-by: Fabio Estevam --- 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