From 6460ed7aaab06b1d88f7e20d4ee9b9b0b9fb58fc Mon Sep 17 00:00:00 2001 From: Varun Wadekar Date: Thu, 20 Jul 2017 09:43:28 -0700 Subject: [PATCH] Tegra: sanity check non-secure DRAM address This patch fixes the logic to validate if a non-secure memory address overlaps the TZDRAM memory aperture. Change-Id: I68af7dc6acc705d7b0ee9161c4002376077b46b1 Signed-off-by: Varun Wadekar --- plat/nvidia/tegra/common/tegra_bl31_setup.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plat/nvidia/tegra/common/tegra_bl31_setup.c b/plat/nvidia/tegra/common/tegra_bl31_setup.c index 26256c2cb..e92960c2e 100644 --- a/plat/nvidia/tegra/common/tegra_bl31_setup.c +++ b/plat/nvidia/tegra/common/tegra_bl31_setup.c @@ -381,13 +381,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; + uint64_t end = base + size_in_bytes - U(1); int32_t ret = 0; /* * Check if the NS DRAM address is valid */ - if ((base < TEGRA_DRAM_BASE) || (end > TEGRA_DRAM_END)) { + if ((base < TEGRA_DRAM_BASE) || (base >= TEGRA_DRAM_END) || + (end > TEGRA_DRAM_END)) { + ERROR("NS address is out-of-bounds!\n"); ret = -EFAULT; } @@ -396,7 +398,7 @@ int32_t bl31_check_ns_address(uint64_t base, uint64_t size_in_bytes) * TZDRAM aperture contains the BL31 and BL32 images, so we need * to check if the NS DRAM range overlaps the TZDRAM aperture. */ - if ((base < TZDRAM_END) && (end > tegra_bl31_phys_base)) { + if ((base < (uint64_t)TZDRAM_END) && (end > tegra_bl31_phys_base)) { ERROR("NS address overlaps TZDRAM!\n"); ret = -ENOTSUP; }