From: Alexandru Gagniuc <mr.nuke.me@gmail.com>
To: u-boot@lists.denx.de
Cc: Alexandru Gagniuc <mr.nuke.me@gmail.com>,
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 [thread overview]
Message-ID: <20210907170709.2684890-2-mr.nuke.me@gmail.com> (raw)
In-Reply-To: <20210907170709.2684890-1-mr.nuke.me@gmail.com>
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 <mr.nuke.me@gmail.com>
---
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
next prev parent reply other threads:[~2021-09-07 17:07 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-07 17:07 [PATCH 0/4] Repeal and replace TZDRAM_ related config options Alexandru Gagniuc
2021-09-07 17:07 ` Alexandru Gagniuc [this message]
2021-10-05 22:01 ` [PATCH 1/4] lib: optee: Avoid CONFIG_TZDRAM_* in optee_verify_bootm_image() Tom Rini
2021-09-07 17:07 ` [PATCH 2/4] lib: optee: Remove CONFIG_OPTEE_TZDRAM_BASE Alexandru Gagniuc
2021-10-05 22:01 ` Tom Rini
2021-09-07 17:07 ` [PATCH 3/4] lib: optee: Remove CONFIG_OPTEE_LOAD_ADDR Alexandru Gagniuc
2021-10-05 22:01 ` Tom Rini
2021-09-07 17:07 ` [PATCH 4/4] arm: imx: mx7: Move CONFIG_OPTEE_TZDRAM_SIZE from lib/optee Alexandru Gagniuc
2021-10-05 22:02 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210907170709.2684890-2-mr.nuke.me@gmail.com \
--to=mr.nuke.me@gmail.com \
--cc=etienne.carriere@linaro.org \
--cc=festevam@gmail.com \
--cc=patrick.delaunay@foss.st.com \
--cc=sbabic@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox