From patchwork Sat Dec 30 01:08:39 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: 122973 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp5318417qgn; Fri, 29 Dec 2017 17:15:42 -0800 (PST) X-Google-Smtp-Source: ACJfBos4yX7OrpQIk0PX8cI6UctVohLkHBEZeetmhO287E5fOS00e8RQ5LwmgByhMxUr39LEIAYG X-Received: by 10.80.181.33 with SMTP id y30mr47690813edd.150.1514596542485; Fri, 29 Dec 2017 17:15:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514596542; cv=none; d=google.com; s=arc-20160816; b=B7EX/41WYYR4ADJvEIBgyYLRgbB/2bnouB/n9ZFlIL0bJv6YFmogufPeBAo6w7ddUz 3NY63nqhyU8R2qdaECoeIW2mfNLhx67F6ynWMjZ7e0fZ0q7s5K5nd8PDdEQjy07B1Lxd /hF1s/0lQzdKtQf582/bL8A6zcav906tGB1se6ochN6+IwRErNsFlWg2K6t1XNiYaS5w ssEuf9XMGNFf9UZA4t18zC/pxDMSRRZBm4dAZRdT373MBfpNbiyPJdQefeGBj+Ut6+Jj rl6Yjbgrs5gD4Ky+ZzqJTzKyaTI+seSp32srmzzrJQ/ISm0iZe9hKyfW63h5LgkwJdoS 9FIA== 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=glD0FwGFPKUo/wuUTwgtD2csIcv+oBZOFW1bmfYNqHMI85shOzPg3gPhvsCVbZ1gZG iYJX/FDQCtuEXPg3TgOMRAcJsVFs1GAO2zTl+sKZ0Rj0sRahMzvo0n3SR8ORiX+rmzG2 yP21xHVef4vxXGbXhWL6WYX4dMD1k6jrA2NTynbhR4my/QouoxXY2pEUbIecCSs/P4jv uKKc2HyuV7o3nlmzrkSafcrG5F6Lwv+7hDF0ZQGDmgBsIyGtsHWuuOk9UYms2ptRqwhJ OL3TRCjZ1prPPzC5gJ0JSi0rAVdJhDQplV0+lt3xd0rq9hUZ9ykaOokGafyt3KnsHV1b 7+sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=MAby3IPl; 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 h20si985524eda.203.2017.12.29.17.15.42; Fri, 29 Dec 2017 17:15:42 -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=MAby3IPl; 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 E8E25C21DF3; Sat, 30 Dec 2017 01:13:33 +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 50A71C21E45; Sat, 30 Dec 2017 01:10:06 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4DAEEC21E48; Sat, 30 Dec 2017 01:09:19 +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 D567BC21DDD for ; Sat, 30 Dec 2017 01:09:15 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id 64so50092930wme.3 for ; Fri, 29 Dec 2017 17:09:15 -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=MAby3IPl7eOjCJl+PdIrdntZBY072Ufj2WTSdYBvNo4Yd3X3w6tMlHs2gzb2+LoKb8 +qvZnDVyVLxMc560IAjFAUBGSlXYN2Nwn24xhrjdBlbP2VRTsC3nBNtahpJKP18O/lSE BCUbJ+RKO7/3UdwZwZR5tgABIvGAzOyM5Pbjk= 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=X0qDsDdDAL4SFizkK9CyMGNQynDbLKQn2dVxFgtiZ3UNBpcUjUmcltB4LaqcZxT2cy CPbt5nHGN570JFuG0E7J+k5eNIp96wrkC5jVtgAvi9dV3YAGD9eHkC+GFCGScLvXnBJf nxqnywcy0Bigfeh5AMM4Wkw3itX+hRLA3YpMqAGsCI+ODyhnHQskI59bAhcUj2Jfxa9O FVWjV3O9Vd56v3yJhsWkWhVoBRxA8mI4mlA2iIxh2iNz1z2HE5k/dm27dytYFS+HZzNr r4kYzzGKGkLGZIfZEfkcLYJ/sjghNJk2ddh+NZDPCy2yosYODTobe7HGJVnxo9Y7s6I0 S6BA== X-Gm-Message-State: AKGB3mIS+YNXaOFzOGdeNn2/6zqf2H9Jlf4oDBXi3VLmABi4csTkoF9M AqJLB9C+STpv+h7GbCwnIVXwvY23ZdY= X-Received: by 10.80.134.18 with SMTP id o18mr47072392edo.306.1514596155306; Fri, 29 Dec 2017 17:09:15 -0800 (PST) Received: from localhost.localdomain ([109.255.42.2]) by smtp.gmail.com with ESMTPSA id f9sm26484148edm.83.2017.12.29.17.09.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Dec 2017 17:09:14 -0800 (PST) From: Bryan O'Donoghue To: u-boot@lists.denx.de, brenomatheus@gmail.com Date: Sat, 30 Dec 2017 01:08:39 +0000 Message-Id: <1514596142-22050-11-git-send-email-bryan.odonoghue@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514596142-22050-1-git-send-email-bryan.odonoghue@linaro.org> References: <1514596142-22050-1-git-send-email-bryan.odonoghue@linaro.org> Cc: Fabio Estevam Subject: [U-Boot] [PATCH v3 10/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 --- 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