Skip to content

Commit e146d64

Browse files
srpatchaAniruddhaKanhere
authored andcommitted
fix: TOCTOU race condition in vTaskListTasks()
Read uxCurrentNumberOfTasks once into uxArraySize and use that local variable for both the size check and pvPortMalloc() call. The previous code read the volatile variable twice, allowing a task to be created between the reads, resulting in an undersized allocation that could cause a buffer overflow in uxTaskGetSystemState().
1 parent 83e56c3 commit e146d64

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

tasks.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7362,7 +7362,7 @@ STATIC void prvResetNextTaskUnblockTime( void )
73627362
/* MISRA Ref 11.5.1 [Malloc memory assignment] */
73637363
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
73647364
/* coverity[misra_c_2012_rule_11_5_violation] */
7365-
pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );
7365+
pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
73667366

73677367
if( pxTaskStatusArray != NULL )
73687368
{
@@ -7531,7 +7531,7 @@ STATIC void prvResetNextTaskUnblockTime( void )
75317531
/* MISRA Ref 11.5.1 [Malloc memory assignment] */
75327532
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
75337533
/* coverity[misra_c_2012_rule_11_5_violation] */
7534-
pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );
7534+
pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
75357535

75367536
if( pxTaskStatusArray != NULL )
75377537
{

0 commit comments

Comments
 (0)