Fix execute-never permissions in xlat tables libs
Translation regimes that only support one virtual address space (such as
the ones for EL2 and EL3) can flag memory regions as execute-never by
setting to 1 the XN bit in the Upper Attributes field in the translation
tables descriptors. Translation regimes that support two different
virtual address spaces (such as the one shared by EL1 and EL0) use bits
PXN and UXN instead.

The Trusted Firmware runs at EL3 and EL1, it has to handle translation
tables of both translation regimes, but the previous code handled both
regimes the same way, as if both had only 1 VA range.

When trying to set a descriptor as execute-never it would set the XN
bit correctly in EL3, but it would set the XN bit in EL1 as well. XN is
at the same bit position as UXN, which means that EL0 was being
prevented from executing code at this region, not EL1 as the code
intended. Therefore, the PXN bit was unset to 0 all the time. The result
is that, in AArch64 mode, read-only data sections of BL2 weren't
protected from being executed.

This patch adds support of translation regimes with two virtual address
spaces to both versions of the translation tables library, fixing the
execute-never permissions for translation tables in EL1.

The library currently does not support initializing translation tables
for EL0 software, therefore it does not set/unset the UXN bit. If EL1
software needs to initialize translation tables for EL0 software, it
should use a different library instead.

Change-Id: If27588f9820ff42988851d90dc92801c8ecbe0c9
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
1 parent 062dd37 commit a56402521f80cf1b17e3936abcc6b1772aa91e66
@Antonio Nino Diaz Antonio Nino Diaz authored on 27 Apr 2017
Showing 10 changed files
View
include/lib/xlat_tables/xlat_tables_defs.h
View
lib/xlat_tables/aarch32/xlat_tables.c
View
lib/xlat_tables/aarch64/xlat_tables.c
View
lib/xlat_tables/xlat_tables_common.c
View
lib/xlat_tables/xlat_tables_private.h
View
lib/xlat_tables_v2/aarch32/xlat_tables_arch.c
View
lib/xlat_tables_v2/aarch64/xlat_tables_arch.c
View
lib/xlat_tables_v2/xlat_tables_common.c
View
lib/xlat_tables_v2/xlat_tables_internal.c
View
lib/xlat_tables_v2/xlat_tables_private.h