|
| 1 | +// |
| 2 | +// env_opteeTa.c |
| 3 | +// Platform-specific code for OPTEE TA. |
| 4 | +// |
| 5 | +// Copyright (c) Microsoft Corporation. Licensed under the MIT license. |
| 6 | +// |
| 7 | + |
| 8 | +#include "precomp.h" |
| 9 | + |
| 10 | +// OPTEE TA specific data |
| 11 | +#define TEE_ERROR_BAD_STATE 0xFFFF0007 |
| 12 | + |
| 13 | +typedef uint32_t TEE_Result; |
| 14 | + |
| 15 | +void TEE_Panic(TEE_Result panicCode); |
| 16 | + |
| 17 | + |
| 18 | +SYMCRYPT_CPU_FEATURES SYMCRYPT_CALL SymCryptCpuFeaturesNeverPresentEnvOpteeTa(void) |
| 19 | +{ |
| 20 | + return 0; |
| 21 | +} |
| 22 | + |
| 23 | +VOID |
| 24 | +SYMCRYPT_CALL |
| 25 | +SymCryptInitEnvOpteeTa( UINT32 version ) |
| 26 | +{ |
| 27 | + if( g_SymCryptFlags & SYMCRYPT_FLAG_LIB_INITIALIZED ) |
| 28 | + { |
| 29 | + return; |
| 30 | + } |
| 31 | + |
| 32 | + // Optee module relies on the unconditional availability of certain CPU features (ASIMD, AES, PMULL, SHA256) |
| 33 | + g_SymCryptCpuFeaturesNotPresent = (SYMCRYPT_CPU_FEATURES) ~(SYMCRYPT_CPU_FEATURE_NEON|SYMCRYPT_CPU_FEATURE_NEON_AES|SYMCRYPT_CPU_FEATURE_NEON_PMULL|SYMCRYPT_CPU_FEATURE_NEON_SHA256); |
| 34 | + |
| 35 | + SymCryptInitEnvCommon( version ); |
| 36 | +} |
| 37 | + |
| 38 | +_Analysis_noreturn_ |
| 39 | +VOID |
| 40 | +SYMCRYPT_CALL |
| 41 | +SymCryptFatalEnvOpteeTa( ULONG fatalCode ) |
| 42 | +{ |
| 43 | + UINT32 fatalCodeVar; |
| 44 | + |
| 45 | + SymCryptFatalIntercept( fatalCode ); |
| 46 | + |
| 47 | + // |
| 48 | + // Put the fatal code in a location where it shows up in the dump |
| 49 | + // |
| 50 | + SYMCRYPT_FORCE_WRITE32( &fatalCodeVar, fatalCode ); |
| 51 | + |
| 52 | + // |
| 53 | + // Our first preference is to fastfail, |
| 54 | + // the second to create an AV, which can trigger a core dump so that we get to |
| 55 | + // see what is going wrong. |
| 56 | + // |
| 57 | + __fastfail( FAST_FAIL_CRYPTO_LIBRARY ); |
| 58 | + |
| 59 | + TEE_Panic(TEE_ERROR_BAD_STATE); |
| 60 | + |
| 61 | + // |
| 62 | + // Next we write to the NULL pointer, this causes an AV |
| 63 | + // |
| 64 | + SYMCRYPT_FORCE_WRITE32( (volatile UINT32 *)NULL, fatalCode ); |
| 65 | + |
| 66 | + SymCryptFatalHang( fatalCode ); |
| 67 | +} |
| 68 | + |
| 69 | +VOID |
| 70 | +SYMCRYPT_CALL |
| 71 | +SymCryptTestInjectErrorEnvOpteeTa( PBYTE pbBuf, SIZE_T cbBuf ) |
| 72 | +{ |
| 73 | + // |
| 74 | + // This feature is only used during testing. In production it is always |
| 75 | + // an empty function that the compiler can optimize away. |
| 76 | + // |
| 77 | + UNREFERENCED_PARAMETER( pbBuf ); |
| 78 | + UNREFERENCED_PARAMETER( cbBuf ); |
| 79 | +} |
| 80 | + |
0 commit comments