From a5fa5658e846ee00338dd90c2959b460e9aa54e6 Mon Sep 17 00:00:00 2001 From: Antonio Nino Diaz Date: Mon, 8 Oct 2018 16:11:11 +0100 Subject: [PATCH] xlat: Fix checks in mmap_add() and mmap_add_ctx() Commit 79621f0038b789de23ecc8891024f7cf6aa65999 broke sgi575. It is possible to have a region with 0 as value for the attributes. It means device memory, read only, secure, executable. This is legitimate if the code is in flash and the code is executed from there. This is the case for SGI_MAP_FLASH0_RO, defined in the file plat/arm/css/sgi/sgi_plat.c. This problem is solved by checking both size and attributes in xlat v1. In xlat v2, it is enough to check the granularity, as it can never be 0. Change-Id: I7be11f1b0e51c4c2ffd560b4a6cdfbf15de2c276 Signed-off-by: Antonio Nino Diaz --- lib/xlat_tables/xlat_tables_common.c | 2 +- lib/xlat_tables_v2/xlat_tables_core.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/xlat_tables/xlat_tables_common.c b/lib/xlat_tables/xlat_tables_common.c index a9aaeee8..2ee77c7a 100644 --- a/lib/xlat_tables/xlat_tables_common.c +++ b/lib/xlat_tables/xlat_tables_common.c @@ -176,7 +176,7 @@ void mmap_add(const mmap_region_t *mm) { const mmap_region_t *mm_cursor = mm; - while (mm_cursor->attr != 0U) { + while ((mm_cursor->size != 0U) || (mm_cursor->attr != 0U)) { mmap_add_region(mm_cursor->base_pa, mm_cursor->base_va, mm_cursor->size, mm_cursor->attr); mm_cursor++; diff --git a/lib/xlat_tables_v2/xlat_tables_core.c b/lib/xlat_tables_v2/xlat_tables_core.c index 3b6c6bcb..8ced76e4 100644 --- a/lib/xlat_tables_v2/xlat_tables_core.c +++ b/lib/xlat_tables_v2/xlat_tables_core.c @@ -815,7 +815,7 @@ void mmap_add_ctx(xlat_ctx_t *ctx, const mmap_region_t *mm) { const mmap_region_t *mm_cursor = mm; - while (mm_cursor->attr != 0U) { + while (mm_cursor->granularity != 0U) { mmap_add_region_ctx(ctx, mm_cursor); mm_cursor++; } -- 2.30.2