From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5140AC433EF for ; Tue, 7 Sep 2021 17:07:43 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7557160187 for ; Tue, 7 Sep 2021 17:07:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7557160187 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id E5E578329C; Tue, 7 Sep 2021 19:07:26 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HeXsj+w6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 67A50832B7; Tue, 7 Sep 2021 19:07:23 +0200 (CEST) Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A2A0D8323A for ; Tue, 7 Sep 2021 19:07:14 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=mr.nuke.me@gmail.com Received: by mail-oi1-x232.google.com with SMTP id y128so13636008oie.4 for ; Tue, 07 Sep 2021 10:07:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=keywQXlB7nm3Uu3Q1WJGDefxndU7hutGgRfFVV718HU=; b=HeXsj+w6Ou4DtR4IpcPCiigwgCvcJOSZNYtFd2svgEo2IUEBderXZ//kOQNXZjeGtm c4n+7MzNDo7jbFZ3qtrYt6P4e16lEARJf57fVDr1ask082bhkMm64EsdNho9QUkxUn3C xxtbZFhOeiDx9neDySekwXBRHSRdDOciwznFtayq2uV8EFtex7Avcm5Npuz5zTavvb46 PyP5lLmraKoW3qXuppYBge/crWNfkrc6LkHCJCyEXf91o14MmCVk7wHlBH8LO/2IUsNo b63C8m9EPTpVFwQ9A6TZsA4UoFKXVsPor+WL7dNuoOShqiF7nn1naE+nKF2fYU6aJCVu /u6A== 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:mime-version:content-transfer-encoding; bh=keywQXlB7nm3Uu3Q1WJGDefxndU7hutGgRfFVV718HU=; b=spr2u1LdvXVoyvHp46nKS8GahtaAMscIAXZGlElQQLxilvWWy6lqI5jVgqfAEkvN1u T7dDUXIeCAaVYRHn35Cckad++jHORur+WvvQJay9l2cTAVAdJswnLox0eS1UtHbgQYiU Ml+BHXb9Hdh+QS0tFTnoHeBydepp5m2Q3z+AEIePfvwh6syaKRwVOHgGMOgvBRuf67+F SFKZbzuyLzP+qs4OJ0NZXnLEq5rui9VXJPUhOS/NYc27LMpb6po3s1U2HJo/rQYDQiOn IvpCQ4L5+zg6+TTByKRoiPqZ/1BYSsFeUfBJgnsF2O2AouKpTMaRuP4PV+2CkidliHrT v9Mw== X-Gm-Message-State: AOAM5328fs+w2n/+A0Q+YCXZ4IKhwahbtHLo29Ph8cM5F9utVEVYLmRl Ph+eajEPplnp4YS5e/PAidh9Nqm8yos= X-Google-Smtp-Source: ABdhPJzGcr2Y99eP3XSzy/3OLWMR5jtE51FU5PVr3cFiqihCOAL0EK7wwfaWO8XAKUwKbeNOF1tTGA== X-Received: by 2002:aca:6008:: with SMTP id u8mr3882893oib.127.1631034432963; Tue, 07 Sep 2021 10:07:12 -0700 (PDT) Received: from nuclearis3.lan (c-98-195-139-126.hsd1.tx.comcast.net. [98.195.139.126]) by smtp.gmail.com with ESMTPSA id z1sm2340898ooj.25.2021.09.07.10.07.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Sep 2021 10:07:12 -0700 (PDT) From: Alexandru Gagniuc To: u-boot@lists.denx.de Cc: Alexandru Gagniuc , patrick.delaunay@foss.st.com, etienne.carriere@linaro.org, sbabic@denx.de, festevam@gmail.com Subject: [PATCH 1/4] lib: optee: Avoid CONFIG_TZDRAM_* in optee_verify_bootm_image() Date: Tue, 7 Sep 2021 12:07:06 -0500 Message-Id: <20210907170709.2684890-2-mr.nuke.me@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210907170709.2684890-1-mr.nuke.me@gmail.com> References: <20210907170709.2684890-1-mr.nuke.me@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean The configs TZDRAM_BASE and TZDRAM_SIZE are expected to describe the memory allocated to the OPTEE region. according to according to commit c5a6e8bd00cc ("optee: Add optee_verify_bootm_image()"). The TZDRAM is with some limitations, described by "/reserved-memory" nodes in the devicetree. Consequently TZDRAM_BASE and TZDRAM_SIZE can point to imaginary regions which have nothing to do with actual DRAM. They are not used to configure the hardware or set up the Trust Zone Controller (TZC) for OP-TEE -- the devicetree values are used instead. When a valid OP-TEE image does not fall within the region described by these configs, u-boot will refuse to load it. In fact, it mostly serves to cause "bootm" to reject perfectly good OP-TEE images. Ironically, someone has to correctly configure the devicetree for TZDRAM, then go back and enter the same information in Kconfig for "bootm". To remedy this, do not use TZDRAM_BASE and TZDRAM_SIZE in the verification of OPTEE images. Signed-off-by: Alexandru Gagniuc --- include/tee/optee.h | 14 -------------- lib/optee/optee.c | 21 ++++++--------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/include/tee/optee.h b/include/tee/optee.h index ebdfe5e98d..764a55b264 100644 --- a/include/tee/optee.h +++ b/include/tee/optee.h @@ -43,20 +43,6 @@ optee_image_get_load_addr(const struct image_header *hdr) return optee_image_get_entry_point(hdr) - sizeof(struct optee_header); } -#if defined(CONFIG_OPTEE) -int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start, - unsigned long tzdram_len, unsigned long image_len); -#else -static inline int optee_verify_image(struct optee_header *hdr, - unsigned long tzdram_start, - unsigned long tzdram_len, - unsigned long image_len) -{ - return -EPERM; -} - -#endif - #if defined(CONFIG_OPTEE) int optee_verify_bootm_image(unsigned long image_addr, unsigned long image_load_addr, diff --git a/lib/optee/optee.c b/lib/optee/optee.c index 672690dc53..67e46d71d6 100644 --- a/lib/optee/optee.c +++ b/lib/optee/optee.c @@ -16,14 +16,12 @@ #define optee_hdr_err_msg \ "OPTEE verification error:" \ - "\n\thdr=%p image=0x%08lx magic=0x%08x tzdram 0x%08lx-0x%08lx " \ + "\n\thdr=%p image=0x%08lx magic=0x%08x" \ "\n\theader lo=0x%08x hi=0x%08x size=0x%08lx arch=0x%08x" \ "\n\tuimage params 0x%08lx-0x%08lx\n" -int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start, - unsigned long tzdram_len, unsigned long image_len) +static int optee_verify_image(struct optee_header *hdr, unsigned long image_len) { - unsigned long tzdram_end = tzdram_start + tzdram_len; uint32_t tee_file_size; tee_file_size = hdr->init_size + hdr->paged_size + @@ -31,11 +29,7 @@ int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start, if (hdr->magic != OPTEE_MAGIC || hdr->version != OPTEE_VERSION || - hdr->init_load_addr_hi > tzdram_end || - hdr->init_load_addr_lo < tzdram_start || - tee_file_size > tzdram_len || - tee_file_size != image_len || - (hdr->init_load_addr_lo + tee_file_size) > tzdram_end) { + tee_file_size != image_len) { return -EINVAL; } @@ -47,12 +41,9 @@ int optee_verify_bootm_image(unsigned long image_addr, unsigned long image_len) { struct optee_header *hdr = (struct optee_header *)image_addr; - unsigned long tzdram_start = CONFIG_OPTEE_TZDRAM_BASE; - unsigned long tzdram_len = CONFIG_OPTEE_TZDRAM_SIZE; - int ret; - ret = optee_verify_image(hdr, tzdram_start, tzdram_len, image_len); + ret = optee_verify_image(hdr, image_len); if (ret) goto error; @@ -63,8 +54,8 @@ int optee_verify_bootm_image(unsigned long image_addr, return ret; error: - printf(optee_hdr_err_msg, hdr, image_addr, hdr->magic, tzdram_start, - tzdram_start + tzdram_len, hdr->init_load_addr_lo, + printf(optee_hdr_err_msg, hdr, image_addr, hdr->magic, + hdr->init_load_addr_lo, hdr->init_load_addr_hi, image_len, hdr->arch, image_load_addr, image_load_addr + image_len); -- 2.31.1