Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stack sealing for TrustZone context #1037

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CMSIS/Core/Template/ARMv8-M/tz_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@
#define TZ_PROCESS_STACK_SIZE 256U
#endif

#define TZ_PROCESS_STACK_SEAL_SIZE 8U

#define TZ_PROCESS_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5UL

typedef struct {
uint32_t sp_top; // stack space top
uint32_t sp_limit; // stack space limit
uint32_t sp; // current stack pointer
} stack_info_t;

static stack_info_t ProcessStackInfo [TZ_PROCESS_STACK_SLOTS];
static uint64_t ProcessStackMemory[TZ_PROCESS_STACK_SLOTS][TZ_PROCESS_STACK_SIZE/8U];
static uint64_t ProcessStackMemory[TZ_PROCESS_STACK_SLOTS][(TZ_PROCESS_STACK_SIZE + TZ_PROCESS_STACK_SEAL_SIZE)/8U];
static uint32_t ProcessStackFreeSlot = 0xFFFFFFFFU;


Expand All @@ -62,6 +66,9 @@ uint32_t TZ_InitContextSystem_S (void) {
ProcessStackInfo[n].sp_limit = (uint32_t)&ProcessStackMemory[n];
ProcessStackInfo[n].sp_top = (uint32_t)&ProcessStackMemory[n] + TZ_PROCESS_STACK_SIZE;
*((uint32_t *)ProcessStackMemory[n]) = n + 1U;

/* Seal each process stack. */
ProcessStackMemory[n][TZ_PROCESS_STACK_SIZE/8U] = TZ_PROCESS_STACK_SEAL_VALUE;
}
*((uint32_t *)ProcessStackMemory[--n]) = 0xFFFFFFFFU;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@
#define TZ_PROCESS_STACK_SIZE 256U
#endif

#define TZ_PROCESS_STACK_SEAL_SIZE 8U

#define TZ_PROCESS_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5UL

typedef struct {
uint32_t sp_top; // stack space top
uint32_t sp_limit; // stack space limit
uint32_t sp; // current stack pointer
} stack_info_t;

static stack_info_t ProcessStackInfo [TZ_PROCESS_STACK_SLOTS];
static uint64_t ProcessStackMemory[TZ_PROCESS_STACK_SLOTS][TZ_PROCESS_STACK_SIZE/8U];
static uint64_t ProcessStackMemory[TZ_PROCESS_STACK_SLOTS][(TZ_PROCESS_STACK_SIZE + TZ_PROCESS_STACK_SEAL_SIZE)/8U];
static uint32_t ProcessStackFreeSlot = 0xFFFFFFFFU;


Expand All @@ -65,6 +69,9 @@ uint32_t TZ_InitContextSystem_S (void) {
ProcessStackInfo[n].sp_limit = (uint32_t)&ProcessStackMemory[n];
ProcessStackInfo[n].sp_top = (uint32_t)&ProcessStackMemory[n] + TZ_PROCESS_STACK_SIZE;
*((uint32_t *)ProcessStackMemory[n]) = n + 1U;

/* Seal each process stack. */
ProcessStackMemory[n][TZ_PROCESS_STACK_SIZE/8U] = TZ_PROCESS_STACK_SEAL_VALUE;
}
*((uint32_t *)ProcessStackMemory[--n]) = 0xFFFFFFFFU;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,18 @@
#define TZ_PROCESS_STACK_SIZE 256U
#endif

#define TZ_PROCESS_STACK_SEAL_SIZE 8U

#define TZ_PROCESS_STACK_SEAL_VALUE 0xFEF5EDA5FEF5EDA5UL

typedef struct {
uint32_t sp_top; // stack space top
uint32_t sp_limit; // stack space limit
uint32_t sp; // current stack pointer
} stack_info_t;

static stack_info_t ProcessStackInfo [TZ_PROCESS_STACK_SLOTS];
static uint64_t ProcessStackMemory[TZ_PROCESS_STACK_SLOTS][TZ_PROCESS_STACK_SIZE/8U];
static uint64_t ProcessStackMemory[TZ_PROCESS_STACK_SLOTS][(TZ_PROCESS_STACK_SIZE + TZ_PROCESS_STACK_SEAL_SIZE)/8U];
static uint32_t ProcessStackFreeSlot = 0xFFFFFFFFU;


Expand All @@ -65,6 +69,9 @@ uint32_t TZ_InitContextSystem_S (void) {
ProcessStackInfo[n].sp_limit = (uint32_t)&ProcessStackMemory[n];
ProcessStackInfo[n].sp_top = (uint32_t)&ProcessStackMemory[n] + TZ_PROCESS_STACK_SIZE;
*((uint32_t *)ProcessStackMemory[n]) = n + 1U;

/* Seal each process stack. */
ProcessStackMemory[n][TZ_PROCESS_STACK_SIZE/8U] = TZ_PROCESS_STACK_SEAL_VALUE;
}
*((uint32_t *)ProcessStackMemory[--n]) = 0xFFFFFFFFU;

Expand Down