mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2026-04-22 14:40:06 +02:00
Add stack size validation in SecureContext_AllocateContext (#1402)
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:
parent
bdcde9583d
commit
7c0c890c64
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
@ -213,8 +213,15 @@ secureportNON_SECURE_CALLABLE void SecureContext_Init( void )
|
|||||||
/* Were we able to get a free context? */
|
/* Were we able to get a free context? */
|
||||||
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
if( ulSecureContextIndex < secureconfigMAX_SECURE_CONTEXTS )
|
||||||
{
|
{
|
||||||
/* Allocate the stack space. */
|
/* Allocate the stack space if possible. */
|
||||||
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
if( ulSecureStackSize > ( UINT32_MAX - securecontextSTACK_SEAL_SIZE ) )
|
||||||
|
{
|
||||||
|
pucStackMemory = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pucStackMemory = pvPortMalloc( ulSecureStackSize + securecontextSTACK_SEAL_SIZE );
|
||||||
|
}
|
||||||
|
|
||||||
if( pucStackMemory != NULL )
|
if( pucStackMemory != NULL )
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user