From 7d30460214c6ff5046234e8705187f322c4fd467 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 14 Apr 2020 12:23:08 -0700 Subject: [PATCH] exosphere: fix reentrancy of se interrupt handler --- exosphere/src/se.c | 19 +++++++------------ exosphere/src/smc_user.c | 8 ++++---- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/exosphere/src/se.c b/exosphere/src/se.c index d487ee005..dcc52f4ea 100644 --- a/exosphere/src/se.c +++ b/exosphere/src/se.c @@ -52,19 +52,20 @@ void ll_init(volatile se_ll_t *ll, void *buffer, size_t size) { } void set_security_engine_callback(unsigned int (*callback)(void)) { - if (callback == NULL || g_se_callback != NULL) { - generic_panic(); - } - + /* Set the callback. */ g_se_callback = callback; + + /* Enable SE Interrupt firing for async op. */ + se_get_regs()->SE_INT_ENABLE = 0x10; } /* Fires on Security Engine operation completion. */ void se_operation_completed(void) { se_get_regs()->SE_INT_ENABLE = 0; - if (g_se_callback != NULL) { - g_se_callback(); + unsigned int (*callback)(void) = g_se_callback; + if (callback != NULL) { g_se_callback = NULL; + callback(); } } @@ -304,9 +305,6 @@ void se_aes_crypt_insecure_internal(unsigned int keyslot, uint32_t out_ll_paddr, /* Set the callback, for after the async operation. */ set_security_engine_callback(callback); - /* Enable SE Interrupt firing for async op. */ - se->SE_INT_ENABLE = 0x10; - /* Setup Input/Output lists */ se->SE_IN_LL_ADDR = in_ll_paddr; se->SE_OUT_LL_ADDR = out_ll_paddr; @@ -358,9 +356,6 @@ void se_exp_mod(unsigned int keyslot, const void *buf, size_t size, unsigned int set_security_engine_callback(callback); - /* Enable SE interrupt firing for async op. */ - se->SE_INT_ENABLE = 0x10; - flush_dcache_range(stack_buf, stack_buf + KEYSIZE_RSA_MAX); trigger_se_rsa_op(stack_buf, size); diff --git a/exosphere/src/smc_user.c b/exosphere/src/smc_user.c index f2e83629b..7d966b27c 100644 --- a/exosphere/src/smc_user.c +++ b/exosphere/src/smc_user.c @@ -36,13 +36,13 @@ static bool g_crypt_aes_done = false; static uint32_t g_exp_mod_result = 0; -static uint8_t g_imported_exponents[4][0x100]; -static uint8_t g_imported_moduli[4][0x100]; +static __attribute__((aligned(4))) uint8_t g_imported_exponents[4][0x100]; +static __attribute__((aligned(4))) uint8_t g_imported_moduli[4][0x100]; static bool g_is_modulus_verified[4]; -static const uint8_t g_rsa_public_key[4] = { 0x00, 0x01, 0x00, 0x01 }; +static __attribute__((aligned(4))) const uint8_t g_rsa_public_key[4] = { 0x00, 0x01, 0x00, 0x01 }; -static const uint8_t g_rsa_test_vector[0x100] = { +static __attribute__((aligned(4))) const uint8_t g_rsa_test_vector[0x100] = { 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D',