Add stack size validation in SecureContext_AllocateContext

Validate that ulSecureStackSize + securecontextSTACK_SEAL_SIZE does not
overflow before calling pvPortMalloc in the ARMv8-M secure context ports.

Reported by Jordan Mecom (Block, Inc.)
This commit is contained in:
patrzhan 2026-04-15 16:32:48 -07:00
parent bdcde9583d
commit 26229fd249
15 changed files with 135 additions and 30 deletions

View file

@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
/* Were we able to get a free context? */
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
{
/* Allocate the stack space. */
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
/* Allocate the stack space if possible. */
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
{
pucStackMemory = NULL;
}
else
{
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
}
if( pucStackMemory != NULL )
{