From 764aa951b2ca451694c74791964a712d423d8206 Mon Sep 17 00:00:00 2001 From: Manish V Badarkhe Date: Wed, 13 Jul 2022 09:47:03 +0100 Subject: [PATCH] feat(drtm): ensure that passed region lies within Non-Secure region of DRAM Ensured DLME data region and DRTM parameters are lies within Non-Secure region of DRAM by calling platform function 'plat_drtm_validate_ns_region'. Signed-off-by: Manish V Badarkhe Change-Id: I93ead775f45ca7748193631f8f9eec4326fcf20a --- services/std_svc/drtm/drtm_main.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/services/std_svc/drtm/drtm_main.c b/services/std_svc/drtm/drtm_main.c index bec4b72f1..443516d28 100644 --- a/services/std_svc/drtm/drtm_main.c +++ b/services/std_svc/drtm/drtm_main.c @@ -328,6 +328,14 @@ static enum drtm_retc drtm_dl_check_args(uint64_t x1, } args_mapping_size = ALIGNED_UP(sizeof(struct_drtm_dl_args), DRTM_PAGE_SIZE); + + /* check DRTM parameters are within NS address region */ + rc = plat_drtm_validate_ns_region(x1, args_mapping_size); + if (rc != 0) { + ERROR("DRTM: parameters lies within secure memory\n"); + return INVALID_PARAMETERS; + } + rc = mmap_add_dynamic_region_alloc_va(x1, &args_mapping, args_mapping_size, MT_MEMORY | MT_NS | MT_RO | MT_SHAREABILITY_ISH); @@ -371,14 +379,6 @@ static enum drtm_retc drtm_dl_check_args(uint64_t x1, dlme_data_start = a->dlme_paddr + a->dlme_data_off; dlme_data_end = dlme_end; - /* - * TODO: validate that the DLME physical address range is all NS memory, - * return INVALID_PARAMETERS if it is not. - * Note that this check relies on platform-specific information. For - * examples, see psci_plat_pm_ops->validate_ns_entrypoint() or - * arm_validate_ns_entrypoint(). - */ - /* Check the DLME regions arguments. */ if ((dlme_start % DRTM_PAGE_SIZE) != 0) { ERROR("DRTM: argument DLME region is not " @@ -428,6 +428,13 @@ static enum drtm_retc drtm_dl_check_args(uint64_t x1, return INVALID_PARAMETERS; } + /* check DLME region (paddr + size) is within a NS address region */ + rc = plat_drtm_validate_ns_region(dlme_start, (size_t)a->dlme_size); + if (rc != 0) { + ERROR("DRTM: DLME region lies within secure memory\n"); + return INVALID_PARAMETERS; + } + /* Check the Normal World DCE region arguments. */ if (a->dce_nwd_paddr != 0) { uint32_t dce_nwd_start = a->dce_nwd_paddr; -- 2.39.5