Commit 685e5609 authored by Varun Wadekar's avatar Varun Wadekar
Browse files

Tegra: sanity check NS address and size before use



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: default avatarVarun Wadekar <vwadekar@nvidia.com>

Change-Id: I46264f913954614bedcbde12e47ea0c70cd19be0
parent a7749acc
...@@ -367,7 +367,15 @@ void bl31_plat_arch_setup(void) ...@@ -367,7 +367,15 @@ void bl31_plat_arch_setup(void)
int32_t bl31_check_ns_address(uint64_t base, uint64_t size_in_bytes) int32_t bl31_check_ns_address(uint64_t base, uint64_t size_in_bytes)
{ {
uint64_t end = base + size_in_bytes - U(1); 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 * 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) ...@@ -376,7 +384,7 @@ int32_t bl31_check_ns_address(uint64_t base, uint64_t size_in_bytes)
(end > TEGRA_DRAM_END)) { (end > TEGRA_DRAM_END)) {
ERROR("NS address 0x%llx is out-of-bounds!\n", base); 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) ...@@ -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)) { if ((base < (uint64_t)TZDRAM_END) && (end > tegra_bl31_phys_base)) {
ERROR("NS address 0x%llx overlaps TZDRAM!\n", base); ERROR("NS address 0x%llx overlaps TZDRAM!\n", base);
ret = -ENOTSUP; return -ENOTSUP;
} }
/* valid NS address */ /* valid NS address */
return ret; return 0;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment