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