Skip to content

Commit 5563c75

Browse files
committed
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 b196726 commit 5563c75

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
@@ -7351,7 +7351,7 @@ static void prvResetNextTaskUnblockTime( void )
73517351
/* MISRA Ref 11.5.1 [Malloc memory assignment] */
73527352
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
73537353
/* coverity[misra_c_2012_rule_11_5_violation] */
7354-
pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );
7354+
pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
73557355

73567356
if( pxTaskStatusArray != NULL )
73577357
{
@@ -7520,7 +7520,7 @@ static void prvResetNextTaskUnblockTime( void )
75207520
/* MISRA Ref 11.5.1 [Malloc memory assignment] */
75217521
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/main/MISRA.md#rule-115 */
75227522
/* coverity[misra_c_2012_rule_11_5_violation] */
7523-
pxTaskStatusArray = pvPortMalloc( uxCurrentNumberOfTasks * sizeof( TaskStatus_t ) );
7523+
pxTaskStatusArray = pvPortMalloc( uxArraySize * sizeof( TaskStatus_t ) );
75247524

75257525
if( pxTaskStatusArray != NULL )
75267526
{

0 commit comments

Comments
 (0)