From 0c41489f01ef9af94c2b51188b7c3fca24f3ed96 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 16 Jul 2021 10:55:49 -0700 Subject: [PATCH] exo: fix SE aes-ctr usage in GetSecureData --- exosphere/program/source/smc/secmon_smc_aes.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/exosphere/program/source/smc/secmon_smc_aes.cpp b/exosphere/program/source/smc/secmon_smc_aes.cpp index 158f249ae..86c347f8e 100644 --- a/exosphere/program/source/smc/secmon_smc_aes.cpp +++ b/exosphere/program/source/smc/secmon_smc_aes.cpp @@ -272,7 +272,19 @@ namespace ams::secmon::smc { void GetSecureDataImpl(u8 *dst, SecureData which, bool tweak) { /* Compute the appropriate AES-CTR. */ - se::ComputeAes128Ctr(dst, AesKeySize, pkg1::AesKeySlot_Device, SecureDataSource, AesKeySize, GetSecureDataCounter(which), AesKeySize); + { + /* Ensure that the SE sees consistent data. */ + hw::FlushDataCache(dst, AesKeySize); + hw::DataSynchronizationBarrierInnerShareable(); + + /* Perform the appropriate AES operation. */ + se::ComputeAes128Ctr(dst, AesKeySize, pkg1::AesKeySlot_Device, SecureDataSource, AesKeySize, GetSecureDataCounter(which), AesKeySize); + hw::DataSynchronizationBarrierInnerShareable(); + + /* Ensure the CPU sees consistent data. */ + hw::FlushDataCache(dst, AesKeySize); + hw::DataSynchronizationBarrierInnerShareable(); + } /* Tweak, if we should. */ if (tweak) {