|
50 | 50 | */ |
51 | 51 | #define securecontextCONTROL_VALUE_UNPRIVILEGED 0x03 |
52 | 52 |
|
| 53 | +/** |
| 54 | + * @brief Size of stack seal values in bytes. |
| 55 | + */ |
| 56 | +#define securecontextSTACK_SEAL_SIZE 8 |
| 57 | + |
| 58 | +/** |
| 59 | + * @brief Stack seal value as recommended by ARM. |
| 60 | + */ |
| 61 | +#define securecontextSTACK_SEAL_VALUE 0xFEF5EDA5 |
| 62 | + |
53 | 63 | /** |
54 | 64 | * @brief Maximum number of secure contexts. |
55 | 65 | */ |
@@ -203,18 +213,22 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void ) |
203 | 213 | if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS ) |
204 | 214 | { |
205 | 215 | /* Allocate the stack space. */ |
206 | | - pucStackMemory = pvPortMalloc( ulSecureStackSize ); |
| 216 | + pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE ); |
207 | 217 |
|
208 | 218 | if( pucStackMemory != NULL ) |
209 | 219 | { |
210 | 220 | /* Since stack grows down, the starting point will be the last |
211 | 221 | * location. Note that this location is next to the last |
212 | | - * allocated byte because the hardware decrements the stack |
213 | | - * pointer before writing i.e. if stack pointer is 0x2, a push |
214 | | - * operation will decrement the stack pointer to 0x1 and then |
215 | | - * write at 0x1. */ |
| 222 | + * allocated byte for stack (excluding the space for seal values) |
| 223 | + * because the hardware decrements the stack pointer before |
| 224 | + * writing i.e. if stack pointer is 0x2, a push operation will |
| 225 | + * decrement the stack pointer to 0x1 and then write at 0x1. */ |
216 | 226 | xSecureContexts[ ulSecureContextIndex ].pucStackStart = pucStackMemory + ulSecureStackSize; |
217 | 227 |
|
| 228 | + /* Seal the created secure process stack. */ |
| 229 | + *( uint32_t * )( pucStackMemory + ulSecureStackSize ) = securecontextSTACK_SEAL_VALUE; |
| 230 | + *( uint32_t * )( pucStackMemory + ulSecureStackSize + 4 ) = securecontextSTACK_SEAL_VALUE; |
| 231 | + |
218 | 232 | /* The stack cannot go beyond this location. This value is |
219 | 233 | * programmed in the PSPLIM register on context switch.*/ |
220 | 234 | xSecureContexts[ ulSecureContextIndex ].pucStackLimit = pucStackMemory; |
|
0 commit comments