]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
Tegra: sanity check NS address and size before use
authorVarun Wadekar <vwadekar@nvidia.com>
Wed, 3 Jun 2020 04:16:00 +0000 (21:16 -0700)
committerVarun Wadekar <vwadekar@nvidia.com>
Sun, 21 Jun 2020 20:34:23 +0000 (13:34 -0700)
This patch updates the 'bl31_check_ns_address()' helper function to
check that the memory address and size passed by the NS world are not
zero.

The helper fucntion also returns the error code as soon as it detects
inconsistencies, to avoid multiple error paths from kicking in for the
same input parameters.

Signed-off-by: Varun Wadekar <vwadekar@nvidia.com>
Change-Id: I46264f913954614bedcbde12e47ea0c70cd19be0

plat/nvidia/tegra/common/tegra_bl31_setup.c

index 269afb196a622e74f2c0c2ca62ccc973fe99bfd1..40713b2c709b5e59a9900a9eba0d27fa8e6bb5b4 100644 (file)
@@ -367,7 +367,15 @@ void bl31_plat_arch_setup(void)
 int32_t bl31_check_ns_address(uint64_t base, uint64_t size_in_bytes)
 {
        uint64_t end = base + size_in_bytes - U(1);
-       int32_t ret = 0;
+
+       /*
+        * Sanity check the input values
+        */
+       if ((base == 0U) || (size_in_bytes == 0U)) {
+               ERROR("NS address 0x%llx (%lld bytes) is invalid\n",
+                       base, size_in_bytes);
+               return -EINVAL;
+       }
 
        /*
         * Check if the NS DRAM address is valid
@@ -376,7 +384,7 @@ int32_t bl31_check_ns_address(uint64_t base, uint64_t size_in_bytes)
            (end > TEGRA_DRAM_END)) {
 
                ERROR("NS address 0x%llx is out-of-bounds!\n", base);
-               ret = -EFAULT;
+               return -EFAULT;
        }
 
        /*
@@ -385,9 +393,9 @@ int32_t bl31_check_ns_address(uint64_t base, uint64_t size_in_bytes)
         */
        if ((base < (uint64_t)TZDRAM_END) && (end > tegra_bl31_phys_base)) {
                ERROR("NS address 0x%llx overlaps TZDRAM!\n", base);
-               ret = -ENOTSUP;
+               return -ENOTSUP;
        }
 
        /* valid NS address */
-       return ret;
+       return 0;
 }