From 3ca26bed7e22b22eb087c54a2a2dea8fdd313d68 Mon Sep 17 00:00:00 2001 From: Sandrine Bailleux Date: Thu, 14 Mar 2019 11:38:01 +0100 Subject: [PATCH 1/2] Fix restoring APIBKey registers Instruction key A was incorrectly restored in the instruction key B registers. Change-Id: I4cb81ac72180442c077898509cb696c9d992eda3 Signed-off-by: Sandrine Bailleux --- lib/el3_runtime/aarch64/context.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/el3_runtime/aarch64/context.S b/lib/el3_runtime/aarch64/context.S index 4371cb2b2..e6ab19bcc 100644 --- a/lib/el3_runtime/aarch64/context.S +++ b/lib/el3_runtime/aarch64/context.S @@ -356,7 +356,7 @@ func pauth_context_restore msr APIAKeyLo_EL1, x9 msr APIAKeyHi_EL1, x10 - ldp x9, x10, [x11, #CTX_PACIAKEY_LO] + ldp x9, x10, [x11, #CTX_PACIBKEY_LO] msr APIBKeyLo_EL1, x9 msr APIBKeyHi_EL1, x10 From 47102b35d644a8c5a1343f9ec05c29b5d1e0e1b0 Mon Sep 17 00:00:00 2001 From: Sandrine Bailleux Date: Wed, 13 Mar 2019 18:02:09 +0100 Subject: [PATCH 2/2] Put Pointer Authentication key value in BSS section The dummy implementation of the plat_init_apiakey() platform API uses an internal 128-bit buffer to store the initial key value used for Pointer Authentication support. The intent - as stated in the file comments - was for this buffer to be write-protected by the MMU. Initialization of the buffer would be performed before enabling the MMU, thus bypassing write protection checks. However, the key buffer ended up into its own read-write section by mistake due to a typo on the section name ('rodata.apiakey' instead of '.rodata.apiakey', note the leading dot). As a result, the linker script was not pulling it into the .rodata output section. One way to address this issue could have been to fix the section name. However, this approach does not work well for BL1. Being the first image in the boot flow, it typically is sitting in real ROM so we don't have the capacity to update the key buffer at any time. The dummy implementation of plat_init_apiakey() provided at the moment is just there to demonstrate the Pointer Authentication feature in action. Proper key management and key generation would have to be a lot more careful on a production system. Therefore, the approach chosen here to leave the key buffer in writable memory but move it to the BSS section. This does mean that the key buffer could be maliciously updated for intalling unintended keys on the warm boot path but at the feature is only at an experimental stage right now, this is deemed acceptable. Change-Id: I121ccf35fe7bc86c73275a4586b32d4bc14698d6 Signed-off-by: Sandrine Bailleux --- plat/arm/common/aarch64/arm_pauth.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/plat/arm/common/aarch64/arm_pauth.c b/plat/arm/common/aarch64/arm_pauth.c index c8471190a..a685c319d 100644 --- a/plat/arm/common/aarch64/arm_pauth.c +++ b/plat/arm/common/aarch64/arm_pauth.c @@ -9,11 +9,9 @@ /* * Instruction pointer authentication key A. The low 64-bit are at [0], and the - * high bits at [1]. They are run-time constants so they are placed in the - * rodata section. They are written before MMU is turned on and the permissions - * are effective. + * high bits at [1]. */ -uint64_t plat_apiakey[2] __section("rodata.apiakey"); +uint64_t plat_apiakey[2]; /* * This is only a toy implementation to generate a seemingly random 128-bit key