]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
lib: optee: Avoid CONFIG_TZDRAM_* in optee_verify_bootm_image()
authorAlexandru Gagniuc <mr.nuke.me@gmail.com>
Tue, 7 Sep 2021 17:07:06 +0000 (12:07 -0500)
committerTom Rini <trini@konsulko.com>
Tue, 5 Oct 2021 12:46:23 +0000 (08:46 -0400)
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
lib/optee/optee.c

index 2928597b61ff7041fcc5ea2b7b9dd13562f84cfa..5412bc7386ec90f20f1b5dab1bb621673a5fa524 100644 (file)
@@ -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_IMAGE)
-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_IMAGE)
 int optee_verify_bootm_image(unsigned long image_addr,
                             unsigned long image_load_addr,
index 5676785cb5633f535f76de4aaf68270f0cbc6fc6..766d0d9e3fac5106f6c8f6a81f7c8b6345f13456 100644 (file)
 
 #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"
 
 #if defined(CONFIG_OPTEE_IMAGE)
-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 +
@@ -32,11 +30,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;
        }
 
@@ -48,12 +42,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;
 
@@ -64,8 +55,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);