Read-only xlat tables for BL31 memory
This patch introduces a build flag which allows the xlat tables
to be mapped in a read-only region within BL31 memory. It makes it
much harder for someone who has acquired the ability to write to
arbitrary secure memory addresses to gain control of the
translation tables.

The memory attributes of the descriptors describing the tables
themselves are changed to read-only secure data. This change
happens at the end of BL31 runtime setup. Until this point, the
tables have read-write permissions. This gives a window of
opportunity for changes to be made to the tables with the MMU on
(e.g. reclaiming init code). No changes can be made to the tables
with the MMU turned on from this point onwards. This change is also
enabled for sp_min and tspd.

To make all this possible, the base table was moved to .rodata. The
penalty we pay is that now .rodata must be aligned to the size of
the base table (512B alignment). Still, this is better than putting
the base table with the higher level tables in the xlat_table
section, as that would cost us a full 4KB page.

Changing the tables from read-write to read-only cannot be done with
the MMU on, as the break-before-make sequence would invalidate the
descriptor which resolves the level 3 page table where that very
descriptor is located. This would make the translation required for
writing the changes impossible, generating an MMU fault.

The caches are also flushed.

Signed-off-by: Petre-Ionut Tudor <petre-ionut.tudor@arm.com>
Change-Id: Ibe5de307e6dc94c67d6186139ac3973516430466
1 parent 2f39c55 commit 60e8f3cfd5910c59c9a573ce05bd61091336b09a
@Petre-Ionut Tudor Petre-Ionut Tudor authored on 7 Nov 2019
Showing 15 changed files
View
Makefile
View
include/lib/xlat_tables/xlat_tables_v2.h
View
include/lib/xlat_tables/xlat_tables_v2_helpers.h
View
include/plat/arm/common/plat_arm.h
View
lib/aarch64/cache_helpers.S
View
lib/xlat_tables_v2/ro_xlat_tables.mk 0 → 100644
View
lib/xlat_tables_v2/xlat_tables.mk
View
lib/xlat_tables_v2/xlat_tables_context.c
View
make_helpers/defaults.mk
View
plat/arm/board/fvp/platform.mk
View
plat/arm/board/juno/platform.mk
View
plat/arm/common/arm_bl31_setup.c
View
plat/arm/common/arm_common.c
View
plat/arm/common/sp_min/arm_sp_min_setup.c
View
plat/arm/common/tsp/arm_tsp_setup.c